Invalid characters for AJAX script

January 19, 2006 / Filed under: XML

I kept getting an XML "not well formed" error in the Firefox JavaScript console.

Well-formed, I wondered? What do you mean? My XML elements were nested properly, and they all had start and end tags.

Ha. Silly me. I was confusing "well formed" with "valid."

Not all XML documents are the same. In particular, two specific descriptions can be applied to XML documents to describe the content contained within them. XML documents can be well formed, and they can also be valid. Validity implies "well-formed-ness," but not vice versa. That’s because a valid XML document is a more strict form of a well-formed XML document. It’s like saying that a square is a rectangle, but not vice versa.

Excerpt taken from the book, XML and Web Services Unleashed.

My problem? I was forgetting to "escape" certain characters - specifically the ampersand (&).

If you don’t escape the ampersand with an Ascii equivalent, your XML parser will spit up your file, in most unpleasant ways. I typically use & - but you can also use &.

Comments/Mentions