将时间布局元素链接到NDFD REST API中的参数

将时间布局元素链接到NDFD REST API中的参数,rest,weather,ndfd,Rest,Weather,Ndfd,我刚开始研究NDFDREST服务来获取天气数据。简而言之,我不知道如何将特定参数链接到返回XML中的时间布局元素 示例调用: 我正在寻找最高温度(最高温度),最低温度(薄荷)和3小时温度(温度)使用这个电话 我得到的XML是(为了相关性而剪掉): NOAA的国家气象局预报数据 气象的 预测 2012-12-26T20:03:47Z http://graphical.weather.gov/xml/ 气象发展实验室产品生成处 http://www.nws.noaa.gov/disclaimer.

我刚开始研究NDFDREST服务来获取天气数据。简而言之,我不知道如何将特定参数链接到返回XML中的时间布局元素

示例调用:

我正在寻找最高温度(最高温度),最低温度(薄荷)和3小时温度(温度)使用这个电话

我得到的XML是(为了相关性而剪掉):


NOAA的国家气象局预报数据
气象的
预测
2012-12-26T20:03:47Z
http://graphical.weather.gov/xml/
气象发展实验室产品生成处
http://www.nws.noaa.gov/disclaimer.html
http://www.weather.gov/
http://www.weather.gov/images/xml_logo.gif
http://www.weather.gov/feedback.php
第一点
http://forecast.weather.gov/MapClick.php?textField1=38.99&textField2=-77.01
k-p24h-n7-1
2012-12-26T07:00:00-05:00
2012-12-26T19:00:00-05:00
k-p24h-n6-2
2012-12-26T19:00:00-05:00
2012-12-27T08:00:00-05:00
k-p3h-n34-3
2012-12-26T16:00:00-05:00
2012-12-26T19:00:00-05:00
2012-12-26T22:00:00-05:00
2012-12-27T01:00:00-05:00
每天最高温度
34
日最低气温
34
温度
33
34
34
34
现在,我想将
时间布局
元素和
参数
元素的子元素链接到maxt、mint和temp,以便相应地填充模型对象

有人做过类似的事情吗

现在,我想我可以发出53个服务调用(每个参数一个,比如maxt、mint、temp等),但对于多个lat/lon对来说,这并不能很好地扩展(我有很多)


如果有任何建议,我将不胜感激。

规范在这里:您可能已经看到了。总的来说,事情应该是一致的。例如,在代码段中,有4个开始有效时间元素,它们应该对应于4个温度。我注意到,尤其是当数据接近时间间隔变化时,数据可能会在不同的时间更新,某些元素可能不一致或具有值xsi:nil=“true”。

每个元素都包含一个布局键元素,该元素提供了用于表示该时间布局的名称。元素的每个子元素都有一个时间布局属性,该属性的值告诉您它与哪个时间布局对齐

中的第5.2节值得一读。这里有一个示例名称:“k-p3h-n28-1”,5.2告诉我们,“k”代表“键”,p3h代表一个周期(至少最初是这样)3小时,n28表示提供了28个值,最后是-1,因此这将是一个唯一的标签。通常,您不想解析这些标签,只需使用时间布局元素中包含的实际时间列表,因为时间间隔会随着数据的移动而变化


使用相同的方案将位置与数据关联。元素有一个location key子元素,该子元素定义了一个类似“point1”的标签,然后元素有一个适用的location属性将它们与位置关联起来。

我认为有两种方法可以实现这一点 1) 具有适合NDFD数据结果的自定义类的反序列化器

您可以在以下位置尝试XML模式定义工具(Xsd.exe)

2) 使用LINQ解析XML文档,如(c#)

<?xml version="1.0"?>
<dwml version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd">
  <head>
    <product srsName="WGS 1984" concise-name="time-series" operational-mode="official">
      <title>NOAA's National Weather Service Forecast Data</title>
      <field>meteorological</field>
      <category>forecast</category>
      <creation-date refresh-frequency="PT1H">2012-12-26T20:03:47Z</creation-date>
    </product>
    <source>
      <more-information>http://graphical.weather.gov/xml/</more-information>
      <production-center>Meteorological Development Laboratory<sub-center>Product Generation Branch</sub-center></production-center>
      <disclaimer>http://www.nws.noaa.gov/disclaimer.html</disclaimer>
      <credit>http://www.weather.gov/</credit>
      <credit-logo>http://www.weather.gov/images/xml_logo.gif</credit-logo>
      <feedback>http://www.weather.gov/feedback.php</feedback>
    </source>
  </head>
  <data>
    <location>
      <location-key>point1</location-key>
      <point latitude="38.99" longitude="-77.01"/>
    </location>
    <moreWeatherInformation applicable-location="point1">http://forecast.weather.gov/MapClick.php?textField1=38.99&amp;textField2=-77.01</moreWeatherInformation>
    <time-layout time-coordinate="local" summarization="none">
      <layout-key>k-p24h-n7-1</layout-key>
      <start-valid-time>2012-12-26T07:00:00-05:00</start-valid-time>
      <end-valid-time>2012-12-26T19:00:00-05:00</end-valid-time>
    </time-layout>
    <time-layout time-coordinate="local" summarization="none">
      <layout-key>k-p24h-n6-2</layout-key>
      <start-valid-time>2012-12-26T19:00:00-05:00</start-valid-time>
      <end-valid-time>2012-12-27T08:00:00-05:00</end-valid-time>
    </time-layout>
    <time-layout time-coordinate="local" summarization="none">
      <layout-key>k-p3h-n34-3</layout-key>
      <start-valid-time>2012-12-26T16:00:00-05:00</start-valid-time>
      <start-valid-time>2012-12-26T19:00:00-05:00</start-valid-time>
      <start-valid-time>2012-12-26T22:00:00-05:00</start-valid-time>
      <start-valid-time>2012-12-27T01:00:00-05:00</start-valid-time>
    </time-layout>
    <parameters applicable-location="point1">
      <temperature type="maximum" units="Fahrenheit" time-layout="k-p24h-n7-1">
        <name>Daily Maximum Temperature</name>
        <value>34</value>
      </temperature>
      <temperature type="minimum" units="Fahrenheit" time-layout="k-p24h-n6-2">
        <name>Daily Minimum Temperature</name>
        <value>34</value>
      </temperature>
      <temperature type="hourly" units="Fahrenheit" time-layout="k-p3h-n34-3">
        <name>Temperature</name>
        <value>33</value>
        <value>34</value>
        <value>34</value>
        <value>34</value>
      </temperature>
    </parameters>
  </data>
</dwml>
System.Xml.Linq.XDocument xmlDoc = System.Xml.Linq.XDocument.Parse(xmlData);

var recordTime = from timevalue in xmlDoc.Descendants("time-layout").Elements("start-valid-time")
                         where timevalue.Parent.Element("layout-key").Value.Contains("k-p3h")
                         select (DateTime)timevalue;

var maxTemperature = from tempvalue in xmlDoc.Descendants("temperature").Elements("value")
                             where tempvalue.Parent.Attribute("type").Value == "maximum"
                          select (double)tempvalue;

var minTemperature = from tempvalue in xmlDoc.Descendants("temperature").Elements("value")
                             where tempvalue.Parent.Attribute("type").Value == "minimum"
                          select (double)tempvalue;

var temperature = from tempvalue in xmlDoc.Descendants("temperature").Elements("value")
                       where tempvalue.Parent.Attribute("type").Value == "hourly"
                       select (double)tempvalue;

var humidity = from humvalue in xmlDoc.Descendants("humidity").Elements("value")
                       where humvalue.Parent.Attribute("type").Value == "relative"
                       select (double)humvalue;