How to: Embed HTML within XML

I spent some time today trying to figure out how to embed HTML within XML. This would obviously be an issue. When the XML would be parsed, the parser would easily mistaken the HTML tags as child XML tags.

I thought using urencode() or perhaps replacing all ‘<' and '>‘ with < and >. Then it hit me, the XML standard should have thought about this. So I checked the XML 1.0 standard. They did have a solution (remove spaces):

CDATA sections begin with the string ” < ! [C D A T A [ " and end with the string " ] ] >“

Related Articles:

Have a second? Check out this great Canadian Health & Living Store based in Toronto

3 Responsesto “How to: Embed HTML within XML”

  1. Bernard says:

    Hi,

    Thanks this helped me solve a problem of xsl stripping from the data of a node.

  2. Bernard says:

    I was saying the xsl was stripping <br /> (html breaks) from the data of a node.

  3. Aitor Elfau says:

    Thank you,

    very concise and helpful.

Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>