首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将时间布局元素链接到NDFD REST API中的参数

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

Stack Overflow用户
提问于 2012-12-27 05:29:08
回答 3查看 921关注 0票数 0

我刚刚开始研究NDFD REST服务,以获取天气数据。简而言之,我不知道如何将特定参数链接到返回XML中的time-layout元素。

示例调用:http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdXMLclient.php?lat=38.99&lon=-77.01&product=time-series&temp=temp&maxt=maxt&mint=mint

我正在寻找最高温度(Maxt),最低温度(Mint)和3小时温度(temp)使用此调用。

我得到的XML是(为了相关性而截取的):

代码语言:javascript
复制
<?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>

现在,我希望将time-layout元素和parameters元素的子元素链接到maxt、mint和temp,以便可以相应地填充模型对象。

有没有人做过类似的事情?

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

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

EN

回答 3

Stack Overflow用户

发布于 2014-04-08 22:14:29

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

http://www.nws.noaa.gov/mdl/XML/Design/MDL_XML_Design.pdf_orig中的5.2节值得一读。下面是一个示例名称:"k-p3h- n28 -1“和5.2告诉我们"k”代表"p3h“,”n28“代表3小时的周期(至少最初),time表示提供了28个值,最后是-1,因此这将是一个唯一的标签。通常您不想解析这些标签,只使用time-layout元素中包含的实际时间列表,因为时间间隔会随着数据的移动而变化。

使用相同的方案将位置与数据相关联。元素有一个location -Key子元素,它定义了一个类似于"point1“的标签,然后元素有一个applicable location属性将它们绑定到它们的位置。

票数 1
EN

Stack Overflow用户

发布于 2013-02-26 01:33:47

规范在这里:http://www.nws.noaa.gov/mdl/XML/Design/MDL_XML_Design.pdf,你可能已经看过了。一般来说,事情应该是对齐的。例如,在您的代码片段中,您有4个start-valid-time元素,它们应该对应于4个温度。我注意到,特别是在接近时间间隔变化的时候,数据可能会在不同的时间更新,一些元素可能不一致,或者值xsi:nil=为“true”。

票数 0
EN

Stack Overflow用户

发布于 2015-03-27 21:51:30

我认为有两种方法可以使用一个自定义类来实现这个反序列化程序,以适应NDFD数据结果。

您可以在https://msdn.microsoft.com/en-us/library/x6c1kb0s%28v=vs.110%29.aspx上尝试使用XML Schema定义工具(Xsd.exe

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

代码语言:javascript
复制
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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14046485

复制
相关文章

相似问题

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