Prev: Xml // Reading Element Value // Namespace issue // XPathExpression XmlNamespaceManager
Next: dynamic loaded ascx delegate event not firing in parent form
From: Martin Honnen on 22 Feb 2010 11:45 sloan wrote: > <?xml version="1.0" standalone="yes"?> > > <sdnList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns="http://tempuri.org/sdnList.xsd"> > > <publshInformation> > > <Publish_Date>02/10/2010</Publish_Date> > > <Record_Count>4301</Record_Count> > > </publshInformation> > > </sdnList> The following should suffice: XPathDocument doc = new XPathDocument("input.xml"); XPathNavigator nav = doc.CreateNavigator(); XmlNamespaceManager mgr = new XmlNamespaceManager(nav.NameTable); mgr.AddNamespace("df", nav.SelectSingleNode("*").NamespaceURI); Console.WriteLine(nav.SelectSingleNode("//df:Publish_Date", mgr).Value); Or use LINQ to XML: XElement root = XElement.Load(@"..\..\XMLFile1.xml"); XNamespace df = root.Name.Namespace; Console.WriteLine(root.Descendants(df + "Publish_Date").First().Value); -- Martin Honnen --- MVP XML http://msmvps.com/blogs/martin_honnen/ |