Jay Nathan's Weblog
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);
nsMan.AddNamespace("ns", "http://schemas.microsoft.com/sharepoint/soap/");

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.

Comments: Post a Comment

<< Home

Powered by Blogger