Tundra Posted February 20, 2008 Share Posted February 20, 2008 Here is a real head scratcher for you:I am pulling 2 elements from an XML feed.One is a URL "playerURL" and the other is text "name".I want to pull both, place them into a single cell, and have the name element appear as a link pointing to the playerURL.eg.TundraIs this possible or am I just wishful thinking?Thanks in advance!-Tundra Link to comment Share on other sites More sharing options...
boen_robot Posted February 21, 2008 Share Posted February 21, 2008 What does the XML look like exactly? Is it something like <players><player><playerURL>http://www.massgate.net/profile.php?0,336482</playerURL><name>Tundra</name></player><!-- More <player> elements --></players> If so, in JavaScript, you can do it like: <div id="container">You need to turn on JavaScript to see all players and their URLs.</div><script type="text/javascript">//We assume xmlDoc is the XML document loaded into memoryvar players = xmlDoc.getElementsByTagName('player');//An element where the conents will be filled in is #containervar container = document.getElementById('container');container.innerHTML = '';for(i=0,l=players.length; i<l, i++) {var playerURL = players[i].getElementsByTagName('playerURL')[0].innerHTML;var name = players[i].getElementsByTagName('name')[0].innerHTML;container.innerHTML += '<a href="' + playerURL + '">' + name + '</a>, ';}</script> Link to comment Share on other sites More sharing options...
Tundra Posted February 21, 2008 Author Share Posted February 21, 2008 Please see my entire code here:http://w3schools.invisionzone.com/index.php?showtopic=17947Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.