Need a small script to add into a wordpress site that will display two elements of data from an XML file.
I'm not completely comfortable with Javascript, and I've been reading how to do this all day and can't break new ground. I'd like to have a script that will access the XML file for a local river gauge, and output the latest observation. The latest observation is the first datum entry and the value I want to have printed in my HTML is the one marked <primary name="Stage" units="ft">. I'd also like to somehow take the valid timecode for that entry (in UTC) and convert it to Eastern Standard Time.
Like I said, I'm doing this so I can add it to a Wordpress site. My trouble came when the tutorial I was following only demonstrated working with one level and not nested levels. It would be interesting to do this myself, but if someone thinks they can knock this out quick enough for under $60, I'd be willing to do that too.
Edit: Sorry if that came off like I'm wanting you to do my work for me (but I am willing to pay someone if it's easier for them to do instead of teach.
To clarify, this is what I came up with on my own from playing with an example:
<script>
displayRIVER(0);
function displayRIVER(i) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this, i);
}
};
xmlhttp.open("GET", "http://water.weather.gov/ahps2/hydrograph_to_xml.php?gage=fftk2&output=xml", true);
xmlhttp.send();
}
function myFunction(xml, i) {
var xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("observed");
document.getElementById("showRIV").innerHTML =
"Level: " +
x[i].getElementsByTagName("primary")[0].childNodes[0].nodeValue;
}
</script>
Which isn't working.
Posted Jun 3, 2017, 7:49 PM UTC · edited
Not experienced either - but I've done that a few times with PHP and it's not too bad. Do you have to use JavaScript?
In any case, I could write out a script for you if it can wait until tomorrow when I'm back home.
Well, javascript is the only thing I've ever used to insert into a wordpress template front-end "code" text box. That's the main reason I went to that.