1

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

cksrc
  • 2,062
  • 3
  • 24
  • 39

1 Answers1

2

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)* >
potame
  • 7,597
  • 4
  • 26
  • 33
  • this is exactly what I ended up doing just after posting the question :) – cksrc Jun 23 '15 at 12:44
  • In [this post](https://stackoverflow.com/questions/29960711/can-there-be-text-and-additional-nodes-in-xml/29960968#29960968) I answered to, you will also find the references regarding *mixed content*. This [other post](https://stackoverflow.com/questions/24389351/dtd-element-type-declaration-different-between-contentspec-and-content-mode) as well is around the subject. – potame Jun 23 '15 at 12:52