Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: How to get value of attribute (XPath)? [Thread Next] Re: How to get value of attribute (XPath)?To: NULL Date: 10/7/2009 10:40:00 AM "Martin Honnen" <mahotrash@y...> wrote in message news:%23VY7Pf1RKHA.4028@T...... > LJB wrote: >> I've been trying to return the value of an attribute named "server" but >> keep getting an XPathSelectionIterator. What do I need to change? The >> following returns "1" which is what I expected. >> Console.WriteLine(nav.Evaluate("count(//location[@office='JAC'])")); >> I'm thinking it should be something like >> Console.WriteLine(nav.Evaluate("//location[@office='JAC']/@server")); >> but that doesn't give me the value. > > If you want to access a single node you might want to use SelectSingleNode > instead of Evaluate, that way you get an XPathNavigator and can access the > Value property e.g. > > XPathNavigator server = > nav.SelectSingleNode("//location[@office='JAC']/@server"); > if (server != null) // XPath found node > { > Console.WriteLine(server.Value); > } > else // handle case that no node was found > { > // > } > > > -- > > Martin Honnen --- MVP XML > http://msmvps.com/blogs/martin_honnen/ THANK YOU. It works perfectly. | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
