Author Topic: JavaScript Help  (Read 731 times)

0 Members and 1 Guest are viewing this topic.

Offline colonieweather

  • Contributor
  • ***
  • Posts: 108
    • Colonie Weather Online
JavaScript Help
« on: July 19, 2019, 04:43:07 PM »
Hi,

I'm trying to get the primary element's value from following XML snippet...

<observed>
    <datum>
      <valid timezone="UTC">2019-07-19T16:15:00-00:00</valid>
      <primary name="Stage" units="ft">16.49</primary>
      <secondary name="Flow" units="cfs">5010.00</secondary>
      <pedts>HGIRG</pedts>
    </datum>
<observed>

I was able to retrieve the datum element as an object (see datum variable below), but cannot retrieve primary value.

var latest = xmlDoc.documentElement.getElementsByTagName("observed");
var datum = latest[0].getElementsByTagName("datum");
var observed = datum[0].getElementsByTagName("primary").childNodes[0].nodeValue;

I get the following error at the observed variable line: Cannot read property 'getElementsByTagName' of undefined

Any help would be greatly appreciated.

Thank you,
Chris
« Last Edit: July 19, 2019, 04:46:35 PM by colonieweather »
Davis Vantage Pro 2 Plus
WeatherLink v6.0.4
colonieweatheronline.com
Wx Underground - KNYCOLON3
APRS/CWOP - EW0288