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

c#怎么读取xml文档啊,在网上找了方法但是读不出来

<?xml version="1.0" encoding="gb2312" ?>

<root>
<ENV_CgiName>/cgi-bin/mobile/MobileQueryAttribution.cgi</ENV_CgiName>
<ENV_ClientAgent>Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Maxthon/4.0.6.2000 Chrome/26.0.1410.43 Safari/537.1</ENV_ClientAgent>
<ENV_ClientIp>182.119.226.121</ENV_ClientIp>
<ENV_QueryString>chgmobile=15850781443</ENV_QueryString>
<ENV_RequestMethod>GET</ENV_RequestMethod>
<ENV_referer></ENV_referer>
<chgmobile>15850781443</chgmobile>
<city>南京 </city>
<province>江苏 </province>
<retcode>0</retcode>
<retmsg>OK</retmsg>
<supplier>移动 </supplier>
<tid></tid>
</root>


我想读取出<city><province>和<supplier>这三项里的内容,以下是在网上找的方法,但是总是读取出来null
            XmlNode xn = xmlDoc.SelectSingleNode("//TreeNode[@name='city']");
            if (xn != null)
            {
                return xn.InnerText;
            }
            else
            {
                return "暂无归属地信息!";
            }

------解决方案--------------------
refer:
string xml = @"<?xml version='1.0' encoding='gb2312' ?>
 
<root>
<ENV_CgiName>/cgi-bin/mobile/MobileQueryAttribution.cgi</ENV_CgiName>
<ENV_ClientAgent>Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Maxthon/4.0.6.2000 Chrome/26.0.1410.43 Safari/537.1</ENV_ClientAgent>