I have a jQuery recursive function which parses my xml data however I am trying to select the children of the child element, so basically the element inside the element. for instance in the xml I want to select <to> tag, so I can indent and add a expand collapse button.
xml
<?xml version="1.0" encoding="UTF-8"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>
jQuery
function traverse(tree) {
            $(tree).contents().each(function (i, child) {
                    if (child.nodeType == 3) { // text node
                        $("#xml-reader").append(
                            '<span>' + child.nodeValue + '</span>'
                        );
                        // this is my attempt
                        if (child.children) { // element node
                            $("#xml-reader").append(
                                '<br><i>' + child.nodeName + ": " + '</i>'
                            );
                        }
                    } else {
                        if (child.nodeType === 8) { // comment node
                            $("#xml-reader").append(
                                '<i>' + child.nodeValue + '</i>'
                            );
                        }
                        else {
                            $("#xml-reader").append(
                                '<br><b>' + child.nodeName + ": " + '<b>'
                            );
                            traverse(child);
                        }
                    }
                }
            );
        }
        traverse($(xml).find('*'));