Javascript to parse XML file
<p>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:</p>

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

<p>So the repeating and traversing nodes I believe should be in following way:</p>

<pre><code>series-&gt;drilldown-&gt;series-&gt;drilldown....
drilldown-&gt;categories
drilldown-&gt;data

Traversing path approach to be taken =
loop
{ 
          for (mainseries)
          {
              get y
              for(series-&gt;drilldown)
              {
                 get name, categories(names), data(points)
                 for(drilldown-&gt;series)
                 {
                        mainseries = currentseries
                 }
              }
         }
} 
</code></pre>

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

<pre><code>  $.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()))
                                                        });
                                                });
                                        });
                });
        });
</code></pre>

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

<pre><code>A series will never have values leaf node
A series is represented as a {..&lt;property : values&gt;..} 
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
</code></pre>

<p>Please help me in achieveing the objective.</p>

<p>Thanks in advance</p>
