Someone asked today how to get a list of all the namespace prefixes used in an XML document, along with their associated URIs so that that information could be used to initialize a XmlNamespaceManager. This works…
XmlNamespaceManager
XPathDocument xdoc = new XPathDocument(@"c:\temp\myfile.xml");
XPathNavigator nav = xdoc.CreateNavigator();
XPathNodeIterator nodes = (XPathNodeIterator)nav.Evaluate("//namespace::*");
Hashtable h = new Hashtable();
while(nodes.MoveNext())
{
h[nodes.Current.Name] = nodes.Current.Value;
}
foreach(string name in h.Keys)
WL("{0}:{1}",name,h[name]);
You’ll end up with a hashtable with the prefixes as keys and the associated URIs as their values. You could probably do something even cooler with a unique set datastructure, but the hashtable works in a pinch.
Powered by: newtelligence dasBlog 1.9.6264.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2008, Patrick Cauldwell
E-mail