View Full Version : Creating a link with a Javascript-read XML page

10-24-2005, 03:59 PM
I don't know if this is possible or not, but I figured I would give it a shot. I have an XML document which lists some information about movies(Title, actor, etc.) I am using Javascript to pull that data and display it as html. Is it possible to create a link for each one of those titles that are pulled from the XML in my JS? Here is my code:

for (var i=0; movies.length > i; i++)
var Title = movies[i].getElementsByTagName("title");
var Actor = movies[i].getElementsByTagName("actor");
var Price = movies[i].getElementsByTagName("price");
results += i+1 + '. ' + ' "<span class=\"title\"><a href="http://www.imdb.com">' + Title[0].firstChild.nodeValue + '</a></span>"' +
' starring <span class=\"actor\">' + Actor[0].firstChild.nodeValue + '</span>' + ' and costs approximately $'+ Price[0].firstChild.nodeValue + "<br/>\n\r";

document.getElementById("displayresults").innerHTML = results;

10-24-2005, 06:35 PM
I have an XML document which lists some information...

Maybe you should consider XSLT. The one has nice transformation capability. It is possible to run JS on the result of a transformation.

10-24-2005, 07:58 PM
I have used XSLT and also worked with Javascript. I was just curious if it was possible to make such a thing using the Javascript which I already had. Thanks

10-24-2005, 09:41 PM

It is possible to manipulate a XML, using xmlDocument object/activeX, as you already did.
Where are link data? In XML file or?

10-25-2005, 02:46 PM
I am referring to creating a link outside of the XML document. I do use ActiveX to call the variable. In other words, I have a movie catalog that lists movies and actors, once I generate that list in my Javascript, I would like to make the name of each movie a clickable link, which connects to a listing of the movie..... In other words, the movie title is pulled out of the XML document and also provides a link to a movie listing.

10-27-2005, 05:27 PM
instead of:
<span class=\"title\"><a href="http://www.imdb.com">' + Title[0].firstChild.nodeValue + '</a></span>

you should have something like:
<span class=\"title\"><a href="http://www.imdb.com/' + linkFile+ '">' + Title[0].firstChild.nodeValue + '</a></span>

the rusult would be:
<span class="title"><a href="http://www.imdb.com/title/tt0289992/">The Life of David Gale</a></span>

if you do not have linkFile information (title/tt0289992) you could use imdb search. The search has following format:

and your code would be:
<span class=\"title\"><a href="http://www.imdb.com/find?q=' + Title[0].firstChild.nodeValue + ';s=all">' + Title[0].firstChild.nodeValue + '</a></span>