Jump to content

Combining Elements...I NEED YOUR HELP!!!


Tundra

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...