为什么 DTD 验证会给我错误 "A ')' is required in the declaration of element type "Invoice"?

Why does validation of DTD gives me the error "A ')' is required in the declaration of element type "Invoice"?

我正在将 DTD 写入我的 XML 文件。我在元素 "Invoice" 上收到同样的错误 "A ')' is required in the declaration of element type "Invoice""我的 DTD 匹配我的 XML,名称正确,元素顺序正确。任何帮助,将不胜感激。下面是我的 DTD 和 XML 文件。

我试过重新排序 DTD 的元​​素,查看我的 XML 试图找出那里的错误,但似乎没有任何效果。

<!ELEMENT InvoiceList (Invoice*) >
<!ELEMENT Invoice (Client, Company, TaxNumber|USt-IdNr, ServicesList, Date, Amount, BankAccount) >
<!ATTLIST Invoice NumberOfInvoice CDATA #IMPLIED>

<!ELEMENT Client (Name, Address)>
<!ELEMENT Name (#PCDATA) >

<!ELEMENT Address (Street, ZipCode, City) >

<!ELEMENT Street (Name, Number) >
<!ELEMENT Number (#PCDATA) >
<!ELEMENT ZipCode (#PCDATA) >
<!ELEMENT City (#PCDATA) >

<!ELEMENT Company (Name, Address) >
<!ELEMENT TaxNumber (#PCDATA) >
<!ELEMENT USt-IdNr (#PCDATA) >

<!ELEMENT ServiceList (Service) >
<!ELEMENT Service (Position, Name, MwSt, Quantity, SinglePrice, TotalPrice) >
<!ATTLIST Service Date CDATA #IMPLIED>
<!ELEMENT Position (#PCDATA) >
<!ELEMENT MwSt (#PCDATA) >
<!ELEMENT Quantity (#PCDATA) >
<!ELEMENT SinglePrice (#PCDATA) >
<!ELEMENT TotalPrice (#PCDATA) >
<!ELEMENT Date (#PCDATA) >

<!ELEMENT Amount (Total|Brutto, Netto, MwSt) >
<!ELEMENT Total (#PCDATA) >
<!ELEMENT Brutto (#PCDATA) >
<!ELEMENT Netto (#PCDATA) >

<!ELEMENT BankAccount (Name, Bank, BLZ, AccountNumber) >
<!ELEMENT Bank (#PCDATA) >
<!ELEMENT BLZ (#PCDATA) >
<!ELEMENT AccountNumber (#PCDATA) >

<InvoiceList>
<Invoice NumberOfInvoice="657321">
        <Client>
            <Name>Frau Sybille Sonder-Sutterrau</Name>
            <Address>
                <Street>
                    <Name>Am Süttelbach</Name>
                    <Number>17</Number> 
                </Street>
                <ZipCode>77070</ZipCode>
                <City>Siedelsuderstadt</City>
            </Address>
        </Client>
        <Company>
            <Name>Kleintier Meier GmbH</Name>
            <Address>
                <Street>
                    <Name>Meierring</Name>
                    <Number>3</Number> 
                </Street>
                <ZipCode>81828</ZipCode>
                <City>Machthausen</City>
            </Address>
            <ContactInformation>
                <PhoneNumber>0777/987987</PhoneNumber>
                <Fax>0777/987789</Fax>
                <EMail>klein.meier@tiere.de</EMail>
            </ContactInformation>
        </Company> 
        <TaxNumber>88 123/8282 2</TaxNumber>
        <ServicesList>
            <Service Date="1.1.2017">
                <Position>1</Position>
                <Name>Antike Holzwürmer</Name>
                <MwSt>19%</MwSt>
                <Quantity>100</Quantity>
                <SinglePrice>1,50</SinglePrice>
                <TotalPrice>150,00</TotalPrice>
            </Service>
            <Service Date="12.1.2017">
                <Position>2</Position>
                <Name>Holzwurmfutter</Name>
                <MwSt>19%</MwSt>
                <Quantity>1</Quantity>
                <SinglePrice>34,45</SinglePrice>
                <TotalPrice>34,45</TotalPrice>
            </Service>
            <Service Date="12.1.2017">
                <Position>3</Position>
                <Name>Steinlaus, Petrophaga lorioti</Name>
                <MwSt>19%</MwSt>
                <Quantity>1</Quantity>
                <SinglePrice>777,77</SinglePrice>
                <TotalPrice>777,77</TotalPrice>
            </Service>
        </ServicesList>
        <Date>15.1.2017</Date>
        <Amount>
            <Brutto>962,22</Brutto>
            <Netto>808,59</Netto>
            <Mwst>153,63</Mwst> 
        </Amount>
        <BankAccount>
            <Name>Kleintier Meier</Name>
            <Bank>Sparkasse Karlsruhe</Bank>
            <BLZ>66050101</BLZ>
            <AccountNumber>987654321</AccountNumber>
        </BankAccount>
    </Invoice>

我正在使用 Eclipse 来验证它。

使用 | 时,您应该将该组括在括号中。

您应该同时更新 InvoiceAmount 声明...

<!ELEMENT Invoice (Client, Company, (TaxNumber|USt-IdNr), ServicesList, Date, Amount, BankAccount) >

<!ELEMENT Amount ((Total|Brutto), Netto, MwSt) >

在这些更改之后,您的 DTD 将有效但可能不正确;您的 XML 仍然无法验证,因为仍然存在一些问题...

  • ContactInformation 不允许作为 Company 的子项(以及 ContactInformation 及其子项(PhoneNumberFaxEMail) 根本没有在 DTD 中声明)
  • 元素 ServicesList 未在 DTD 中声明。 ServiceList 已声明,因此您可能只是错过了声明名称中的 s
  • 您在 XML 中使用 Mwst 但在 DTD 中它被声明为 MwSt (注意大小写)。