Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: this simple xpath expression doesn't work

From: "Coaster" <Coaster@-------.--->
To: NULL
Date: 4/5/2007 11:48:00 PM

ok thanks. I was making some very stupid mistakes in my order of things but 
your example helped. Thanks


"Martin Honnen" <mahotrash@y...> wrote in message 
news:%23f%23cht3dHHA.4188@T......
> 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/ 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent