查询xml出错 在线等 急急急
查询代码如下:
private void Button1_Click(object sender, System.EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load("C:\\Inetpub\\wwwroot\\test\\booksort.xml");
XmlNode book;
XmlNode root = doc.DocumentElement;
book=root.SelectSingleNode("descendant::book[price='24.95']");
//Change the price on the book.
book.LastChild.InnerText="15.95";
Console.WriteLine("Display the modified XML document....");
doc.Save(Console.Out);
}
xml文档如下:
<?xml version="1.0"?>
<!-- a fragment of a book store inventory database -->
<bookstore xmlns="http://tempuri.org/booksort.xsd" xmlns:bk="urn:samples">
<book genre="novel" publicationdate="1997">
<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">
<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">
<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">
<title>Sense and Sensibility</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
</bookstore>
出错信息如下:
未将对象引用设置到对象的实例。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 65: book.LastChild.InnerText="15.95";
另外我想知道书写xpath的规则