我正在尝试从下面给出的 xml 文档中获取位置名称值,但它显示了 argumentnullexception 。任何帮助将不胜感激
<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>
dd31ffaf098f4406b7ecdd0da36680ff
</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>....
这是我试过的
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
XDocument result = XDocument.Parse(e.Result);
var ns = result.Root.GetDefaultNamespace();
var address1 = from query in result.Descendants(ns + "Location")
select new Location
{
address = (string)query.Element(ns + "Name")
};
Location loc = new Location();
MessageBox.Show(loc.address);
}