2011-12-23 51 views
2

我有一个XML Like Below,但我无法解析它。请帮我解析下面的XML。如何解析Windows Phone 7中的soap 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> 

这里我想要表(即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"). 

但是这段代码返回null。

谢谢提前。

+4

那么,为什么你不只是生成与模式的客户端,让净为您做解析? – Bashwork 2011-12-23 15:30:05

+0

谢谢Bashwork。但我想在Windows Phone 7中解析这个XML。我可以在WP7中解析这个XML。 – 2011-12-24 08:24:41

+0

@MahiKumar - 您可以在WP7项目中设置服务参考。或者你的意思是说应该是动态的,因为模式每次都会有所不同? – 2011-12-24 08:38:58

回答

0

在您的c#项目中,您可以导入W​​eb引用,并将该引用指向您正在使用的Web服务提供者。这个引用将创建一个封装类,它将把所有的SOAP协议抽象为你。

请参阅MSDN链接查看更多细节:http://msdn.microsoft.com/en-us/library/d9w023sx%28VS.71%29.aspx

+0

感谢Carl T.我想在Windows Phone7中解析这个XML。我如何在WP7中解析这个XML。 – 2011-12-24 08:25:10

+0

-1:为什么在世界上你会发布一个.NET 1.1链接作为Windows Phone问题的答案?另外,为什么你会建议使用Web参考,这是传统技术? – 2011-12-24 08:25:57

+0

我添加了服务引用并使用它,但是在服务中它们正在返回数据集,所以数据集不是可用的wp7。所以我必须使用正常的方法打网址和获取XMl。所以我必须解析上面的XMl。 – 2011-12-24 09:10:52