Jquery 遍历xmldom
如何使用javscript/jquery遍历XMLDOM? 我的xml是自定义名称空间的。我使用的是ajax get,它在控制台中返回文档。 我如何解析/遍历它Jquery 遍历xmldom,jquery,xml-parsing,xmldocument,Jquery,Xml Parsing,Xmldocument,如何使用javscript/jquery遍历XMLDOM? 我的xml是自定义名称空间的。我使用的是ajax get,它在控制台中返回文档。 我如何解析/遍历它 $.ajax({ type: 'GET', url: 'xmlsimple.xml', dataType: 'xml', success: function(data) { parseXml(data); }, error: function() { ale
$.ajax({
type: 'GET',
url: 'xmlsimple.xml',
dataType: 'xml',
success: function(data) {
parseXml(data);
},
error: function() {
alert('fail');
}
});
});
据我所知,我使用的jQuery 1.8不允许反斜杠转义名称空间或使用find([namespace=“*”])。/
//
// this might help:
//
// traverse.dom(
// function() {
// // this === current_node ( inside callback )
// // doStuffWith( this );
// // return ( === )false, to break iteration
// },
//
// startNode // provide a node to start traversing from ( it is included in traversal )
//
// );
//
//
// $.ajax({
// url : 'xmlsimple.xml',
// dataType : 'xml',
// success : function( doc ) {
// traverse.dom( function() { console.log( this ); }, doc );
// }
// });
//
;
( function( w, _a ) {
var
pn = this.toString(),
F = {},
t = !0,
f = !t,
_s = _a.slice,
_d = w.document;
function _gather_nodes( node, coll ) {
coll.push( node );
node = node.firstChild;
while ( node ) {
_gather_nodes( node, coll );
node = node.nextSibling;
}
return coll;
}
_a.each = function( callback ) {
return ( function ( fn, len, k ) {
for ( ; k < len ; k++ )
if (
( function( i ) {
return fn.call( this, i, this[i] );
} ).call( this, k ) === f ) break;
return this;
} ).call( this, callback, this.length, 0 );
};
F.dom = function( callback_fn, startNode/*, ...args*/ ) {
var
args1 = _s.call( arguments, 2 );
return ( _gather_nodes( ( startNode || _d ), [] ) ).each( function ( pos, N ) {
return callback_fn.apply( N, args1 );
} );
};
w[pn] = F;
} ).call( new String('traverse'), window, Array.prototype );
//这可能有助于:
//
//traverse.dom(
//函数(){
////this==当前_节点(回调内部)
////Dostufwith(这个);
////返回(==)false,以中断迭代
// },
//
//startNode//提供一个开始遍历的节点(它包含在遍历中)
//
// );
//
//
//$.ajax({
//url:'xmlsimple.xml',
//数据类型:“xml”,
//成功:功能(doc){
//dom(function(){console.log(this);},doc);
// }
// });
//
;
(函数(w,_a){
变量
pn=this.toString(),
F={},
t=!0,
f=!t,
_s=_a.slice,
_d=w.文件;
函数_聚集_节点(节点,coll){
coll.push(节点);
node=node.firstChild;
while(node){
_聚集_节点(节点,coll);
node=node.nextSibling;
}
返回coll;
}
_a、 each=函数(回调){
返回(函数(fn,len,k){
对于(;k
//
//这可能有助于:
//
//traverse.dom(
//函数(){
////this==当前_节点(回调内部)
////Dostufwith(这个);
////返回(==)false,以中断迭代
// },
//
//startNode//提供一个开始遍历的节点(它包含在遍历中)
//
// );
//
//
//$.ajax({
//url:'xmlsimple.xml',
//数据类型:“xml”,
//成功:功能(doc){
//dom(function(){console.log(this);},doc);
// }
// });
//
;
(函数(w,_a){
变量
pn=this.toString(),
F={},
t=!0,
f=!t,
_s=_a.slice,
_d=w.文件;
函数_聚集_节点(节点,coll){
coll.push(节点);
node=node.firstChild;
while(node){
_聚集_节点(节点,coll);
node=node.nextSibling;
}
返回coll;
}
_a、 each=函数(回调){
返回(函数(fn,len,k){
对于(;k
不是重复的-让我更新我的问题@Rhyso:它仍然是重复的,只是答案已经改变了(见对已接受答案的评论。看起来是正确的痛苦。不是重复的-让我更新我的问题@Rhyso:它仍然是重复的,只是答案已更改。)(见对已接受答案的评论。看起来是正确的痛苦。