我的 xml 数据是 :
<response>
<result name="response" numFound="2" start="0">
<doc><str name="Author">ALi Ahmadi</str><int name="BookID">1904</int><str name="Title">BookName 1</str></doc>
<doc><str name="Author">Reza Javadi</str><int name="BookID">1523</int><str name="Title">BookName 2</str></doc>
</result>
</response>
我的C#代码是:
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.LoadXml(ResultData);
XmlNodeList XnList = XmlDoc.SelectNodes("/response/result/doc");
foreach (XmlNode Xn in XnList)
{
string a = Xn["str"].InnerText;
string b = Xn["int"].InnerText;
string c = Xn["str"].InnerText;
//string c = Xn["str[@name= Title ]"].InnerText;//error !
}
a & amp; c 结果为 : "Ali Ahmadi", 如何在 c 变量中找到 "BookName 1"?