Ok, I have a simple xml file with a default namespace as shown here:
< test xmlns="http://www.shaune.net/test">
< config>
< data>test< /data>
< settings>
< moredata>test< /moredata>
< /settings>
< /config>
< /test>
I loaded the xml file using
XmlTextReader reader = new XmlTextReader("C:\\xml\\My.Config.xml" );
nsm = new XmlNamespaceManager(reader.NameTable);
//I read that this is how you specify a default namespace
nsm.AddNamespace("", "http://www.shaune.net/test");
configDoc.Load(reader);
reader.Close();
and then I do a SelectSingleNode
XmlNode test2 = configDoc.SelectSingleNode("//Config");
This should work right? Wrong!!!
It turns out that XPath 1.0 doesn't support default namespace. XPath 2.0 does but I guess that doesn't help right now with .net 2.0.
What I needed to do was give the default namespace a name
nsm.AddNamespace("cfg", "http://www.shaune.net/test");
Then all my selects need to specify this namespace
XmlNode test2 = configDoc.SelectSingleNode("//cfg:Config");
What a pain.