Reputation: 1543
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?
Upvotes: 0
Views: 67
Reputation: 28697
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:
<!ELEMENT nahrung (obst|gemuese|sonstiges)+>
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:
<!ELEMENT nahrung (obst|gemuese|sonstiges)>
Upvotes: 2
Reputation: 143119
The (obst|gemuese|sonstiges)+
means either one of those 1 or more times. Meaning this xml is valid.
Upvotes: 1
Reputation: 81694
This
(obst|gemuese|sonstiges)+
means "any non-zero number of obst
, gemuese
, and sontiges
elements, in any order."
Upvotes: 1