How to define dtd element with XOR

402 Views Asked by At

I have an xml element vehicle that can have as sub-elements either car XOR truck XOR a combination of multiple #PCDATA OR bus. How do I write the dtd?

<?xml version="1.0" encoding="UTF-8" ?>
    <!ELEMENT root (vehicle)*>
    <!ELEMENT vehicle (truck|car|(#PCDATA|bus)*)>

The above fails with error

parser error : ContentDecl : Name or '(' expected

1

There are 1 best solutions below

2
On BEST ANSWER

It's not possible in XML. Once you need to define a content model allowing text (#PCDATA) and elements - also named mixed content - , you MUST define it that way :

(#PCDATA | element1 | element2 | ...)*

A workaround for your case can probably be :

<!ELEMENT vehicle (truck|car|buscontent)>
<!ELEMENT buscontent (#PCDATA | bus)* >