Hi
I'm having trouble with my javascript. I retrieving my data from a XML document:
The following is the code I have so far:
What I am trying to do is get the first "item" nodes and display it on a webpage. Then place all the child "item" nodes under the first "item" node. For example, on the webpage: happy, sad and angry will be displayed. But when the user clicks onto "happy" it expands and smile, laugh and haha will be displayed. When the user clicks onto smile it will redirect the user to the "smile" webpage.
Any help will be much appreciated.
Thanks!
I'm having trouble with my javascript. I retrieving my data from a XML document:
Code:
<root>
<item>Happy
<item filePath="http://www.smile.com">Smile</item>
<item filePath="http://www.laugh.com">Laugh</item>
<item filePath="http://www.haha.com">Haha</item>
</item>
<item>Sad
<item filePath="http://www.cry.com">Cry</item>
<item filePath="http://www.upset.com">Upset</item>
</item>
<item>Angry
<item......>....</item>
</item>
</root>
Code:
function getXMLlinks()
{
var XMLVal;
var itemURL,i;
var itemXML;
var dropList,nodes;
var headNode;
var itemNode;
XMLVal = new ActiveXObject("Msxml2.XMLHTTP");
itemXML = new ActiveXObject("Microsoft.XMLDOM");
itemURL = 'http://www.emotions.xml';
XMLVal.open("POST",itemURL, false,"","");
XMLVal.setRequestHeader("content-type","text/xml");
XMLVal.send('');
itemXML.loadXML(XMLVal.responseText);
var root = itemXML.documentElement;
var elem = root.getElementsByTagName("item");
var n = itemXML.documentElement.firstChild;
var numNodes = elem.length;
var writeLinks = "";
for (var i=0; i<numNodes; i++)
{
var elemvalue = elem.item(i).getAttribute("filePath");
if (elemvalue == "null")
{
writeLinks = writeLinks + elem.text + '<br/>';
}
else
{
writeLinks = writeLinks + '<a href="' + elemvalue + '">' + elem.item(i).text + '</a><br/>'
}
}
linkList.innerHTML = writeLinks;
}
Any help will be much appreciated.
Thanks!
Comment