Jquery从给定XML文档中选择所有节点的方法 [英] Jquery's method of selecting all nodes from a given XML document

查看:98
本文介绍了Jquery从给定XML文档中选择所有节点的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<A>
<z id="232" zzz="3" aaa="13" >
<z id="232" zzz="3" aaa="13">
<z id="232" zzz="3" aaa="13">
</A>





我需要使用jquery选择所有''z'节点。

我已经知道了使用Xpath实现(由FF,chrome支持)和Msxml2.DOMDocument(selectNodes - 在IE中使用)



我基本上想要删除检查浏览器类型并写一个常见的Jquery实现来做到这一点。我必须将所有节点分别放入js数组中以便以后处理。

感谢Adance





低于2行可以获得所有z节点。假设结果包含上面的xml。



I need to select all ''z'' nodes using jquery.
I already know implemntation using Xpath(supported by FF,chrome) and Msxml2.DOMDocument(selectNodes--used in IE)

I basically want to remove check for Browser type and write a common Jquery implementation to do that. I have to put all the nodes seperately into an js array for later processing.
Thanks in Adance


Below 2 lines gets me all the ''z'' nodes. Assume result contains above xml.

xmlDoc = $.parseXML(result);
var Nodenew = $(xmlDoc).find("z");





但是我发现它并没有将命令保留在属性中。例如:第一个''z''节点按此顺序具有属性:id,zzz,aaa但是我没有得到这个订单,而是我得到zzz,aaa,id。

有什么方法吗?没有XPath,可以订购它,适合IE和FF.Thanks



But i see that it is not keeping the order within attributes. For ex: First ''z'' nodes has attribute in this order: id,zzz,aaa but i am not getting this order, instead i get zzz,aaa,id.
Is there any method without XPath which can order it and fits for both IE and FF.Thanks

推荐答案

.parseXML(result);
var Nodenew =
.parseXML(result); var Nodenew =


(xmlDoc).find( z);
(xmlDoc).find("z");





但是我看到它是不保持属性中的顺序。例如:第一个''z''节点按此顺序具有属性:id,zzz,aaa但是我没有得到这个订单,而是我得到zzz,aaa,id。

有什么方法吗?没有XPath可以订购,适合IE和FF.Thanks



But i see that it is not keeping the order within attributes. For ex: First ''z'' nodes has attribute in this order: id,zzz,aaa but i am not getting this order, instead i get zzz,aaa,id.
Is there any method without XPath which can order it and fits for both IE and FF.Thanks


你好,



下面是一个小的演示HTML 。它展示了如何使用混合的JQuery和amp;来处理XML。 JavaScript。

Hello,

Below is a small demo HTML. It shows how to process XML using a mix of JQuery & JavaScript.
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<p id="someElement"></p>
<p id="anotherElement"></p>
<script>
var xml = '<a><z id="232" zzz="3" aaa="13" /><z id="232" zzz="3" aaa="13" /><z id="232" zzz="3" aaa="13" /></a>';
var xmlDoc =


这篇关于Jquery从给定XML文档中选择所有节点的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆