Preserving HTML in XML

Characters like “<” and “&” are illegal in XML elements. “<” will generate an error because the parser interprets it as the start of a new element. “&” will generate an error because the parser interprets it as the start of an character entity. Some text, like JavaScript code, contains a lot of “<” or “&” characters. To avoid errors, we need to parse the code using CDATA (Character Data) like so:

<!CDATA[
xxxxxxxxxxxxxxx
]]>

This is different from commenting. Commenting skips the whole section entirely, like so:

<!–
xxxxxxxxxx
–>

which is just like HTML comments.

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Sitecritic.net Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.

1 thought on “Preserving HTML in XML”

  1. OMG; The blog site Preserving HTML in XML | LAMP How To – Open Source At Work rocks ! How have one insure that it is look this good 🙂 Incidentally did you hear Obama remarkable headlines? Thx ! Rob Rasner Facebook

Comments are closed.