Is that my XML code valid or not.
<?xml version="1.0"?>
<!DOCTYPE nahrung [
<!ELEMENT nahrung (obst|gemuese|sonstiges)+>
<!ELEMENT obst (#PCDATA)>
<!ELEMENT gemuese (#PCDATA)>
<!ELEMENT sonstiges (#PCDATA|beschreibung)*>
<!ELEMENT beschreibung EMPTY>
<!ATTLIST beschreibung artikelname CDATA #REQUIRED
preis CDATA #REQUIRED>
]>
<nahrung>
<obst>Pflaume</obst>
<gemuese>Kohl</gemuese>
<sonstiges>Keks</sonstiges>
<sonstiges><beschreibung preis="22.50"
artikelname="banane"/></sonstiges>
<gemuese>Gurke Preis: 22.50</gemuese>
</nahrung>
i have a <!ELEMENT nahrung (obst|gemuese|sonstiges)+> that means obst OR gemuse OR sonstiges only one time in xml appear and not all of them altogher.Did I understand correctly?
Your XML looks like it should successfully validate against your DTD – but I don’t think that your DTD matches what you are expecting.
Specifically, this line from your DTD:
Means that I you must have 1 or more of the elements from that list.
If you only wanted to allow one child element, for example (either obst OR gemuse OR sonstiges), you could use this: