Get the Node value from XML

How do I use XPathNavigator.Evaluate ( or other methods in XPathNavigator) to obtain the ISBN value for the following xml input?

<?xml version="1.0"?>
<!-- a fragment of a book store inventory database -->
<bookstore xmlns:bk="urn:samples">
  <book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8">
    <title>Pride And Prejudice</title>
    <author>
      <first-name>Jane</first-name>
      <last-name>Austen</last-name>
    </author>
    <price>24.95</price>
  </book>
  <book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1">
    <title>The Handmaid's Tale</title>
    <author>
      <first-name>Margaret</first-name>
      <last-name>Atwood</last-name>
    </author>
    <price>29.95</price>
  </book>
  <book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6">
    <title>Emma</title>
    <author>
      <first-name>Jane</first-name>
      <last-name>Austen</last-name>
    </author>
    <price>19.95</price>
  </book>
  <book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3">
    <title>Sense and Sensibility</title>
    <author>
      <first-name>Jane</first-name>
      <last-name>Austen</last-name>
    </author>
    <price>19.95</price>
  </book>
</bookstore>

Answers


The answer given by amdfan is almost correct. Here's the correct syntax:

XPathIterator xit = XPathNavigator1.Select("/bookstore/book/@bk:ISBN");
xit.MoveNext();
String value = xit.Current.Value;

I tested this in VS 2008.


XPathIterator xit = XPathNavigator1.Select("/bookstore/book/@bk:ISBN");
xit.MoveNext();
String value = xit.Current.Value;

The value you want is in xit.Current.Value

By the way, I recommend you check out this great article on xPath.


Need Your Help

.NET find dead code across multiple solutions

.net visual-studio reference projects-and-solutions dead-code

We have a product with ~15 solutions with each a number of projects.

Apache + Perl + NTLM/LDAP == Single signon?

apache ldap ntlm apache-config

We have a Perl app which runs under Apache on Solaris using CGI::Application. That's all running fine. We'd like to get access to the USER_ID variable passed by the IE browser, and do some Database

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.