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 to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Accessing Difficult XML Node

    Document from Last.fm api... scroll down to read question...
    Code:
    <lfm status="ok">
    
    	<recenttracks user="RJ" page="1" perPage="10" totalPages="3168">
    
    		<track>
    
    			<artist mbid="bc641be9-ca36-4c61-9394-5230433f6646">Liquid Tension Experiment</artist>
    
    			<name>Biaxident</name>
    
    			<streamable>1</streamable>
    
    			<mbid/>
    
    			<album mbid="6c20d297-121e-47d0-aa3a-8f27c7a06553">Liquid Tension Experiment 2</album>
    
    			<url>http://www.last.fm/music/Liquid+Tension+Experiment/_/Biaxident</url>
    
    			<image size="small">http://userserve-ak.last.fm/serve/34s/33028463.jpg</image>
    
    			<image size="medium">http://userserve-ak.last.fm/serve/64s/33028463.jpg</image>
    
    			<image size="large">http://userserve-ak.last.fm/serve/126/33028463.jpg</image>
    
    			<image size="extralarge">http://userserve-ak.last.fm/serve/300x300/33028463.jpg</image>
    
    			<date uts="1274524554">22 May 2010, 10:35</date>
    
    		</track>
    
    		....more tracks
    
    	</recenttracks>
    
    </lfm>
    Here is the document i am working with from the last.fm data api, the complete file
    is here, and i am trying to access this node
    Code:
    <image size="small">http://userserve-ak.last.fm/serve/34s/33028463.jpg</image>
    but i can;t seem to find out how because of the other three nodes with the same name,
    if anyone could help me out with this it would be great,
    i have been stumped for months, gave up for a while and decided that i cant leave anything unfinished.
    -thanks, Mike

  • #2
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I also forgot to mention that i am using javascript and the getElementsByTagName() function if that helps at all

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    what about getting the <image> nodes and then checking for the size attribute?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #4
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    okay, so i posted this up on another website and got this as a response

    Code:
    var images = document.getElementsByTagName("image");
    for (var i = 0; i < images.length; ++i)
    {
    	if (images[i].getAttribute("size") != null && images[i].getAttribute("size") == "small")
    	{
    		//do your thing
    	}
    }
    which worked but now i am trying to access the value inside the node with

    Code:
    imgURL = images[i].childNodes[0].nodeValue;
    and it is returning an "Object Required" error

  • #5
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    soo i got some input from another forum, and i improved on what everyone gave me and came up with this

    Code:
    	var imgURL = "http://i45.tinypic.com/f3w5lk.jpg"; //picture for  no album art
    	var images = xmlDoc.getElementsByTagName("image");
    	for (var i = 0; i < images.length; ++i)
    	{
    	    if (images[i].getAttribute("size") != null && images[i].getAttribute("size") == "extralarge" && images[i].firstChild)
    	    {
    	        imgURL = images[i].firstChild.nodeValue;
    	    }
    	}
    i also decided to go with the higher quality picture from the "extralarge" image node, it makes my app look much prettier

  • #6
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    if anyone was wondering what i was working on you can check it out here, as of now it is not published so you will not be able to see it unless you add me on myspace (heres my profile) and i add you as an application tester, so if you want just add me and shoot me a message and i will let you check it out, and hopefully it will be processed and published soon


  •  

    Posting Permissions

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