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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:38:31+00:00 2026-05-31T10:38:31+00:00

I am a bit novice in JS and trying to parse and XML file

  • 0

I am a bit novice in JS and trying to parse and XML file as a response via an AJAX call which is following format:

<chart>
     <categories>
        <name>'MSIE'</name>
        <name>'Firefox'</name>
        <name>'Chrome'</name>
        <name>'Safari'</name>
        <name>'Opera'</name>
      </categories>
      <name>'Browser Brands'</name>
      <data>
             <series>
               <y>55.11</y>
               <drilldown>
                  <name>'MSIE versions'</name>
                  <categories>
                      <name>'MSIE 8.0'</name>
                      <name>'MSIE 6.0'</name>
                      <name>'MSIE 7.0'</name>
                      <name>'MSIE 9.0'</name>
                  </categories>
                 <data>
                     <series>
                       <y>33.06</y>
                       <drilldown>
                           <name>'drilldown next level'</name>
                            <categories>
                              <name>'a'</name>
                              <name>'b'</name>
                              <name>'c'</name>
                            </categories>
                            <data>
                              <point>23</point>
                              <point>54</point>
                              <point>47</point>
                             </data>
                       </drilldown>
                     </series>
                   <point>10.85</point>
                   <point>7.35</point>
                   <point>2.41</point>
                 </data>
               </drilldown>
             </series>
             <series>
               <y>21.63</y>
                <drilldown>
                <name>'Firefox versions'</name>
                <categories>
                    <name>'Firefox 3.6'</name>
                    <name>'Firefox 4.0'</name>
                    <name>'Firefox 3.5'</name>
                    <name>'Firefox 3.0'</name>
                    <name>'Firefox 2.0'</name>
                </categories>
                 <data>
                    <point>13.52</point>
                    <point>5.43</point>
                    <point>1.58</point>
                    <point>0.83</point>
                    <point>0.20</point>
                 </data>
               </drilldown>
             </series>
             <series>
               <y>11.94</y>
               <drilldown>
                <name>'Chrome versions'</name>
                <categories>
                   <name>'Chrome 10.0'</name>
                   <name>'Chrome 11.0'</name>
                   <name>'Chrome 8.0'</name>
                   <name>'Chrome 9.0'</name>
                   <name>'Chrome 12.0'</name>
                   <name>'Chrome 6.0'</name>
                   <name>'Chrome 5.0'</name>
                   <name>'Chrome 7.0'</name>
                </categories>
                <data>
                   <point>9.91</point>
                   <point>0.50</point>
                   <point>0.36</point>
                   <point>0.32</point>
                   <point>0.22</point>
                   <point>0.19</point>
                   <point>0.12</point>
                   <point>0.12</point>
               </data>
               </drilldown>
               </series>
               <series>
               <y>7.15</y>
               <drilldown>
               <name>'Safari versions'</name>
               <categories>
                   <name>'Safari 5.0'</name>
                   <name>'Safari 4.0'</name>
                   <name>'Safari Win 5.0'</name>
                   <name>'Safari 4.1'</name>
                   <name>'Safari/Maxthon'</name>
                   <name>'Safari 3.1'</name>
                   <name>'Safari 41'</name>
               </categories>
               <data>
                   <point>4.55</point>
                   <point>1.42</point>
                   <point>0.23</point>
                   <point>0.21</point>
                   <point>0.20</point>
                   <point>0.19</point>
                   <point>0.14</point>
               </data>
            </drilldown>
           </series>
           <series>
              <y>2.14</y>
               <drilldown>
               <name>'Opera versions'</name>
               <categories>
                  <name>'Opera 11.x'</name>
                  <name>'Opera 10.x'</name>
                  <name>'Opera 9.x'</name>
               </categories>
                <data>
                   <point>1.65</point>
                   <point>0.37</point>
                   <point>0.12</point>
                 </data>
                </drilldown>
            </series>
        </data>
</chart>

So the repeating and traversing nodes I believe should be in following way:

series->drilldown->series->drilldown....
drilldown->categories
drilldown->data

Traversing path approach to be taken =
loop
{ 
          for (mainseries)
          {
              get y
              for(series->drilldown)
              {
                 get name, categories(names), data(points)
                 for(drilldown->series)
                 {
                        mainseries = currentseries
                 }
              }
         }
} 

As I am a novice I am somehow not getting the traversing and parsing logic which I want to implement:

  $.get('ex.xml', function(xml) {
                var $xml = $(xml);
                $xml.find('chart categories name').each(function(i, category) {
                        options.xAxis.categories.push($(category).text());
                });
                chart.setTitle.push($xml.find('chart name').text());
                $xml.find('series').each(function(i, series) {
                                var seriesOptions = {
                                        y: parseInt($(series).find('y').text()),
                                        drilldown : []
                                        };
                                        $xml.find('series drilldown').each(function(i, drilldown) {
                                                name : $(drilldown).find('name').text()
                                                categories : [],
                                                data: []
                                                $xml.find('drilldown categories').each(function(i, categories) {
                                                        name : $(categories).find('name').text()
                                                        });
                                                $xml.find('drilldown data').each(function(i, data) {
                                                        $xml.find('data point').each(function(i, point) {
                                                                seriesOptions.drilldown.data.push(parseInt($(point).text()))
                                                        });
                                                });
                                        });
                });
        });

How can I have the traversing and each leaf / branch node be visited so that I can get the chart data, note that:

A series will never have values leaf node
A series is represented as a {..<property : values>..} 
A series will always one drilldown and a drilldown will have one series in itself which goes in repetition
A series will always have a proerty y or a drilldown
A drilldown will have name leaf node,categories branch and either a another series or a data branch
A category branch will always have a name leaf node
A data branch will always have values leaf node

Please help me in achieveing the objective.

Thanks in advance

  • 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-05-31T10:38:32+00:00Added an answer on May 31, 2026 at 10:38 am

    I think the key to the answer you’re looking for is to use the $(this) in jQuery. That is a self-referencing element within the each() function so that for each element, $(this) refers to that element.

    With that in mind, you can then do:

    var thisElement = $(this);
    thisElement.find("some other selector").each(function(){
        var theOtherSelector = $(this);
        theOtherSelector.find("yet another selector").each(function(){
           // and so forth...
        };
    })
    

    Note that I am storing the $(this) reference to a variable so that the value is accessible within the function closure scope.

    Hope this answers your question

    Edit: example code for recursive depth search for your xml (haven’t been checked for syntax!)

    $xml.find("chart data series").each(function(){
        var chartDataSeries = $(this);
        var seriesDrillDownSearch = function(){
            var seriesDrillDownElement = $(this);
    
            // do your processing here ..
    
            seriesDrillDownElement.find("series drilldown").each(seriesDrillDownSearch);
        }();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a novice in mySql. I'm trying to replace a value in the xml
I have the following bit of code. I'm trying to dynamically add drop-down options
I realize this is a bit of a novice question. I am trying to
I apologize for wording as I'm a bit novice. Here's what I'm trying to
Bit of a beginner question here: Say I have a block of xml: <root>
I'm trying to create a .resx file from a dictionary of strings. Luckily the
I am a novice to IOS programming hence struggling a bit with the below
Before we start, I apologize for my MYSQL novice status. I'm trying to self-teach
I have been fighting with this for a bit now. I’m trying to convert
I'm trying to do something a bit unusual... I have this class Foo :

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.