Paul's Dev Blog – iGonzo.net

Word to my fellow nerds.

Archive for the ‘xml’ tag

ASP hates XML

without comments

This is what I thought. For the last day or so I have been trying to get a silly little (well, quite large actually) XML string to import into a database table.

After my previous troubles with just getting the data file, I thought I was in the clear. However, it seems that some of the nodes within the taget XML file contained characters that XML did not like at all. Mostly those characters that have squiggly little lines and flourishes above them. And despite my efforts, I just could not get them to import or to simply skip that data node.

So have spending more hours than I care to admin banging my head against the desk, I stepped back to examine the problem from its most basic form.

The simplified problem was this: I have a string of text that I need to parse and put into the database. There is a character or three preventing that.

The simplified solution was this: Remove the offending character.

Trouble was, I could not get the character targeted for a replace, as it was being processed according to whatever format the MS XMLHTTP object uses. Then it hit me. No matter what, information has to get passed, and the only want to ensure this was to convert certain characters to their HTML equivalents, such as   for spaces, < for brackets, etc. This is basic to every form of data transmission on the web.

So the simplified plan of attack now was this: Convert the entire XML string to and HTML encoded string; Find the HTML encoded character and replace it; Decode the string back to an XML string.

Once I had that plan it was stupidly simple to convert, replace, and then convert back to XML. I piped that into my DB input script and it worked.

So kids, the moral of the story is this: Step back once in a while to examine the problem. And then break it down (or convert it) to its most basic workable form. After that, solutions tend to pop up faster than just mucking about with fancy object functions.

-Cheers

Written by iGonzo

July 20th, 2011 at 1:20 pm