Document structure
Mixed content
An element containing both text and child elements, interleaved — the model prose uses and data rarely does.
Mixed content is what XML was built for: a paragraph with emphasis inside it, a description with a link in the middle. The text between and around the children is content in its own right, and its position matters.
It is also what makes XML awkward to convert. JSON has no way to express text interleaved with objects, so every XML-to-JSON conversion either loses the interleaving or invents a representation for it. If your documents carry mixed content, check what your converter did before trusting the output.
- Defined in
- XML 1.0 §3.2.2
- Category
- Document structure
- Also written
- text and elements, #PCDATA model
Shown, not asserted
All 3 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.
The children include text nodes, not just elements.
document.xml <p>Some <b>bold</b> text.</p>expression count(/p/node())What the engine returns
3The element's string value is all of the text, in document order.
document.xml <p>Some <b>bold</b> text.</p>expression string(/p)What the engine returns
Some bold text.A minifier must leave that whitespace alone: dropping it would join words together.
document.xml <p>Some <b>bold</b> text.</p>What the engine returns
minify <?xml version="1.0"?> <p>Some <b>bold</b> text.</p>
What catches people out
- Whitespace in mixed content is significant. Pretty-printing such a document changes what it says.
- XML-to-JSON conversion cannot represent interleaving faithfully. Expect the text and the children to be separated.
- A DTD content model for mixed content can constrain which elements may appear but never their order or number.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- ToolsXML to JSON converterShows what happens to interleaved text when the tree becomes an object.
- ToolsXML minifierDrops only the whitespace that is safe to drop, which is why mixed content survives it.
- FormatsSVGA format where mixed content carries real meaning, inside <text>.
Related terms
- Text nodeA run of character data in the tree, as a node in its own right — the model a query language sees rather than the markup you wrote.
- PCDATAParsed character data: text content that the parser scans for markup, so < and & in it have meaning and must be escaped.
- Significant whitespaceWhitespace that is part of a document's content, as opposed to indentation a processor may drop.
- Content modelThe rule saying what an element may contain: which children, in what order, how many times, and whether text is allowed.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.