JQuery get all node names (both parent and child)

I have an XML document that is generated by an object. I do not know how it will look during a jQuery AJAX call. What I would like to do is parse the XML through the parent and child elements, getting the node names.

Any direction you can offer will be an excellent service.

Thank!

+3
source share
2 answers

You should be able to parse XML the same way you parse DOM elements in jquery;

http://jsfiddle.net/TBwm8/3/

var xml = "<root><stuff></stuff><stuff><stuffchild></stuffchild></stuff></root>";

function alertit(jqueryObject) {
    if (jqueryObject.length === 0) return;

    jqueryObject.each(function() {
        alert(this.nodeName.toLowerCase());
    });

    alertit(jqueryObject.children());
}

alertit($(xml));
+6
source

Have you watched jParse ?

0
source

All Articles