// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Xml; using System.Xml.XPath; namespace E { public class Program { public static void Main(string[] args) { XmlDocument doc1 = new XmlDocument(); doc1.Load(@"C:\history.xml"); XmlNamespaceManager nsm1 = new XmlNamespaceManager(doc1.NameTable); nsm1.AddNamespace("defns", "http://www.hest.dk/changelog"); nsm1.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Console.WriteLine(doc1.SelectSingleNode("//defns:history/defns:foobar", nsm1).OuterXml); XPathDocument doc2 = new XPathDocument(@"C:\history.xml"); XPathNavigator nav = doc2.CreateNavigator(); XmlNamespaceManager nsm2 = new XmlNamespaceManager(nav.NameTable); nsm2.AddNamespace("defns", "http://www.hest.dk/changelog"); nsm2.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Console.WriteLine(nav.SelectSingleNode("//defns:history/defns:foobar", nsm2).OuterXml); } } }