DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: Looping through XML results

  1. #1
    Join Date
    Jul 2007
    Posts
    1

    Looping through XML results

    Hi, I got a question that I'd like some help with. Let me explain:

    To start, I'm doing an AJAX call to update a side pannel on a home page. The AJAX call is grabbing an XML object that's thrown together from a PHP script. Th e XML object really contains a few things (title, paragraph and a few li's). My script is pulling in everything fine and parsing it fine too. However my problem is I'm trying to loop through the object and grab the li's but I can't seem to figure out why it's not working.

    My code looks like this:
    function BuildXML(obj)
    {
    //create vars
    //title
    var obj_title = obj.getElementsByTagName('title')[0].childNodes[0].nodeValue;
    var title = document.createTextNode(obj_title);

    //list items
    var obj_bullet = obj.getElementsByTagName('bullet');
    var ul = document.createElement('ul');

    //loop through list items
    for(i=0; i < obj_bullet.length; i++)
    {
    var li = document.createElement('li');
    var bullet = obj_bullet[i].childNodes[0].nodeValue;
    }

    //description
    var obj_desc = obj.getElementsByTagName('description')[0].childNodes[0].nodeValue;
    var desc = document.createTextNode(obj_desc);

    //parse data
    a_page.appendChild(title);
    para.appendChild(desc);
    }

    I'm still kinda learning everything so any help would be great.
    Thanks,
    Ben

    Edit: I got it working afterall- I had to take a break and when I came back I realized my mistake.

    Here's what my function looks like now:
    function BuildXML(obj)
    {
    //create vars
    //title
    var obj_title = obj.getElementsByTagName('title')[0].childNodes[0].nodeValue;
    var title = document.createTextNode(obj_title);

    //list items
    var obj_bullet = obj.getElementsByTagName('bullet');

    //loop through list items
    for(i=0; i < obj_bullet.length; i++)
    {
    var li = document.createElement('li');
    var value_bullet = obj_bullet[i].childNodes[0].nodeValue;
    var bullet = document.createTextNode(value_bullet);
    li.appendChild(bullet);
    ul.appendChild(li);
    }

    //description
    var obj_desc = obj.getElementsByTagName('description')[0].childNodes[0].nodeValue;
    var desc = document.createTextNode(obj_desc);

    //parse data
    a_page.appendChild(title);
    para.appendChild(desc);
    }

    First, I realized I had forgotten to create a text node for my li. Then I realized I needed to append the newly created text node into my li, append the li to my ul.

    Hopefully this makes sense if anybody is reading this that was having the same problem I was. Thanks for reading.
    Last edited by bbabics; 07-08-2007 at 09:11 PM.

Similar Threads

  1. Try XML Junction
    By Tim in forum xml.announcements
    Replies: 0
    Last Post: 10-11-2001, 04:00 PM
  2. XML Startkabel Updates
    By xmlstartkabel in forum XML
    Replies: 0
    Last Post: 10-10-2001, 04:07 AM
  3. Data Junction Announces XML Junction 7.51
    By Tim Frost in forum xml.announcements
    Replies: 0
    Last Post: 04-02-2001, 10:53 AM
  4. Check out Turbo XML: Free trial download
    By Extensibility in forum web.announcements
    Replies: 0
    Last Post: 07-20-2000, 06:20 PM
  5. Check out Turbo XML
    By Sales in forum xml.announcements
    Replies: 0
    Last Post: 07-20-2000, 06:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center