View Single Post
Old 10-26-2012, 04:35 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
First: your xml code, first line reads
Code:
<?xml version=1.0"?>
It should be
Code:
<?xml version="1.0"?>
I saved it as location.xml
This html does what you want:

Code:
<!DOCTYPE html>
<html>
<body>
<script>
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","location.xml",false);
xmlhttp.send('');
xmlDoc=xmlhttp.responseXML;

var x=xmlDoc.getElementsByTagName("loc");
for (i=0;i<x.length;i++)
{
	if(x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue == 122)
	{
		document.write(x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue+"<br />");
		document.write(x[i].getElementsByTagName("user")[0].childNodes[0].nodeValue+"<br />");
		document.write(x[i].getElementsByTagName("section")[0].childNodes[0].nodeValue);
	}
}
</script>
</body>
</html>
sunfighter is offline   Reply With Quote