Thursday, October 4, 2012

List all namespaces in an XML document using XMLNamespaceManager


Use this below code to get the list of all namespaces.

            XPathDocument xdoc = new XPathDocument(string.Format(@ " {0}\[filename].xml",Environment.CurrentDirectory));
            XPathNavigator nav = xdoc.CreateNavigator();
            XPathNodeIterator nodes = (XPathNodeIterator)nav.Evaluate("//namespace::*");
         
            while (nodes.MoveNext())
            {
                Console.WriteLine(string.Format("{0} : {1}", nodes.Current.Name, nodes.Current.Value));
            }


No comments:

Post a Comment