Note: This blog entry has been superseded by the comment from Chris below. Use the xml status property instead. Posting one's ignorance is one way to learn. I guess the corrected blog should simply say: "check the status code in addition to the onLoad success argument."
If an XML file is created manually or edited manually, it is easy to misspell a closing tag, misplace a greater than sign or forget a quote mark – it's easy to create non-well-formed xml. Flash will not be able to read it and your application will fail. Furthermore, it might load some of the data and operate in a mysterious, crippled fashion, and the cause of the problem will not be obvious.
The easiest way to prevent this is to use a xml editor that will tell you if your xml is well-formed. I use a free version of XMLSpy, but I can't find the free version on their website anymore. Visual Studio also works. I'm sure there are others.
But sometimes your client will edit the file, or a co-worker who does not use such an editor. Maybe the xml files is a configuration file that the client will want to change periodically, and maybe your client likes to use notepad. Maybe the xml is edited remotely with an ftp-based editor. If they do make a mistake, your Flash app will not work. You will get blamed.
It would be nice if there were an easy way to check whether the xml is well-formed in the Flash app itself.
Fortunately, AS3 throws an exception when it reads an xml file that is not well formed. No problem there.
Flash 8, however, does not complain at all. If it reads an invalid xml file, it merely stops parsing when it encounters a problem. Your XML onLoad function is called with success set to true. Your application will execute with partial data and who knows what will happen.
Here’s my simple solution: I add a final node to the xml named “well-formed”. It must be there. If, after parsing the xml, that node is not present, the xml is not well formed and an error message is displayed.
Here's what the xml looks like.
And here's the ActionScript:
Yes, this technique is so simple as to be trivial, but it has saved me much grief.
