首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SelectSingleNode返回值

SelectSingleNode返回值
EN

Stack Overflow用户
提问于 2015-02-13 10:49:35
回答 2查看 196关注 0票数 0

我正在做一个学校项目,我使用来自在线数据源的XML数据来创建一个小型的飞行前简报工具。该代码旨在能够搜索XML文档并获得各种数据(机场代码、风向/风速、能见度等)。并显示数据。通过在互联网上搜索,我发现了一个相当简单的代码,应该可以工作。

代码语言:javascript
复制
Dim doc As XmlDocument = New XmlDocument()
    doc.Load("http://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requesttype=retrieve&format=xml&hoursBeforeNow=1&mostRecentForEachStation=constraint&stationString=KDAB")
    Dim airportcode As String = doc.SelectSingleNode("//station_id").Value
    Label1.Text = airportcode

正如您所猜到的,标签的文本不会改变。我对此做了一些研究,它与XML名称空间有关,但它对我来说太难理解了。

提前感谢你的帮助。-Michael

EN

回答 2

Stack Overflow用户

发布于 2015-02-13 16:14:11

使用XDocument的其他可能性:

代码语言:javascript
复制
Dim doc As XDocument = XDocument.Load("http://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requesttype=retrieve&format=xml&hoursBeforeNow=1&mostRecentForEachStation=constraint&stationString=KDAB")
Dim airportcode As String = doc...<station_id>.Value
Label1.Text = airportcode
票数 1
EN

Stack Overflow用户

发布于 2015-02-13 11:48:06

所选节点的内容位于子节点中。您需要添加firstchild

代码语言:javascript
复制
Dim airportcode As String = doc.SelectSingleNode("//station_id").FirstChild.Value
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28491726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档