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

  • SEARCH
  • Home
  • 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 8665777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:34:09+00:00 2026-06-12T17:34:09+00:00

I am pulling my hair out trying to create an unordered list from an

  • 0

I am pulling my hair out trying to create an unordered list from an xml file with no luck so far.I know how to process the xml from jQuery but I am not able to figure out how to make the multi-level unordered list.

Here is what I have achieved so far.

The xml file

<?xml version="1.0" encoding="utf-8"?>
<Parent>Director
    <Children>Exe Director1</Children>
    <Children>Exe Director2</Children>
    <Parent>Exe Director2
        <Children>Sub Director 1</Children>
        <Children>Sub Director 2</Children>
        <Parent>Sub Director 3
            <Children>Cameraman 1</Children>
            <Children>Cameraman 2</Children>
        </Parent>
    </Parent>    
</Parent>

The html file

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
    var levels;
    $(document).ready(function() 
    {
        $.ajax({
            type: "GET",
            url: "test.xml",
            dataType: "xml",
            success: xmlParser
        });
    });
    function xmlParser(xml)
{
    $(xml).find("Children").each(function()
    { 
        var text = $(this).text();
    });
}
</script>
</head>
<body>
    <div id="ListContainer"></div>
</body>
</html>

This is the expected list

<ul>
    <li>Exe Director1</li>
    <li>Exe Director2</li>
    <ul>
        <li>Sub Director 1</li>
        <li>Sub Director 2</li>
        <ul>
            <li>Cameraman 1</li>
            <li>Cameraman 2</li>
        </ul>
    </ul>
</ul>

Can you guys please help me out!

Edit:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
    var levels;
    $(document).ready(function() 
    {
        $.ajax({
            type: "GET",
            url: "test.xml",
            dataType: "xml",
            success: function (xml) { xmlParser($(xml)); }
        });
    });
    function xmlParser(xml) {
        //alert($(xml).contents());  
        var $ul = $("<ul>"); // For each Parent, create an <ul>
        $(xml).contents().each(function (i, el) {
            if (el.nodeType == 3) return true;
            if (el.nodeName.toUpperCase() == "CHILDREN") 
            {
               $("<li>").text($(el).text()).appendTo($ul); // Append <li> Children
            } else 
            {
               $ul.append(xmlParser($(el))); // Recursively append the other Parent
            }
            //$("#ListContainer").append($ul);
        });
        //alert($ul.html());
        $("#ListContainer").append($ul);
    }
</script>
</head>
<body>
    <div id="ListContainer"></div>
</body>
</html>
  • 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. Editorial Team
    Editorial Team
    2026-06-12T17:34:11+00:00Added an answer on June 12, 2026 at 5:34 pm

    Recursively construct the unordered list:

    function xmlParser($xml) {   
        var $ul = $("<ul>"); // For each Parent, create an <ul>
        $xml.contents().each(function (i, el) {
            if (el.nodeType == 3) return true;
            if (el.nodeName.toUpperCase() == "CHILDREN") {
               $("<li>").text($(el).text()).appendTo($ul); // Append <li> Children
            } else {
               $ul.append(xmlParser($(el))); // Recursively append the other Parent
            }
        });
        return $ul;
    }
    

    Here’s a DEMO. Think of each group Parent and respective Children as a separate unit. For example, if your XML looked like the following:

    <Parent>Director
        <Children>Exe Director1</Children>
        <Children>Exe Director2</Children>
    </Parent>
    

    The resulting HTML would be:

    <ul>
        <li>Exe Director1</li>
        <li>Exe Director2</li>
    </ul>
    

    How would you construct this? It’s quite simple: create an <ul> element, and for each Children append a <li> element to it. Now, for the recursive part, when you introduce another Parent, you simply create another <ul> again is if it were a single unit, and append its result to the parent <ul>.

    Note that the function that I’ve used above requires a jQuery object to passed as an argument, thus you’d need to change your success handler:

    success: function (xml) {
      xmlParser($(xml));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been pulling my hair out trying to use jQuery.get() to pull in my
Am pulling my hair out trying getting GeoCoder working. I went so far as
Pulling my hair out, trying to figure out what's wrong here. Create table query:
I'm pulling my hair out trying to get a jQuery script working that will
I'm pulling my hair out trying to find a simple jquery gallery. I must
I'm pulling my hair out trying to figure out why the mouseover event won't
I have been pulling my hair out trying to figure out what I can't
Ive been pulling my hair out trying to figure out how to embed a
I have been pulling my hair out trying to make this work. I have
Hey Apple developers, I'm pulling my hair out trying to figure out how iOS

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.