<?xml version="1.0" encoding="utf-8" ?>
<!-- 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>如何从上面文件获得想要元素  
比如 
price为19.95的author

解决方案 »

  1.   

    XPATH也不能解决吗。
    /bookstore/book[Price="19.95"]
    这样至少能找到price为19.95的全部book出来
    再想取得author不就水到渠成了
      

  2.   

    xmlpath就可以阿/bookstore/book[price='19.95'/author]
      

  3.   

    /bookstore/book[price='19.95']/author] 少了一括号
      

  4.   

    xmlpath拼路径  楼上说的很详细了
      

  5.   

     /// <summary>
            /// 读取指定节点的值(InnerText)
            /// </summary>
            /// <param name="strNode">节点名称</param>
            /// <returns></returns>
            public string GetXmlNodeValue(string strNode)
            {
                string strReturn = String.Empty;
                try 
                {
                    XmlNode xmlNode = xmlDoc.SelectSingleNode(strNode);
                    if (xmlNode != null)
                    {
                        strReturn = xmlNode.InnerXml;
                    }
                }
                catch (XmlException xmle)
                {
                    throw xmle;            
                }
                return strReturn;
            }