我正在做一个学校项目,我使用来自在线数据源的XML数据来创建一个小型的飞行前简报工具。该代码旨在能够搜索XML文档并获得各种数据(机场代码、风向/风速、能见度等)。并显示数据。通过在互联网上搜索,我发现了一个相当简单的代码,应该可以工作。
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
发布于 2015-02-13 16:14:11
使用XDocument的其他可能性:
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发布于 2015-02-13 11:48:06
所选节点的内容位于子节点中。您需要添加firstchild
Dim airportcode As String = doc.SelectSingleNode("//station_id").FirstChild.Valuehttps://stackoverflow.com/questions/28491726
复制相似问题