Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery XML层次树解析_Jquery_Xml - Fatal编程技术网

Jquery XML层次树解析

Jquery XML层次树解析,jquery,xml,Jquery,Xml,我有这个XML文件,如上所示,我想解析字段outputId -<personRepresentaion> <theId>1324</theId> <name>John</name> <topY>1</topY> <leftX>0</leftX> <height>10</height> <w

我有这个XML文件,如上所示,我想解析字段
outputId

-<personRepresentaion>
      <theId>1324</theId>
      <name>John</name>
      <topY>1</topY>
      <leftX>0</leftX>
      <height>10</height>
      <width>12</width>
     -<relationships>
       <inputId>1324</inputId>
       <outputId>1325</outputId>
      </relationships>
    </personRepresentaion>
-
1324
约翰
1.
0
10
12
-
1324
1325
目前,我解析其他字段,如下所示:

var x=xmlDoc.getElementsByTagName("personRepresentaion"); 
for (i=0;i<x.length;i++){
var y =x[i].getElementsByTagName("theId")[0].childNodes[0].nodeValue //this gets me theId

//now I want to get the outputId
var outputId = x[i].getElementsByTagName("outputId")[0].childNodes[0].nodeValue //what is wrong with this?
}
var x=xmlDoc.getElementsByTagName(“PersonRepresentation”);
对于(i=0;i请尝试使用jquery这样做:

jQuery(document).ready(function($){
    var _personXML = $('<personRepresentaion><theId>1324</theId><name>John</name><topY>1</topY><leftX>0</leftX><height>10</height><width>12</width><relationships><inputId>1324</inputId><outputId>1325</outputId></relationships></personRepresentaion>');

    alert("the id: "+_personXML.find("theId").eq(0).text());    
    _personXML.find("relationships").each(function(){
        alert("Output id: "+$(this).find("outputId").eq(0).text());
    });

});
jQuery(文档).ready(函数($){
var_personXML=$('1324john10101232411325');
警报(“id:”+_personXML.find(“theId”).eq(0.text());
_查找(“关系”).each(函数(){
警报(“输出id:+$(this).find(“outputId”).eq(0.text());
});
});
更新:*演示*