使用jQuery访问XML数据?
假设我有一个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
<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();