Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

XML Datafeed Help - Almost there...just need a hand!?

Hi I have an xml datafeed from http://xmlfeed.laterooms.com/index.aspx?aid=4066&r...

I have made a local xml copy http://www.cytravel.co.uk/test/html/england.xml

And currently the page displays ok here http://www.cytravel.co.uk/test/html/cheap_hotels_i...

What I actually want to do is make all the "region_descriptions" linkable using the url next to them so "Central and South England" should jst be clickable through to http://www.laterooms.com/en/p4066/r242_hotels-in-c... and the same for each region (preferably with an alt tag that states "click here for cheap hotels in (region_description)

The code I am currently using is below...please can someone help me as it is driving me nuts!!

TIA

<script type="text/javascript">

var xmlDoc;

if (window.XMLHttpRequest)

{

xmlDoc=new window.XMLHttpRequest();

xmlDoc.open("GET","england.xml",false);

xmlDoc.send("");

xmlDoc=xmlDoc.responseXML;

}

// IE 5 and IE 6

else if (ActiveXObject("Microsoft.XMLDOM"))

{

xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

xmlDoc.async=false;

xmlDoc.load("england.xml");

}

document.write("<table border='1'>");

var x=xmlDoc.getElementsByTagName("region");

for (i=0;i<x.length;i++)

{

document.write("<tr><td>");

document.write(x[i].getElementsByTagName("region_description")[0].childNodes[0].nodeValue);

document.write("</td><td>");

document.write(x[i].getElementsByTagName("region_url")[0].childNodes[0].nodeValue);

document.write("</td></tr>");

}

document.write("</table>");

</script>

Update:

Can you please stop listing paysites..I just need a couple of lines tweaking..but I can't work out which ones :-(

Update 2:

The text above is all trunicated hence you cannot read the code, I have uploaded the full explanation in a text file to http://www.cytravel.co.uk/test/help.txt

I am desperate to get this project underway so any help would be very appreciated

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    Hi OKBusinessGroup,

    I use the createDOM() method to transform the responseText into a DOM document:

    <script type="text/javascript">

    var xmlDoc;

    function createDOM(sXml){

    var browser = navigator.appName;

    var oXmlDom = null;

    if(browser == "Microsoft Internet Explorer") {

    oXmlDom=new ActiveXObject("Microsoft.XMLDOM");

    oXmlDom.async="false";

    oXmlDom.loadXML(sXml);

    }

    else {

    var oParser = new DOMParser();

    oXmlDom = oParser.parseFromString(sXml, "text/xml");

    }

    return oXmlDom;

    }

    function loadXMLDoc(url){

    xmlDoc=null;

    if(window.XMLHttpRequest){

    xmlDoc=new XMLHttpRequest();

    }

    else if (window.ActiveXObject){

    xmlDoc=new ActiveXObject("Microsoft.XMLHTTP");

    }

    if(xmlDoc!=null){

    xmlDoc.onreadystatechange=stateChange;

    xmlDoc.open("GET",url,false);

    xmlDoc.send(null);

    }

    }

    function stateChange(){

    if(xmlDoc.readyState==4){

    if(xmlDoc.status==200){

    var xmlres = createDOM(xmlDoc.responseText);

    var country = xmlres.getElementsByTagName('country')[0];

    var regions = country.getElementsByTagName('region');

    document.write("<table border='1'>");

    for(var i = 0; i < regions.length; i++){

    document.write("<tr><td>");

    var tag1 = regions[i].getElementsByTagName("tag1");

    document.write(tag1[0].childNodes[0].nodeValue);

    document.write("</td><td>");

    var tag2 = regions[i].getElementsByTagName("tag2");

    document.write(tag2[0].childNodes[0].nodeValue);

    document.write("</td></tr>");

    }

    document.write("</table>");

    }

    }

    }

    window.onload = function(){

    loadXMLDoc('england.xml');

    }

    </script>

    england.xml

    <?xml version="1.0" encoding="windows-1250"?>

    <country>

    <region>

    <tag1>yep</tag1>

    <tag2>nope</tag2>

    </region>

    <region>

    <tag1>hey</tag1>

    <tag2>wow</tag2>

    </region>

    <region>

    <tag1>yes</tag1>

    <tag2>ok</tag2>

    </region>

    </country>

    Best regards,

    subexpression

    EDIT:

    One line got truncated:

    var country = xmlres. getElementsByTagName ('country')[0];

Still have questions? Get your answers by asking now.