C# 导航xml节点;

C# 导航xml节点;,c#,C#,嗨,我有一个从另一个服务返回的xml数据。看起来像这样 <?xml version="1.0" encoding="UTF-8"?> <response xmlns="http://test.com/group/application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Response> <Response> <ReturnCode>0</Return

嗨,我有一个从另一个服务返回的xml数据。看起来像这样

<?xml version="1.0" encoding="UTF-8"?>
<response xmlns="http://test.com/group/application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Response>
<Response>
<ReturnCode>0</ReturnCode>
<Message>Sucess</Message>
<Data>PRINT 'This is a test #2'</Data>
</Response>
</Response>
</response>

试试这个

XmlDocument xml = new XmlDocument();
xml.LoadXml(myXmlString); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
XmlNodeList xnList = xml.SelectNodes("/responset[@*]/Response");
foreach (XmlNode xn in xnList)
{
XmlNode response = xn.SelectSingleNode("Response");
if (response != null)
{
string rc = response["ReturnCode"].InnerText;
string msg = example["Message"].InnerText;
string data = example["Data"].InnerText;
}
} 

那你最好开始编码!是的,我是从一个c#应用程序访问这个。我是XmlDocument xm=新的XmlDocument();字符串Rsp=obj.getContent(str,173810,SHA);xm.LoadXml(Rsp);WriteLine(xm.InnerXml);xmlnodeoldcd;xmlementroot=xm.DocumentElement;Console.WriteLine(root.InnerText);oldCd=root。选择SingleNode(“/response/response/response/ReturnCode/Message/Data/”;但我在数据列中看不到任何值。谢谢你需要问一个具体的问题。这听起来更像是您想要一个完整的解决方案。您是将XML作为字符串加载还是从文件中读取。请提供您的问题的一些细节或输入来源。我以字符串形式阅读。
static void Main()
    {
        try
        {

            svc obj = new svc();
          ..
            //XmlDocument xm = new XmlDocument();

            string rsp = obj.getContent(..;


            String myEncodedString;
            myEncodedString = obj.XmlDecode(rsp);

            XNamespace xmlns = XNamespace.Get("http://xxxx.com/xxx/xx");

            XDocument doc = XDocument.Parse(myEncodedString);

            Console.WriteLine(obj.Return_Message_Data("ReturnCode", myEncodedString));

            Console.WriteLine(obj.Return_Message_Data("Message", myEncodedString));

            Console.WriteLine(obj.Return_Message_Data("Data", myEncodedString));               

            Console.ReadLine();
        }

        catch (Exception e)
        {
            Console.WriteLine(e);
            Console.ReadLine();
        }

    }
XmlDocument xml = new XmlDocument();
xml.LoadXml(myXmlString); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
XmlNodeList xnList = xml.SelectNodes("/responset[@*]/Response");
foreach (XmlNode xn in xnList)
{
XmlNode response = xn.SelectSingleNode("Response");
if (response != null)
{
string rc = response["ReturnCode"].InnerText;
string msg = example["Message"].InnerText;
string data = example["Data"].InnerText;
}
}