Sunday, June 06, 2004
XPath - Handling Default Namespaces in System.Xml
After being burned by this one time, I've learned my lesson... When you want to query and XML document that has a default namespace in the .NET framework you must use an XmlNamespaceManager to help with the queries, like this:
XmlNamespaceManager nsMan = new XmlNamespaceManager(xmlListCollection.NameTable);
XmlNodeList lists = xmlListCollection.SelectNodes("//ns:Lists/ns:List", nsMan);
The XmlNamespaceManager handles a variety of namespace-related tasks within the .NET Framework. The XPath specification makes no provision for the concept of a default namespace.