簡體   English   中英

如何查詢地址? (LINQ to XML)

[英]How to query the address? (LINQ to 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 © 2011 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>
50230e70257e4ed5a5002a3d4a625c83|LTSM001156|02.00.159.1700|LTSMSNVM001471, LTSMSNVM001477
</TraceId>
<ResourceSets>
<ResourceSet>
<EstimatedTotal>1</EstimatedTotal>
<Resources>
<Location>
<Name>1 Microsoft Way, Redmond, WA 98052</Name>
<Point>
<Latitude>47.640568390488625</Latitude>
<Longitude>-122.1293731033802</Longitude>
</Point>
<BoundingBox>
<SouthLatitude>47.636705672917948</SouthLatitude>
<WestLongitude>-122.137016420622</WestLongitude>
<NorthLatitude>47.6444311080593</NorthLatitude>
<EastLongitude>-122.1217297861384</EastLongitude>
</BoundingBox>
<EntityType>Address</EntityType>
<Address>
<AddressLine>1 Microsoft Way</AddressLine>
<AdminDistrict>WA</AdminDistrict>
<AdminDistrict2>King Co.</AdminDistrict2>
<CountryRegion>United States</CountryRegion>
<FormattedAddress>1 Microsoft Way, Redmond, WA 98052</FormattedAddress>
<Locality>Redmond</Locality>
<PostalCode>98052</PostalCode>
</Address>
<Confidence>Medium</Confidence>
</Location>
</Resources>
</ResourceSet>
</ResourceSets>
</Response>

如何從地址查詢地點。 我想這是LINQ to XML對象的文本。 我在xmlLocation.Elements(“地址”)中嘗試了var asdf = from q選擇q.Element(“Locality”)。Value; 但不行,為什么?

如果你知道請寫信給我謝謝

Xml名稱空間; 由於您的數據不在默認命名空間中,因此您需要:

XNamespace ns = "http://schemas.microsoft.com/search/local/ws/rest/v1";

然后在所有查詢中使用它,即

var asdf = from q in xmlLocation.Elements(ns + "Address")
           select (string) q.Element(ns + "Locality");
var ns = XNamespace.Get("http://schemas.microsoft.com/search/local/ws/rest/v1");
var asdf = from q in xmlLocation.Descendants(ns + "Address") 
           select q.Element(ns + "Locality").Value;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM