Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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,它会重复自己: <sample> <org.postgis.Point> <dimension>2</dimension> <haveMeasure>false</haveMeasure> <type>1</type> <srid>4326</srid> <x>-73.4397583007

假设我有一个XML,它会重复自己:

<sample>
    <org.postgis.Point>
     <dimension>2</dimension>
     <haveMeasure>false</haveMeasure>
     <type>1</type>
     <srid>4326</srid>
     <x>-73.43975830078125</x>
     <y>42.0513801574707</y>
     <z>0.0</z>
     <m>0.0</m>
    </org.postgis.Point>
<sample>

这是正确的想法吗?有没有一种不那么冗长的方法可以进入嵌套的标记?

首先,您需要转义
s,因为在CSS选择器中,它们表示类。接下来,您可以使用子代组合符
,删除每个
es的
级别:

$(xml).find('sample org\\.postgis\\.Point').each(function() {
     var x = $(this).find('x').text();
当然,如果只有一个
org.postgis.Point

var x = $(xml).find('sample org\\.postgis\\.Point x').text();

首先,您需要转义
s,因为在CSS选择器中,它们表示类。接下来,您可以使用子代组合符
,删除每个
es的
级别:

$(xml).find('sample org\\.postgis\\.Point').each(function() {
     var x = $(this).find('x').text();
当然,如果只有一个
org.postgis.Point

var x = $(xml).find('sample org\\.postgis\\.Point x').text();