在 c# 中解析天气预报数据(来自 NDFD)
我正在使用> http://www.weather.gov/forecasts/xml/DWMLgen/wsdl /ndfdXML.wsdl Web服务通过调用GmlTimeSeries Web方法获取天气详细信息。现在我只想从 xml 中读取温度、天气图标链接详细信息。 xml数据量很大。任何人都可以提供从 xml 中获取所需数据的想法吗?
XML 看起来几乎如下所示:完整的 XML 文件在这里
我想从下面的 xml 数据中获取温度:
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-07T12:00:00</app:validTime>
<app:temperature>77.0</app:temperature>
</app:Forecast_Gml2Point>
</gml:featureMember>
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-07T15:00:00</app:validTime>
<app:temperature>90.0</app:temperature>
</app:Forecast_Gml2Point>
</gml:featureMember>
以及从下面的天气短语:
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-08T03:00:00</app:validTime>
<app:weatherPhrase>Mostly Clear</app:weatherPhrase>
</app:Forecast_Gml2Point>
</gml:featureMember>
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-08T06:00:00</app:validTime>
<app:weatherPhrase>Mostly Clear</app:weatherPhrase>
</app:Forecast_Gml2Point>
</gml:featureMember>
上面是一段 xml 文件。像这样我有 7 天天气详细信息的大数据。我需要从上面的 xml 中读取温度和天气状况。
<一href="http://www.weather.gov/forecasts/xml/SOAP_server/ndfdXMLclient.php?whichClient=GmlLatLonList&lat=&lon=&listLatLon=&a mp;lat1=&lon1=&lat2=&lon2=&resolutionSub=&listLat1=&listLon1=&listLat2=&listLon2=&resolutionList=&a mp;endPoint1Lat=&endPoint1Lon=&endPoint2Lat=&endPoint2Lon=&listEndPoint1Lat=&listEndPoint1Lon=&listEndPoint2La t=&listEndPoint2Lon=&zipCodeList=&listZipCodeList=¢erPointLat=¢erPointLon=&distanceLat=&distanceLon =&resolutionSquare=&listCenterPointLat=&listCenterPointLon=&listDistanceLat=&listDistanceLon=&listResolutionSq uare=&citiesLevel=&listCitiesLevel=&扇区=&gmlListLatLon=38.99,-77.02%2039.70,-104.80%2047.6,-122.30&featureType=F orecast_Gml2Point&requestedTime=&startTime=2000-01-01T00:00:00&endTime=2012-01-01T00:00:00&compType=Between&proper tyName=wx,temp,icons&product=时间序列&begin=2004-01-01T00:00:00&end=2015-06-07T00:00:00&maxt=maxt&Submit=提交" rel="nofollow">完整的 XML 文件在这里
I am using > http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl webservice to get the weather detials by calling GmlTimeSeries webmethod. Now I just want to read temparature, weather icon link details from the xml. The xml has huge data. Can anybody give an idea to fetch the required data from the xml?
The XML looks almost like below : Full XML File is Here
I want to fetch Temparature from below xml data:
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-07T12:00:00</app:validTime>
<app:temperature>77.0</app:temperature>
</app:Forecast_Gml2Point>
</gml:featureMember>
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-07T15:00:00</app:validTime>
<app:temperature>90.0</app:temperature>
</app:Forecast_Gml2Point>
</gml:featureMember>
And weather phrase from below:
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-08T03:00:00</app:validTime>
<app:weatherPhrase>Mostly Clear</app:weatherPhrase>
</app:Forecast_Gml2Point>
</gml:featureMember>
<gml:featureMember>
<app:Forecast_Gml2Point>
<gml:position>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-87.8859170,41.7450495</gml:coordinates>
</gml:Point>
</gml:position>
<app:validTime>2011-06-08T06:00:00</app:validTime>
<app:weatherPhrase>Mostly Clear</app:weatherPhrase>
</app:Forecast_Gml2Point>
</gml:featureMember>
The above is a piece of xml file. Like this I have large data for 7 days weather details. I need to read for the temp and weather condition from above xml.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你会找到答案 此处
编辑:
您需要使用名称空间,例如:
编辑2:
如果您需要获取具有其他名称空间的 Element,这里是另一个示例:
I think you will find your answer here
Edit:
you need to use namespace, for example:
Edit 2:
if you need to get Element with other namespace, here is another example:
如果使用 Visual Studio 的“添加 Web 引用”功能会更容易。通过这种方式,Visual Studio 会根据 WSDL 为您生成所有(代理)类,然后您可以像平常一样针对这些类进行编程。换句话说,不需要解析 XML。
正如此链接中指出的:
您可能需要参考上述链接了解有关使用 WSDL 的详细信息。
It would be easier if you use the "Add Web Reference" feature of Visual Studio. In this way, Visual Studio generates all the (proxy) classes for you base on the WSDL, and you can then program against the classes like how you'll do normally. In other words, there is no parsing of XML needed.
As pointed out in this link:
You might want to refer to the above link about consuming WSDL in details.