fobi
fobi

Reputation: 65

XML & DTD: The content of element type must match

I'm learning XML at the moment and I'm struggling with the first DTD extenstion. My XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE Activities [
<!ELEMENT Activities (ToDo)>
<!ELEMENT ToDo (Household,Cat,House,Bills,Groceries)>
<!ELEMENT Object (Cat,House,Bills,Groceries)>
<!ELEMENT Cat (#PCDATA)>
<!ELEMENT House (#PCDATA)>
<!ELEMENT Bills (#PCDATA)>
<!ELEMENT Groceries (#PCDATA)>
<!ATTLIST ToDo id CDATA #IMPLIED>
<!ATTLIST Object id CDATA #IMPLIED>
]>
<Activities>
<ToDo id="Household">
<Object id="Cat">
    <ToDo>bathe</ToDo>
</Object>
<Object id="House">
    <ToDo>vacuum</ToDo>
</Object>
<Object id="Bills">
    <ToDo>pay</ToDo>
</Object>
<Object id="Groceries">
    <ToDo>Buy</ToDo>
</Object>
</ToDo>
</Activities>

The XML Validation (http://xmlvalidation.com) tells me that "The content of element type "ToDo" must match" and that "The content of element type "Object" must match".

What am I doing wrong? Thanks a lot in advance!

Upvotes: 1

Views: 3158

Answers (1)

tolanj
tolanj

Reputation: 3724

<!ELEMENT ToDo (Household,Cat,House,Bills,Groceries)>

For example does not allow Object as a Child but HouseHold etc, ie change Xml to:

<Activities>
  <ToDo id="Household">
    <HouseHold/>
    <Cat>
      xxx
    </Cat>
    <House>
      yyy
    </House>
     .....
  </ToDo>
</Activities>

whence you will clear the 'Outer' "The content of element type "ToDo" must match

Now you also have Inner ToDo items in say Cat, ie <ToDo>bathe</ToDo> however you DTD says: <!ELEMENT ToDo (Household,Cat,House,Bills,Groceries a ToDo must have a Houshold, then a Cat etc, ie it cant just be text.

also <!ELEMENT Cat (#PCDATA)> says A Cat must only contain text.

Its not clear what you are aiming for but remove Household from <!ELEMENT ToDo (Household,Cat,House,Bills,Groceries whence

<Activities>
  <ToDo id="Household">
    <Cat id="1">
      bathe
    </Cat>
    <House id="2">
      vacumm
    </House>
     .....
  </ToDo>
</Activities>

Would satisfy the DTD

Upvotes: 1

Related Questions