XmlNamespaceManager

When quering XML elements that belong to a namespace, you have to create an XmlNamespaceManager, and pass it to every SelectNodes or SelectSingleNode statement you make.  This object is used to resolve the namespaces in the queries, so that you can get to the correct resultset.  You can't access the data without this feature.  To create one, you do:

XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);

I passed in the NameTable of an existing XmlDocument.  From this, you can add namespaces defined in the XML:

nsMgr.Add("DSS", "http://someuri.com/schemas/");
nsMgr.Add("XRR", "http://someuri.com/schemas/");

Then you can do this query for an element defined in the DSS namespace:

XmlNode node = doc.SelectSingleNode("Entity", nsMgr);

You can find out more about this class at:  http://msdn2.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.aspx

Published Friday, September 15, 2006 7:26 AM by bmains
Filed under:

Comments

No Comments

The leading UI suite for ASP.NET - Telerik radControls
Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.