我想从下面的XML字符串返回纬度节点(例如)一个XML元素返回只/单字符串值(来自雅虎地理编码API。)我想从使用LINQ
<ResultSet version="1.0">
<Error>0</Error>
<ErrorMessage>No error</ErrorMessage>
<Locale>us_US</Locale>
<Quality>60</Quality>
<Found>1</Found>
<Result>
<quality>87</quality>
<latitude>37.68746446</latitude>
<longitude>-79.6469878</longitude>
<offsetlat>30.895931</offsetlat>
<offsetlon>-80.281192</offsetlon>
<radius>500</radius>
<name></name>
<line1>123 Main Street</line1>
<line2>Greenville, SC 29687</line2>
<line3></line3>
<line4>United States</line4>
<house>123</house>
<street>Main Street</street>
<xstreet></xstreet>
<unittype></unittype>
<unit></unit>
<postal>29687</postal>
<neighborhood></neighborhood>
<city>Greenville</city>
<county>Greenville County</county>
<state>South Carolina</state>
<country>United States</country>
<countrycode>US</countrycode>
<statecode>SC</statecode>
<countycode></countycode>
<uzip>29687</uzip>
<hash>asdfsdfas</hash>
<woeid>127757446454</woeid>
<woetype>11</woetype>
</Result>
</ResultSet>
我已经将此XML成功加载到XElement实例中,但似乎无法找到将纬度节点(例如)加载到字符串变量中的方式。如果没有节点或节点是空的,那么我想得到一个空或空字符串。如果有多个(不会有,但只是为了以防万一)然后返回第一个实例。
我想这将是容易的,但我不能得到它的工作。我试过的所有Linq查询都返回null。
虽然我在这,如果你能有足够的详细解释一下,这样我还可以得到错误节点。我只提到它,因为它处于不同的级别。
谢谢。
赛斯
这做到了完全一样。谢谢。 – 2011-03-23 22:37:22