0

如何使用XPathNavigator.Evaluate(或 XPathNavigator 中的其他方法)获取以下 xml 输入的 ISBN 值?

<?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>
4

2 回答 2

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

你想要的价值在xit.Current.Value

顺便说一句,我建议您查看这篇关于 xPath 的精彩文章。

于 2008-11-24T03:29:49.863 回答
3

amdfan 给出的答案几乎是正确的。这是正确的语法:

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

我在 VS 2008 中对此进行了测试。

于 2008-11-24T04:42:35.960 回答