Copyright © 2010 Silmaril Consultants
Rev: 2010-04-24T15:52:33+0100

Provide for it in the output, use a deep copy, or try disable-output-escaping.C.29  How can I handle embedded HTML in my XML?

Apart from using CDATA Sections, there are two common occasions when people want to handle embedded HTML inside an XML element:

  1. when they have received (possibly poorly-designed) XML from somewhere else which they must find a way to handle;

  2. when they have an application which has been explicitly designed to store a string of characters containing < and & character entity references with the objective of turning them back into markup in a later process (eg FreeMind, Atom).

Generally, you want to avoid this kind of trick, as it usually indicates that the document structure and design has been insufficiently thought out. However, there are occasions when it becomes unavoidable, so if you really need or want to use embedded HTML markup inside XML, and have it processable later as markup, there are a couple of techniques you may be able to use:

For more details of using these techniques in XSL[T], see the relevant question in the XSL FAQ.

Tip

Read question C.28, ‘When should I use a CDATA Marked Section?’ as well, which is very closely related.