当前位置:编程学习 > C#/ASP.NET >>

关于xml中的读取

有xml文件如下:
  <?xml version="1.0" ?> 
- <!--  This file represents a fragment of a book store inventory database 
  --> 
- <bookstore>
- <book genre="autobiography" publicationdate="1981" ISBN="1-861003-23-0">
  <title>The Autobiography of Benjamin Franklin</title> 
- <author>
  <first-name>Benjamin</first-name> 
  <last-name>Franklin</last-name> 
  </author>
  <price>8.99</price> 
  </book>
- <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
  <title>The Confidence Man</title> 
- <author>
  <first-name>Herman</first-name> 
  <last-name>Melville</last-name> 
  </author>
  <price>11.99</price> 
  </book>
- <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
  <title>The Gorgias</title> 
- <author>
  <name>Plato</name> 
  </author>
  <price>9.99</price> 
  </book>
  </bookstore>

   我想得到每一个<book genre="autobiography" publicationdate="1981" ISBN="1-861003-23-0"> 中的genre="autobiography" publicationdate="1981" ISBN="1-861003-23-0"这个数据,请问怎么得到!??
--------------------编程问答-------------------- MSDN中查一下xpath --------------------编程问答-------------------- 看一下xmlDocument --------------------编程问答-------------------- XmlDocument xmlRequestDoc = new XmlDocument();
xmlRequestDoc.LoadXml(Xml);
XmlNodeList xNodes = xmlRequestDoc.SelectNodes("bookstore/book"); 
foreach(XmlNode xNode in xNodes)
{
   string str = xNode.Attributes["genre"].Value; 
   ...
} --------------------编程问答-------------------- 嗯,就是楼上的方法 --------------------编程问答-------------------- XPathDocument doc=new XPathDocument("FileName");
XPathNavigater nav=doc.CreateNavigator();
XPathNodeIterator iter=nav.Select("/bookstore/book/[@ISBN='1-861003-23-0']");
--------------------编程问答-------------------- 参见我的BLOG,
http://blog.csdn.net/yumanqing/archive/2007/03/20/1534744.aspx --------------------编程问答-------------------- 那三个是节点的属性值,可以参看xmlnode属性 --------------------编程问答-------------------- 获得接点的xnlElement 然后可以获取属性的
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,