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 9228691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:23:14+00:00 2026-06-18T05:23:14+00:00

this is xml file:- <root> <child1 entity_id = 1 value= Asia> <child2 entity_id =

  • 0

this is xml file:-

<root>
<child1 entity_id = "1" value= "Asia">
    <child2 entity_id = "2" value = "india">
        <child3 entity_id = "3" value = "Gujarat">
            <child5 entity_id = "5" value ="Rajkot"></child5>
        </child3>
        <child4 entity_id = "4" value = "Rajshthan">
            <child6 entity_id = "6" value = "Ajmer"></child6>
        </child4>
    </child2>
</child1>
</root>

this is my jquery file:-

   data = false;
function loadChild(id) {
    var obj = $("#" + id);

    if(obj.data("loaded") == null) {
        ul = "<d>";
        var path = (id == 0) ? "root" : "[entity_id='" + id + "']";

        // Only if it contains children
        if( $(data).find(path).children().length > 0) {
            $("li").hide();
            if($(this).data("loaded") == null) {
            $("#path").text($("#path").text()  + obj.text()+ " => ");
        }
        }

        $(data).find(path).children().each(function(){
            var value_text = $(this).attr('value');
            var id = $(this).attr('entity_id');
            ul += "<li id='" + id + "'>" + value_text + "</li>";
        });

        ul += "</d>";

        $("#" + id).before(ul);
        obj.data("loaded", true);
    } else {
        $("#" + id + " ul").remove();
        //obj.data("loaded", null);
    }
}

 $(document).ready(function() {
     $('#loader').click(function() {
     $(this).hide();
      $.ajax({
             type: "GET",
             url: "try.xml",
             dataType: "xml",
             success: function(xml) {
                data = xml;
                ul = $("<d></d>");
                //loadChild("0");
                $(xml).find('child1').each(function(){
                var value_text = $(this).attr('value');
                var id = $(this).attr('entity_id');
                li=$("<li id='" + id + "'></li>");
                             li.html(value_text);
                             ul.append(li);
                             $(this).unbind('click');
                });
                             ul.appendTo('#firstLevelChild');
    }
         }); //close $.ajax(
     }); //close click(
     $(document).on("click", "li", function(event) {

        event.stopPropagation();
        loadChild($(this).attr("id"), event);
        return false;
 });
 });

this is my html file:-

<div id="path">
</div>
<div id="1">
<span  id='update-target'>Click here to load value</span>
<ol id="0"></ol>
</div>
<div id="firstLevelChild">
<ol id="0"></ol>
</div>

and my output is something like:

<div id="firstLevelChild">
    <ul>
        <li id="1" style="display: none;">Asia</li>
        <ul>
            <li id="2" style="display: none;">india</li>
            <ul>
                <li id="3">Gujarat</li>
                <li id="4">Rajshthan</li>
            </ul>
        </ul>
    </ul>
</div>
<div id="path">  Asia => india => Gujarat =></div><br>

If i am click on div path value any of like India then only asia dispaly in path
Then india diaplay on another div

like

<div id="path"> Asia => India => Gujarat =>

if i am clicked on India then output display something like this

<div id="path"> Asia =>
<div id="firstLevelChild">
<d><li id="2"> Inida </li></d>
</div>

something like reverse process

thanks 🙂

  • 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-18T05:23:15+00:00Added an answer on June 18, 2026 at 5:23 am

    I have got a solution for you, but you will need to fix your code for this to work…

    Working code…

    HTML

    <body>
        <div id="loader">
            <span id='update-target'>Click here to load value</span>
        </div>
    
        <div id="firstLevelChild"></div>
    
        <div id="path"></div>
    </body>
    

    jQuery

    data = false;
    
    $(document).ready(function() {
        $('#loader').click(function() {
            $(this).hide();
            $.ajax({
                type: "GET",
                url: "./final.xml",
                dataType: "xml",
                success: function(xml) {
                    data = xml;
                    ul = $("<ul></ul>");
                    $(xml).find('child1').each(function(){
                        var value_text = $(this).attr('value');
                        var id = $(this).attr('entity_id');
                        li = $("<li id='" + id + "'></li>");
                        li.html(value_text);
    
                        ul.append(li);
                    });       //close each(      
                    ul.appendTo('#firstLevelChild');
                }
            }); //close $.ajax(
        }); //close click(
    
        $(document).on("click", "li", function(event) {
            event.stopPropagation();
            loadChild($(this).attr("id"), false);
            return false;
        });
    
        $(document).on("click", "span.paths", function(event) {
            event.stopPropagation();
            id = $(this).attr("id").replace("path_","");
            $(this).nextAll("span").remove();
            $(this).remove();
            loadChild(id, true);
            return false;
        });
    });
    
    function loadChild(id, path) {
        var obj = $("#firstLevelChild #" + id);
    
        if(obj.data("loaded") == null || path) {
            ul = "<ul>";
            var path = (id == 0) ? "root" : "[entity_id='" + id + "']";
    
            // Only if it contains children
            if( $(data).find(path).children().length > 0) {
                $("li").hide();
                $("span #path_" + id).remove();
                p = $("<span id=\"path_" + id + "\" class=\"paths\">" + obj.text() + " => </span>"); 
                $("#path").append(p);
            }
    
            $(data).find(path).children().each(function(){
                var value_text = $(this).attr('value');
                var id = $(this).attr('entity_id');
                $("#" + id).remove();
                ul += "<li id='" + id + "'>" + value_text + "</li>";
            });
    
            ul += "</ul>";
    
            obj.after(ul);
            obj.data("loaded", true);
        } else {
            $("#" + id + " ul").remove();
            obj.data("loaded", null);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my xml file :- <root> <child1 entity_id = 1 value= Asia> <child2
Lets consider this xml file : <?xml version=1.0 encoding=UTF-8?> <root attribute=value> <element>myElement</element> </root> I'm
i have a xml file like <?xml version=1.0 encoding=ISO-8859-1?> <childrens> <child entity_id=1 value=Root Catalog
I have this XML at http://localhost/file.xml : <?xml version=1.0 encoding=utf-8?> <val:Root xmlns:val=http://www.hw-group.com/XMLSchema/ste/values.xsd> <Agent> <Version>2.0.3</Version>
The xml file is having the following structure <Root> <Child value=A/> <Child value=B/> <Child
I have an XML file like this to work with. <root> <ignore> <child>1</child> </ignore>
This is a sample of the XML file : <Nodes version=1> <Node name=root> <Node
I have an XML file: <?xml version=1.0 encoding=ISO-8859-1?> <childrens> <child id=1 value=Root Catalog parent_id=0>
With this XML file - <Instructions> <Admin> <Instruction> Steps must be completed in order.&lt;/br&gt;
This is my Xml file.i want to transform this xml file into another customized

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.