Author Topic: JavaScript Help  (Read 896 times)

0 Members and 1 Guest are viewing this topic.

Offline colonieweather

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

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

      <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>

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,
« Last Edit: July 19, 2019, 04:46:35 PM by colonieweather »
Davis Vantage Pro 2 Plus
WeatherLink v6.0.5
Wx Underground - KNYCOLON3