简体   繁体   English

jQuery获取所有节点名称(父节点和子节点)

[英]jQuery get all node names (both parent and children)

I have an XML document that gets generated by an object. 我有一个由对象生成的XML文档。 I have no idea what it will really look like at the time of the jQuery AJAX call. 我不知道在jQuery AJAX调用时它会是什么样子。 What I would like to do is parse through the XML by parent and child getting the node names. 我想要做的是通过父和子获取节点名称来解析XML。

Any direction you can offer will be of great service. 您可以提供的任何方向都将提供很好的服务。

Thanks! 谢谢!

You should be able to parse through XML the same way you parse through DOM elements in jquery; 你应该能够像解析jquery中的DOM元素一样解析XML;

http://jsfiddle.net/TBwm8/3/ 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));

你看过jParse吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM