我这里有一个xml文件。如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book genre="fantasy" ISBN="2-3631-4">
    <title>Oberon's Legacy</title>
    <author>Corets, Eva</author>
    <price>5.95</price>
  </book>
</bookstore>
我想用C#应用程序将title或是price不管里面的那个接点都能单独的显示出来。怎么做那。谢谢大家了。

解决方案 »

  1.   

    XmlNode xn=xmlDoc.SelectSingleNode("bookstore");
     
       XmlNodeList xnl=xn.ChildNodes;
       
       foreach(XmlNode xnf in xnl)
       {
        XmlElement xe=(XmlElement)xnf;
        Console.WriteLine(xe.GetAttribute("genre"));//显示属性值
        Console.WriteLine(xe.GetAttribute("ISBN"));
     
        XmlNodeList xnf1=xe.ChildNodes;
        foreach(XmlNode xn2 in xnf1)
        {
         Console.WriteLine(xn2.InnerText);//显示子节点点文本
        }
       }楼主详细可以参见:
    http://www.blogcn.com/user63/rhfan2005/blog/25161802.html
      

  2.   

    XmlNode title = doc.SelectSingleNode("bookstore/book/title");
    XmlNode price = doc.SelectSingleNode("bookstore/book/price");