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

怎么获取XML节点里面的内容,在线求教
<?xml version="1.0" encoding="gb2312"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.jiangsuedu.net/justone/">
<SOAP-ENV:Header>
<TransactionID>110000000001</TransactionID>
<ServiceType>/sms/mt</ServiceType>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<GateWayID>YNMC</GateWayID>
<DstID>15125664368</DstID>
<SrcID>099879</SrcID>
<FeeID>15125664368</FeeID>
<LinkID/>
<MsgContent>哈哈</MsgContent>
<ServiceID>AYN3913101</ServiceID>
<MsgID>1234</MsgID>
<CommitTime>201311130101022</CommitTime>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

怎么获取<MsgContent>哈哈</MsgContent> 这个节点内容

------解决方案--------------------
XmlDocument doc = new XmlDocument();
            doc.Load("test.xml");

            XmlElement root = doc.DocumentElement;
            string nameSpace = root.NamespaceURI;
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); ;
            nsmgr.AddNamespace("SOAP-ENV", nameSpace);

            string value = doc.SelectSingleNode("/SOAP-ENV:Envelope/SOAP-ENV:Body/MsgContent", nsmgr).InnerText;
            Console.WriteLine(value);//输出:哈哈