Reputation: 13002
this is getting to my brain so i have a XML doc that has a node called family
<family>
<parents>
<name>Bob</name>
<init>R</init>
<surname>Johnson</surename>
</parents>
<kids>
<name>Lucy</name>
<surname>Johnson</surname>
</kids>
</family>
the inital is optional so i create the DTD for this it ends up looking like
<!ELEMENT parent (name, initial?, surname)>
<!ELEMENT kid (name, initial?, surname)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT initial (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT initial (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
but i keep getting this error validity error : Redefinition of element name ^ /tmp/tmp.dtd:26: validity error : Redefinition of element initial ^ /tmp/tmp.dtd:27: validity error : Redefinition of element surname ^
even if i change the DTD to look like this.
<!ELEMENT parent (name, initial?, surname)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT initial (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
<!ELEMENT kid (name, initial?, surname)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT initial (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
same error.. this is literally the second day i am using xml and from the tutorials i have read i cant seem to see what i am doing wrong..
Upvotes: 1
Views: 3618
Reputation: 122364
You don't need to declare the name
, initial
and surname
twice, just try
<!ELEMENT parent (name, initial?, surname)>
<!ELEMENT kid (name, initial?, surname)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT initial (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
parent
and kid
share the same definitions for their three (or two) child elements. Given an additional definition of
<!ELEMENT family (parent*, kid*)>
this would validate the following (corrected from the document you included in the question)
<family>
<parent>
<name>Bob</name>
<initial>R</initial>
<surname>Johnson</surname>
</parent>
<kid>
<name>Lucy</name>
<surname>Johnson</surname>
</kid>
</family>
Upvotes: 3