<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
1、要把title的内容:Harry Potte 读取出来:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlContent);
var bookName = xmlDoc.SelectNodes("/bookstore/book/title");
var bookNameValue = actualValues[0].InnerText;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlContent);
var bookName = xmlDoc.SelectNodes("/bookstore/book/title");
var bookNameValue = actualValues[0].InnerText;
输出结果:Harry Potter
如果把var bookNameValue = actualValues[1].InnerText; 就可以获取到第二个title的内容。
2、把title的内容:eng 读取出来:
01.XmlDocument xmlDoc = new XmlDocument();
02.xmlDoc.LoadXml(xmlContent);
03.
04.var bookName = xmlDoc.SelectNodes("/bookstore/book/@title");
05.var bookNameValue = actualValues[0].InnerText;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlContent);
var bookName = xmlDoc.SelectNodes("/bookstore/book/@title");
var bookNameValue = actualValues[0].InnerText;
输出结果:eng