View Single Post
Old 02-26-2013, 04:28 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
This is just an example. I only did it for firefox and it depends on only having three entrees in xml. I hope you know how to read an xml and get the right url:
The XML:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<links>

<link category="COOKING">
  <url>goole</url>
  <img>2005</img>
</link>

<link category="CHILDREN">
  <url>google</url>
  <img>2005</img>
  <price>29.99</price>
</link>

<link category="WEB">
  <url>http://facebook.com/</url>
  <img>2003</img>
</link>

</links>
The Javascript:
Code:
<!DOCTYPE html>
<html>
<body>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest();
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}

xml=loadXMLDoc("Links.xml");
path="/links/link/url"
// code for IE
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);

for (i=0;i<nodes.length;i++)
  {
  document.write(nodes[i].childNodes[0].nodeValue);
  document.write("<br>");
  }
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result=nodes.iterateNext();

while (result)
  {
  jimmy = result.childNodes[0].nodeValue;
  document.write(result.childNodes[0].nodeValue);
  document.write("<br>");
  result=nodes.iterateNext();
  }
}
/*bill = String(jimmy);   <= YOU MIGHT HAVE TO DO THIS, DON'T KNOW*/
window.open(jimmy);
</script>

</body>
</html>
sunfighter is offline   Reply With Quote