Stefan Hristov
Stefan Hristov

Reputation: 47

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

I am writing a DTD to my XML file. I get this same error "A ')' is required in the declaration of element type "Invoice"" on the element "Invoice". My DTD matches my XML, names are correct, order of elements is correct. Any help would be appreciated. Below are my DTD and XML files.

I've tried reordering the elements of the DTD, looked at my XML to try and find a mistake there, but nothing seems to work.

<!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>[email protected]</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>

I am using Eclipse to validate it.

Upvotes: 2

Views: 122

Answers (1)

Daniel Haley
Daniel Haley

Reputation: 52858

When using | you should wrap that group in parentheses.

You should update both Invoice and Amount declarations...

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

and

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

After those changes your DTD will be valid but perhaps not correct; your XML still won't validate as there are still a few issues...

  • ContactInformation isn't allowed as a child of Company (and ContactInformation and it's children (PhoneNumber, Fax, and EMail) aren't declared at all in the DTD)
  • The element ServicesList isn't declared in the DTD. ServiceList is declared though so you probably just missed the s in the name of the declaration.
  • You use Mwst in the XML but in the DTD it's declared MwSt (pay attention to case).

Upvotes: 1

Related Questions