helpful sql wrote:
I load an xml file into XmlDocument object and would like to get a list
of namespaces used in the file. How can I get a list of namespaces used in
xml file?
XPath has a namespace axis for namespace nodes which are in scope for a
given element node, here is an example using an XPath expression with
SelectNodes to output all namespace nodes (those explictly given and
those implictly defined):
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"test2005052501.xml");
XmlNodeList namespaceNodes =
xmlDocument.SelectNodes("//*/namespace::*");
foreach (XmlNode node in namespaceNodes) {
Console.WriteLine(
"Node type {0} has name \"{1}\" and value \"{2}\".",
node.NodeType, node.Name, node.Value);
}
Note that you will get a lot of duplicates that way so you would need to
filter that list further to remove duplicates.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/