Arjan's World: Debugging XML Code
You are now being redirected to the new housing of Arjan's World. Click here in case nothing happens

Friday, April 01, 2005

Debugging XML Code

Lately I've been putting up a small XMLHTTPRequest - or should I say Ajax - application on our intranet. This gave me the opportunity to dive a bit into the features of behind-the-scenes JavaScript generated XML-based server roundtrips. While it looks very complicated on the outside, the code to make the magic happen is quite straightforward, and not even bleeding-edge: it's just an old trick with a new name. The difference is, that now you see libraries popping up here and there that make using this technique more straightforward.

I had some trouble in getting my XML document to work, but in the end using ISO-8859-1 as XML-encoding turned out to do the trick. The encoding I was using before, and to which I really didn't give a second thought, turned out not to be able to recognize the special non-ASCII chars like รถ that are in my returned string. Implementing a
<?xml version="1.0" encoding="ISO-8859-1" ?>
was seemed all that was neccessary. However, after getting the behind-the-scenes processing to work, I started a little testing. Suddenly, for one of the categories, I did not see a response in my HTML page. That was odd, since there definetely was output. I fired up the XML page supposed to harvest the result from the database, and it worked for all categories, except this one:
Whitespace is not allowed at this location.
Error processing resource file

Well, the decision was quickly made to look for odd characters in the response. The only really strange one I found was '&', and indeed the response was shown in my little browserwindow the minute the & was removed from the stream. But that of course was only the problem, not the solution to the problem, as this character definetely needs to be used in the output. Then again, I could Replace the character out and think I'm done. But in the back of my head there was this nagging voice telling me it's just waiting for another character to show up and stir things up. Firing up Google was the way to go: This Usenet posting has the definite answer. The & character is used as an escape character and therefore breaks the XML stream when it is used literally. Fixing this by replacing & with it's HTML equivalent &amp; was trivial. It's always good to see a little problem solved, even if it takes almost an hour to fix ...

0 Comments:

Post a Comment

<< Home