Search code examples
xmlelementdtdpcdata

DTD Element: Alternative between text and element


I want to define a dtd for my xml document.

In this dtd, I have an element called

p

. p can contain either #PCDATA or another element (img). How can i declare this? I tried this:

<!ELEMENT p (#PCDATA | img)>
<!ELEMENT img EMPTY>

But that doesn't work. Response error: Error: '>' is an unexpected token. The expected token is '*'. When I try this:

<!ELEMENT p ((#PCDATA) | img)>
<!ELEMENT img EMPTY>

the error occurred: Error: Name cannot begin with the '#' character, hexadecimal value 0x23.

How can I achieve that p contains text or another element img? It's necessary that both options are working. One of the two options must be implemented.

<p>some text</p>

and

<p><img src='...' /></p>

Greetings!


Solution

  • Mixed content models must have occurrence constraint of zero or more.

    <!ELEMENT p (#PCDATA | img)*>