Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 172497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:10:35+00:00 2026-05-11T13:10:35+00:00

I’m creating a Yahoo! Widget and have done this before without any problems (creating

  • 0

I’m creating a Yahoo! Widget and have done this before without any problems (creating a widget). I’m getting a xml document via a weblink and want to get all the nodes intro a tree. I’m doing this:

var request = new XMLHttpRequest();         request.open( 'GET', url, false );         request.send();         if ( request.status == 200 )         {             doc = request.responseXML;             tree = doc.evaluate('/lfm');             status = tree.item(0).getAttribute('status')             if(status == 'ok')             {                 print ('status is ok!');                 tracks = doc.evaluate('/lfm/recenttracks[1]/track');                 for(i=0;i<tracks.length;i++)                 {                     artist = tracks.item(i).firstChild.firstChild.data;                 }             }         }     } 

This way you can get the node artist out of the tree. there’s a problem though if you want to have the next sibling. You have to call

tracks.item(i).firstChild.nextSibling.firstChild.data; tracks.item(i).firstChild.nextSibling.nextSibling.firstChild.data; tracks.item(i).firstChild.nextSibling.nextSibling.nextSibling.firstChild.data; 

to get this done. The node next to that adds a ‘nextsibling’ to it and so on. I do not want to keep on adding these nodes and thought it would be possible to use childNodes[i] like this:

artist = tracks.item(i).childNodes[0].firstChild.data; nextitem = tracks.item(i).childNodes[1].firstChild.data; 

this doesn’t work though. it returns ‘childNodes[0] has no properties’ in whatever way I use it. Now I think there’s also a way in Xpath to do this in a for-loop:

name = doc.evaluate('string(/lfm/recenttracks[1]/track['+i+']/name)');                     print(name); othernode = doc.evaluate('string(/lfm/recenttracks[1]/track['+i+']/album)');                     print(othernode); 

and then increasing i for the next track. but somehow this returns only one item. it doesn’t retrieve more items in a for-loop. i-1 doesn’t work either.

Anyone knows how to use a Xpath expression with my i value to choose a node and then get the subnodes per supernode? Per track I want to get artist, name, streamable, mbid, album, url, image(small), image(medium), image(large) and date.

my xml file looks like this:

<lfm status='ok'>    <recenttracks user='xaddict'>       <track nowplaying='true'>           <artist mbid='f5b8ea5f-c269-45dd-9936-1fedf3c56851'>The Presets</artist>          <name>Girl (You Chew My Mind Up)</name>          <streamable>1</streamable>          <mbid></mbid>          <album mbid='b150d099-b0f3-4feb-9a05-34e693c6dd24'>Beams</album>          <url>http://www.last.fm/music/The+Presets/_/Girl+%28You+Chew+My+Mind+Up%29</url>          <image size='small'>http://userserve-ak.last.fm/serve/34s/8696437.jpg</image>          <image size='medium'>http://userserve-ak.last.fm/serve/64s/8696437.jpg</image>          <image size='large'>http://userserve-ak.last.fm/serve/126/8696437.jpg</image>          <date uts='1236440600'>7 Mar 2009, 15:43</date>       </track>       <track >           <artist mbid='f5b8ea5f-c269-45dd-9936-1fedf3c56851'>The Presets</artist>          <name>Get Outta Here</name>          <streamable>1</streamable>          <mbid></mbid>          <album mbid='0469956f-d895-4120-8ec5-29ad41b9e2fd'>Blow Up</album>          <url>http://www.last.fm/music/The+Presets/_/Get+Outta+Here</url>          <image size='small'>http://userserve-ak.last.fm/serve/34s/20923179.png</image>          <image size='medium'>http://userserve-ak.last.fm/serve/64s/20923179.png</image>          <image size='large'>http://userserve-ak.last.fm/serve/126/20923179.png</image>          <date uts='1236440242'>7 Mar 2009, 15:37</date>       </track>    </recenttracks> </lfm> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:10:36+00:00Added an answer on May 11, 2026 at 1:10 pm

    the fully Xpath-enabled way of doing this is using the string conversion in Xpath. Ive already posted this code as an answer to another question and will do this again. I’m very glad I found out about this way of doing things.

    var entries = xmlDoc.evaluate('lfm/recenttracks/track'); var length = entries.length; for(var i = 0; i &lt; length; i++) {    var entry = entries.item(i);    var obj = {       artist: entry.evaluate('string(artist)'),       name: entry.evaluate('string(name)'),       url: entry.evaluate('string(url)'),       image: entry.evaluate('string(image[@size='medium'])')    }; posts[i] = obj; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer It is possible to connect to the database without specifying… May 11, 2026 at 2:28 pm
  • added an answer Problem solved: select list did not have the name attribute… May 11, 2026 at 2:28 pm
  • added an answer I like XStream alot, especially compared to JAXB - unlike… May 11, 2026 at 2:28 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.