Tuesday, June 10, 2008

handling xml in .net

For some funky reason, MS has decided to only offer two extremes when it comes to dealing with XML. You may either use the XmlTextReader method, which requires you to create your own parser from scratch, or you may use XmlDocument, which reads everything into memory and gives you a tree to work from. The problem with XmlDocument is that it will toss an exception on "malformed" (but acceptable to other XML parsers) XML.

It quickly turns into a gooey, tarry mess... especially if you have a 6000 line xml file that you know is malformed and you're trying to read it into a program so that you can fix it. /o\

I found a tutorial on how to build a simple DOM parser (along with sample code) in C# that helped me stop thrashing around with the nuances of XmlDocument and get going in about 20 minutes. Perfect for the Perl/Ruby/Python hacker caught in this strange world of strong types. :)

No comments: