我有一个如下所示的 XML,但我无法解析它。请帮我解析下面的 XML。
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body>
<GetResponse xmlns="http://tempuri.org/"><GetResult>
<diffgr:diffgram>
<NewDataSet>
<Table>
<a>hi1</a>
<b>hi2</b>
</Table>
<Table>
<a>hi3</a>
<b>hi4</b>
</Table>
</NewDataSet>
</diffgr:diffgram>
</GetResponse></GetResult>
</soap:Body>
</soap:Envelope>
这里我想要 Table (即 a,b )标签的结果。我尝试使用 Linq,但无法解析它。我试过这样的代码:
//XML will be there in response string
String response = e.response;
public static String myNamespace = "http://tempuri.org/";
XDocument reader = XDocument.Parse(response);
var results = from result in reader.Descendants(XName.Get("GetResponse", myNamespace))
select result.Element("GetResult").
但是这段代码返回的是空值。
提前致谢。
最佳答案
在您的 C# 项目中,您可以导入 Web 引用并将其指向您正在使用的 Web 服务提供商。此引用将创建一个封装类,它将向您抽象所有 SOAP 协议(protocol)。
有关详细信息,请参阅 MSDN 链接:http://msdn.microsoft.com/en-us/library/d9w023sx%28VS.71%29.aspx
关于c# - 如何在 Windows Phone 7 中解析 Soap XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8616371/