Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a link with a Javascript-read XML page

    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;

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    rm -f /

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok

    It is possible to manipulate a XML, using xmlDocument object/activeX, as you already did.
    Where are link data? In XML file or?
    Last edited by rm-f; 10-24-2005 at 09:59 PM.
    rm -f /

  • #5
    New Coder
    Join Date
    Sep 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    http://www.imdb.com/find?q=The%20Lif...%20David;s=all

    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>
    rm -f /


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •