I am trying to parse temperature data into a google spreadsheet from a NOAA source with xml of the form:
.....
<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>
I would like each of the numbers inside the tags from both the maximum and minimum headings to be in separate cell in a spreadsheet. My current script is:
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
}
}
However, running this script parses only a single reading—the first tag, 63, into a cell. If I change .getElement(“value”).getText(); to .getElements(“value”).getText(); I receive the following error message: “TypeError: Cannot find function getText in object.”
Thank you for any advice you can provide.
Ron