I have an XML document that gets generated by an object. I have no idea what it will really look like at the time of the jQuery AJAX call. What I would like to do is parse through the XML by parent and child getting the node names.
Any direction you can offer will be of great service.
Thanks!
I have an XML document that gets generated by an object. I have no idea what it will really look like at the time of the jQuery AJAX call. What I would like to do is parse through the XML by parent and child getting the node names.
Any direction you can offer will be of great service.
Thanks!
Share Improve this question edited Jun 17, 2011 at 19:36 webdad3 asked Jun 17, 2011 at 18:28 webdad3webdad3 9,13031 gold badges128 silver badges229 bronze badges 2- Do you have control over this webservice? If you do, would you consider returning a JSON object instead of XML? JSON is much easier and faster to work with. – pixelfreak Commented Jun 17, 2011 at 18:33
- unfortunately I don't have control... It is XML and will stay XML at least until the next version... – webdad3 Commented Jun 17, 2011 at 18:34
2 Answers
Reset to default 6 +50You should be able to parse through XML the same way you parse through DOM elements in jquery;
http://jsfiddle/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));
Have you looked at jParse?