In trying to convert this blog I had to knock up an application to read dasBlog dayentry files and write out a large RSS style wordpress import file.

Now I don’t do XML that often but when I do its been with simple XML so a quick “//Entries” XPath query and away you go.  However the dasBlog XML is done properly with lots of namespaces.

So when I’ve been doing my simple XPath query it returns nothing.  So for those having similar problems the solution is this.  You need a namespace manager.

Here is a quick code snippet that explains how you would use it.

 

XmlNamespaceManager mgr=new XmlNamespaceManager(xmlDoc.NameTable);
mgr.AddNamespace(“def”,”urn:newtelligence-com:dasblog:runtime:data”);

foreach(XmlNode innerNode in xmlDoc.SelectNodes(“//def:Entry”,mgr) )
{
    //Do things with innerNode;
    title=innerNode.SelectSingleNode(“def:Title”,mgr).InnerText;
    //Do more things
}

Simple as that.

tags: , , , ,

Advertisements