in

WPF Design and Development

IdentityMine Team Blogs

David Kelley

A day in the life of a humble software architect... doing C#, WPF, Silverlight, Legos, Fuzzy Logic AI and/or whatever is the latest and greatest or more importantly the coolest techo mumbo jumbo...

Parsing XML in Silverlight 1.0 - Cross Browser

So the little XML mini me is great for simple stuff but when you really need to do real work with XML you really need a more robust solution that includes a real XML parser.  Now that can prove problematic especially when it has to work in lots of browsers.  To address this problem with my own work I wrote another class that wraps the cross browser functionality and wraps some key elements that I use.  Typically I need things like all of properties of a given node in a list in the form of an array.  Plus things like xPath and the like for Silverlight. 

 So the attached javascript class wraps the core functionality.  It includes the HTTP request functionality and XML parsing with the other bits I 'might' need.  Basically the class works like this:

var NewDOM = new XML();
NewDOM.Load("Sample.xml");

This code fires when the html page script code behind fires.  When you call 'Load' and pass a url to an xml file it then depending on the browser it uses the appropriate HTTP request object to load the file and assign the onload event.  On the XML files load the call back is called and the object does the appropriate processing.  Once this does its thing we now can use it to parse our XML. 

On the onload event for the page in my little test I make two calls to different methods.  The same methods are supported on this class as the XML mini me but additional ones are included like 'SelectNodesAttributes'.  Also I noticed in firefox by 'onload event gets called twice so I put a flag on it so it only fires once.  So in this sample I call the two methods that return arrays but you can have direct access to the DOM and use xPath etc using NewDOM.XmlDocument.

Comments

No Comments

About david.kelley

David for the past 10 years has focused on distributed application design and emerging Microsoft technologies on the web. Having helped design and build some of the largest systems for companies like Microsoft, Onyx Software, Saltmine, Giordanous Group and more and of course our favorite company Identitymine, he has been on the leading edge of applying the latest tech to real world business problems. David’s technology breadth includes everything from SQL Server to Windows/WCF and Silverlight. David’s accomplishments also include developing new technologies such as self editing XML files and related XML technologies to fuzzy logic systems and advanced web user interface design.
© 2007 IdentityMine, Inc.
Powered by Community Server (Commercial Edition), by Telligent Systems