日期:2014-05-17  浏览次数:20783 次

获取XML单个节点的属性值..[c#]
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!
请高手指点迷津!!!万分感激!!

------解决方案--------------------
C# code
class Program
    {
        static void Main(string[] args)
        {
            string path = Path.GetFullPath("../../Files/Test.xml");
            XmlDocument doc = new XmlDocument();
            doc.Load(path);
            XmlNode xn = doc.SelectSingleNode("return");
            string attr = xn.Attributes["msgid"].Value;
            Console.WriteLine(attr);

            XmlNode xnTwo = doc.SelectSingleNode("return/arguments/integer[@id='result']");
            Console.WriteLine(xnTwo.InnerText);

            Console.Read();
        }
    }