Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67411

Display XML values in HTML of a specific element or attribute

$
0
0

I need to from an HTML, get a specific element or attribute and some values thereof from an XML. So in the HTML, get http://ipaddress/files/devices.xml , find field that has attribute/element "Gmail SMTP" and disply its "status" attribute

then to add on maybe, create if statement to load image"online" if attribute "status" = on

XML Page:

<devices>
 <device server_id="1">
  <label>Server_test</label>
  <status>on</status>
  <last_check>2019-10-30 02:20:53</last_check>
 </device>
 <device server_id="2">
   <label>Gmail SMTP</label>
   <status>on</status>
   <last_check>2019-10-30 02:20:53</last_check>
 </device>

HTML script:

<script>
if (window.XMLHttpRequest) {
  xmlhttp = new XMLHttpRequest();
} else {
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}


xmlhttp.open("GET", "http://ipaddress/Controllers/cron/devices.xml",
  true);
xmlhttp.send();


function myFunction(xml, i) {
  var xmlDoc = xml.responseXML;
  x = xmlDoc.getElementsByTagName("devices");
  document.getElementById("Gmail SMTP").innerHTML =
    "status:" +
    x[i].getElementsByTagName("status")[0].childNodes[0].nodeValue +
    "<br>label:" +
    x[i].getElementsByTagName("label")[0].childNodes[0].nodeValue +
    "<br>last check:" +
    x[i].getElementsByTagName("last_check")[0].childNodes[0].nodeValue;
}
</script>

Viewing all articles
Browse latest Browse all 67411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>