<?xml version="1.0" encoding="gb2312"?>
<products>
<product>
<name>CPU</name>
<price>600</price>
<company>Intel</company>
</product>
<product>
<name>显卡</name>
<price>300</price>
<company>gj</company>
</product>
</products>怎么按<name>把<product></product>的内容读出并转为字符串,急
<products>
<product>
<name>CPU</name>
<price>600</price>
<company>Intel</company>
</product>
<product>
<name>显卡</name>
<price>300</price>
<company>gj</company>
</product>
</products>怎么按<name>把<product></product>的内容读出并转为字符串,急
x.Load(Server.MapPath("A.xml"));
System.Xml.XmlNodeList nodes = x.SelectNodes("//Name");
foreach(System.Xml.XmlNode y in nodes)
{
if(y.InnerText.IndexOf("") >-1)
Response.Write(y.InnerText);
}System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load("A.xml");
foreach (System.Xml.XmlNode n in doc.DocumentElement.SelectNodes("product[contains(Name,'')]"))
{
MessageBox.Show(n.InnerXml);
}
或用LINQ查询
参考