XML文件如下:
<return msgid="123">
< arguments >
<string id="devicecode">ZHAOYINGBI</string>
<string id="command">OPENDEV</string>
<integer id="result">0</integer>
</arguments>
</return>1. 获取<return msgid="123"> 中的msgid的值。
2. 获取<integer id="result">0</integer> 的值(即 0)。
请高手指教!万分感激!!!
<return msgid="123">
< arguments >
<string id="devicecode">ZHAOYINGBI</string>
<string id="command">OPENDEV</string>
<integer id="result">0</integer>
</arguments>
</return>1. 获取<return msgid="123"> 中的msgid的值。
2. 获取<integer id="result">0</integer> 的值(即 0)。
请高手指教!万分感激!!!
此消息通过 【CSDN论坛 Winform正式版】 回复!有关此工具
if (firstNode != null)
{
XmlAttributeCollection xmlAttributes = node.Attributes;
msgid = xmlAttributes["msgid"].Value;
XmlNodeList nodes = firstNode.SelectSingleNode("arguments").SelectNodes("string");
if (nodes != null)
{
foreach (XmlNode node in nodes)
{
XmlAttributeCollection xmlAttributes = node.Attributes;
if (xmlAttributes["id"].Value == "result")
{
itemText = xmlAttributes[itemValueName].InnerText;
break;
}
}
}
}
好像整复杂了。
xmlDoc.Load(Server.MapPath(@"c:\test.xml"));
Console.WriteLine(xmlDoc.DocumentElement.Attributes["msgid"].Value);
Console.WriteLine(xmlDoc.SelectSingleNode(@"//integer[@id='result']").InnerText);