我正在尝试将温度数据解析为来自 NOAA 源的 google 电子表格,其格式为 xml:
......
<parameters applicable-location="point1">
<temperature type="maximum" units="Fahrenheit" time-layout="k-p24h-n7-1">
<name>Daily Maximum Temperature</name>
<value>63</value>
<value>72</value>
<value>76</value>
<value>78</value>
<value>74</value>
<value>62</value>
<value>58</value>
</temperature>
<temperature type="minimum" units="Fahrenheit" time-layout="k-p24h-n6-2">
<name>Daily Minimum Temperature</name>
<value>52</value>
<value>58</value>
<value>56</value>
<value>60</value>
<value>48</value>
<value>45</value>
</temperature>
</parameters>
</data>
</dwml>
我希望最大和最小标题中标签内的每个数字都位于电子表格中的单独单元格中。我当前的脚本是:
function Temperatures() {
var text = UrlFetchApp.fetch("http://graphical.weather.gov/xml/SOAP_server/ndfdXMLclient.php?whichClient=NDFDgen&lat=38.99&lon=-77.01&listLatLon=&lat1=&lon1=&lat2=&lon2=&resolutionSub=&listLat1=&listLon1=&listLat2=&listLon2=&resolutionList=&endPoint1Lat=&endPoint1Lon=&endPoint2Lat=&endPoint2Lon=&listEndPoint1Lat=&listEndPoint1Lon=&listEndPoint2Lat=&listEndPoint2Lon=&zipCodeList=&listZipCodeList=¢erPointLat=¢erPointLon=&distanceLat=&distanceLon=&resolutionSquare=&listCenterPointLat=&listCenterPointLon=&listDistanceLat=&listDistanceLon=&listResolutionSquare=&citiesLevel=&listCitiesLevel=§or=&gmlListLatLon=&featureType=&requestedTime=&startTime=&endTime=&compType=&propertyName=&product=time-series&begin=2004-01-01T00%3A00%3A00&end=2017-04-12T00%3A00%3A00&Unit=e&maxt=maxt&mint=mint&Submit=Submit").getContentText();
return parse(text);
function parse(text) {
var doc = Xml.parse(text, true);
var temps = doc.dwml.data.getElement("parameters").getElement("temperature").getElements("value").getText();
return temps
}
}
但是,运行此脚本只会将一个读数(第一个标签 63)解析为一个单元格。如果我改变 .getElement(“value”).getText(); 到 .getElements(“值”).getText(); 我收到以下错误消息:“TypeError: Cannot find function getText in object.”</p>
感谢您提供的任何建议。
罗恩