Search code examples
xmlnodesmarkup

Is it wrong in XML to have element nodes as siblings of text nodes?


Is the following "allowed" or simply bad use of XML? I cannot find restrictions on this, but it feels a bit weird.

<example>
    You can choose from
    <option>this</option>
    <option>that</option>
    <option>something else</option>
    Choose wisely.
</example>

If it is wrong, what is a nice alternative?


Solution

  • No, mixing elements and text is completely normal in XML.

    You may be more familiar with data-oriented uses of XML, but XML actually evolved from a basis in representing documents, where marking up text within other text is the norm. Its predecessor, SGML, was like this, and HTML is still like this today.

    In XML Schema (XSD), mixed="true" designates mixed text in a content model.