Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: this simple xpath expression doesn't work >Thread Next - Re: this simple xpath expression doesn't work Re: this simple xpath expression doesn't workTo: NULL Date: 4/5/2007 2:10:00 PM Coaster wrote: > Actually both don't work, my mistake. I had them working when I did a > SelectNodes call, I guess I'm not understanding the xpath very well I took your XML and added a closing tag (</Project>) to make it well-formed, then run the following piece of code using your XPath expressions XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(@"file.xml"); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDocument.NameTable); namespaceManager.AddNamespace("def", "http://schemas.microsoft.com/developer/msbuild/2003"); foreach (string expression in new string[] { "/def:Project/def:PropertyGroup[1]/def:OutputType/text()", "def:Project/def:PropertyGroup[1]/def:AssemblyName/text()"}) { Console.WriteLine("SelectSingleNode with expression \"{0}\" finds: {1}.", expression, xmlDocument.SelectSingleNode(expression, namespaceManager)); } and both expressions find a text node, output is SelectSingleNode with expression "/def:Project/def:PropertyGroup[1]/def:OutputType/text()" finds: System.Xml.XmlText. SelectSingleNode with expression "def:Project/def:PropertyGroup[1]/def:AssemblyName/text()" finds: System.Xml.XmlText. Make sure you use the same namespace URI in both the XML document and the .NET code with its namespace manager. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
