Question

I am trying to create an XML file with a DTD, but in Netbeans it doesn't give me any errors, but in Oxygen XML it states Unexpected element "childone". The content of the parent element type must match "((c:childone,c:childtwo)|(childone,childtwo,childthree,childfour))".

The XML I have is as follows:

<rootelement>
   <c:childone></c:childone>
   <c:childtwo></c:childtwo>
   <childone></childone>
   <childtwo></childtwo>
   <childthree></childthree>
   <childfour></childfour>
</rootelement>

The DTD I have as follows:

<!ELEMENT rootelement ((c:childone,c:childtwo)|(childone,childtwo,childthree,childfour))>
<!ELEMENT c:childone (#PCDATA)>
<!ELEMENT c:childtwo (#PCDATA)>
<!ELEMENT childone (#PCDATA)>
<!ELEMENT childtwo (#PCDATA)>
<!ELEMENT childthree (#PCDATA)>
<!ELEMENT childfour (#PCDATA)>

I'm confused now, please help. Hope I formatted this correctly.

Was it helpful?

Solution

The DTD says the contents of <rootelement> can be one of two forms; your actual document contains both of them. Pick one, or change the DTD.

I suspect Netbeans is simply not validating, and hence is not noticing the problem.

By the way, DTDs are VERY poorly suited to working with namespaced documents -- and I certainly hope you've bound the c: prefix to a namespace! -- so I'd strongly recommend switching to XML Schemas, which are a more powerful replacement for DTDs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top