user3664490
user3664490

Reputation: 217

XML DTD parent element same with child element

in my xml:

<mother>
     <name>mary</name>
     <child>
          <name>Ali</name>
     </child>
</mother>

so in my dtd:

<!ELEMENT mother (name,child)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT child (name)>
<!ELEMENT name(#PCDATA)>

when i try to run the DTD, its said that my name already been declared. so how i should change in order to solve this problem?

Upvotes: 1

Views: 663

Answers (1)

helderdarocha
helderdarocha

Reputation: 23637

You don't need the second name declaration. These three declarations:

<!ELEMENT mother (name,child)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT child (name)>

are sufficient to validate your file. Your DTD "says":

  1. The <mother> element must contain a sequence of one <name>, followed by one <child>
  2. The <name> element can contain parsed character data (any text, including nothing, but no tags)
  3. The <child> element must contain exactly one <name>

Upvotes: 1

Related Questions