Windows phone 7 Windows Phone解析XML字符串

Windows phone 7 Windows Phone解析XML字符串,windows-phone-7,xml-parsing,Windows Phone 7,Xml Parsing,我试图解析这个XML,它是作为虚拟地球的响应检索的 <Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1"> <Copyright> Copyright © 2013 Microsoft an

我试图解析这个XML,它是作为虚拟地球的响应检索的

<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1">
<Copyright>
Copyright © 2013 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.
</Copyright>
<BrandLogoUri>
http://dev.virtualearth.net/Branding/logo_powered_by.png
</BrandLogoUri>
<StatusCode>200</StatusCode>
<StatusDescription>OK</StatusDescription>
<AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>
<TraceId>
ebbe16390026429f967a06977c3bc94c|MIAM000025|02.00.150.1300|MIAMSNVM001367, EWRMSNVM003182
</TraceId>
<ResourceSets>
<ResourceSet>
<EstimatedTotal>1</EstimatedTotal>
<Resources>
<Location>
<Name>TE-V 1009, 44167 Camañas (TE)</Name>
<Point>
<Latitude>40.640868544578552</Latitude>
<Longitude>-1.1300414800643921</Longitude>
</Point>
<BoundingBox>
<SouthLatitude>40.637005827007876</SouthLatitude>
<WestLongitude>-1.1368284398869133</WestLongitude>
<NorthLatitude>40.644731262149229</NorthLatitude>
<EastLongitude>-1.1232545202418709</EastLongitude>
</BoundingBox>
<EntityType>Address</EntityType>
<Address>
<AddressLine>TE-V 1009</AddressLine>
<AdminDistrict>Aragon</AdminDistrict>
<AdminDistrict2>TE</AdminDistrict2>
<CountryRegion>Spain</CountryRegion>
<FormattedAddress>TE-V 1009, 44167 Camañas (TE)</FormattedAddress>
<Locality>Camañas</Locality>
<PostalCode>44167</PostalCode>
</Address>
<Confidence>Medium</Confidence>
<MatchCode>Good</MatchCode>
<GeocodePoint>
<Latitude>40.640868544578552</Latitude>
<Longitude>-1.1300414800643921</Longitude>
<CalculationMethod>Interpolation</CalculationMethod>
<UsageType>Display</UsageType>
<UsageType>Route</UsageType>
</GeocodePoint>
</Location>
</Resources>
</ResourceSet>
</ResourceSets>
</Response>

版权所有©2013微软及其供应商。版权所有。未经微软公司明确书面许可,不得访问本API,不得以任何方式使用、复制或传播本API的内容和任何结果。
http://dev.virtualearth.net/Branding/logo_powered_by.png
200
好啊
有效存款
ebbe16390026429f967a06977c3bc94c | MIAM000025 | 02.00.150.1300 | MIAMSNVM001367,EWRMS NVM003182
1.
TE-V 1009、44167卡马纳斯(TE)
40.640868544578552
-1.1300414800643921
40.637005827007876
-1.1368284398869133
40.644731262149229
-1.1232545202418709
地址
TE-V 1009
阿拉贡
TE
西班牙
TE-V 1009、44167卡马纳斯(TE)
卡马纳斯
44167
中等
好
40.640868544578552
-1.1300414800643921
插值
展示
路线
我一直在寻找任何可能对我有用的答案。但每个人都以其他方式询问他们想要什么,我什么也找不到。我只想得到由“Address”组成的“Locality”值作为字符串值

我将这个XML作为一个名为MyXMLString的字符串

提前感谢。

您只需使用:

如果Windows Phone 7中没有
Parse
,您可以使用
StringReader

var reader = new StringReader(text);
XDocument doc = XDocument.Load(reader);
或者如果这不起作用:

var bytes = Encoding.UTF8.GetBytes(text);
var stream = new MemoryStream(bytes);
XDocument doc = XDocument.Load(stream);

当然,解析在WP7中是可用的,但我认为我们在这一行遇到了问题;location.Element(ns+“Name”).Value。那个“名字”是什么?我只想得到“”,它是“”的孩子。那么我应该如何编辑你的代码?@ilerleartik:这是元素的名称。您应该阅读
子体
元素
方法的文档。我将更新我的示例,为您提供
Locality
元素,但是如果给您一个包含您不熟悉的方法的代码示例,您确实需要做一些研究。此外,Locality是一片叶子,由许多父元素组成。它的父对象是地址,地址的父对象是位置,位置也有父对象,依此类推。。。我应该在我的解析器中写这个树关系吗?当然你是对的,我正在尝试做一些事情,但我真的研究太多了,我的大脑已经消失了:),谢谢你的帮助。它工作起来很有魅力,现在是测试和学习解析工作原理的时候了。再次感谢!
var bytes = Encoding.UTF8.GetBytes(text);
var stream = new MemoryStream(bytes);
XDocument doc = XDocument.Load(stream);