Skip to main content
 首页 » 编程设计

c#之在 C# 中从 rss 提要中提取数据

2024年02月24日20shihaiming

我需要从下面的 xml 文档中读取 woeid。我需要读取数据并将其存储到字符串变量中,以便查询雅虎天气服务。

查询返回的 XML:

<query yahoo:count="1" 
       yahoo:created="2009-12-22T08:30:31Z" 
       yahoo:lang="en-US" 
       yahoo:updated="2009-12-22T08:30:31Z" 
       yahoo:uri="http://query.yahooapis.com/v1/yql?q=select+woeid+from+geo.places+where+text%3D%22farnborough%2C+greater+london%2Cuk%22"> 
− 
<diagnostics> 
<publiclyCallable>true</publiclyCallable> 
− 
<url execution-time="32"> 
http://where.yahooapis.com/v1/places.q(farnborough%2C%20greater%20london%2Cuk);start=0;count=10 
</url> 
<user-time>33</user-time> 
<service-time>32</service-time> 
<build-version>4265</build-version> 
</diagnostics> 
− 
<results> 
− 
<place> 
<woeid>19941</woeid> 
</place> 
</results> 
</query> 

谁能告诉我如何通过 linq 做到这一点?

------------编辑------------------------------------ ---------------------------------------------- ----

我刚刚意识到 .net 2.0 不支持我的 linq...doh

那么,能否有人建议使用 .net 2.0 提供的引用资料的替代方法? -也许重新发布并标记? 非常感谢,

请您参考如下方法:

你可以这样做:

XDocument doc = XDocument.Parse(xml); 
string s = doc.Descendants() 
              .Where(element => element.Name == "woeid") 
              .FirstOrDefault().Value;