-5
嗨我有一個xml數據從另一個服務返回。它看起來像這樣導航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>
我需要Data,Message和ReturnCode的值。數據(PRINT「這是一個試驗#2」)節點內的值可以是單線或上千行..
我使用此C#代碼以獲得值
XmlDocument的XM =新的XmlDocument ();
string Response = obj.getContent(str, 1, 73810, SHA);
//Console.WriteLine("Response" + Response);
xm.LoadXml(Response);
Console.WriteLine(xm.InnerXml);
XmlNode oldCd;
XmlElement root = xm.DocumentElement;
Console.WriteLine(root.InnerText);
oldCd = root.SelectSingleNode("/response/Response/Response/ReturnCode/Message/Data/");
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();
}
}
你最好開始再編碼! –
是的,我從c#應用程序訪問這個。我是 XmlDocument xm = new XmlDocument(); 串RSP = obj.getContent(STR,1,73810,SHA); xm.LoadXml(Rsp); Console.WriteLine(xm.InnerXml); XmlNode oldCd; XmlElement root = xm.DocumentElement; Console.WriteLine(root.InnerText); oldCd = root.SelectSingleNode(「/ response/Response/Response/ReturnCode/Message/Data /」); 但我在Data列中沒有看到任何值。 謝謝 – jramacha
您需要提出具體問題。這聽起來更像是你想要一個完整的解決方案。 – leigero