0

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.

Shon
  • 690
  • 6
  • 22
Dino
  • 561
  • 3
  • 10
  • 21

1 Answers1

1

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.

keshlam
  • 7,931
  • 2
  • 19
  • 33
  • I am actually creating a DTD and schema. But I'm creating the DTD first then the schema. The c: is a prefix to a namespace. I'm still learning. I thought I could have an "or" to select either the ones with the prefix of the c or the ones without in the DTD, but obviously not. – Dino Feb 14 '14 at 20:47
  • The or is between two different sets of content. As you've written it, you can have one set (prefixed) or the other set (non-prefixed) but not both. If you wan to allow a mix, the grammar has to say so. Unless you have a very specific reason for dealing with them, these days I'd skip DTDs. – keshlam Feb 14 '14 at 21:01
  • Ah I see so technically my DTD must be changed ot I must remove one of the group of elements, either the preceding ones or the ones that don't precede. – Dino Feb 15 '14 at 06:45