Anyone know what the best practices are or have general advice around having HTML/XHTML content within an XML element? Is it best to use CDATA or to just HTML encode the HTML?
Anyone know what the best practices are or have general advice around having HTML/XHTML
Share
I would recommend CDATA; it will make the XML smaller and more easily human-readable.
However, make sure to escape
]]>as]]>]]<![CDATA[.EDIT: As other people have said, if you control the HTML that you’re embedding, and you know that it will always be valid XHTML, then you should nest it directly without escaping.
However, if you don’t control the HTML, I might not recommend that. Even if it’s valid now, it might one day become invalid, and you do not want your system to suddenly break because of that. Obviously, this depends on the circumstances and the use case; if you want a more precise recommendation, please give us more detail.