【发布时间】:2011-06-08 18:57:13
【问题描述】:
我正在解析 XML,并希望以易于阅读的方式存储这些值。
我得到了 mapShapes 和 mapPoints(所以 x 和 y 坐标)。 (x,y) 对构成一个点,点的集合构成一个形状。
这是我想解析的一些示例 XML:
<?xml version='1.0'?>
<mapQuery id='10918014'>
<mapShape id='429436'>
<mapPoint id='4259799'>
<x>-81.61508</x>
<y>41.52184</y>
</mapPoint>
<mapPoint id='4259800'>
<x>-81.61537</x>
<y>41.52181</y>
</mapPoint>
<mapPoint id='4259801'>
<x>-81.61538</x>
<y>41.522198</y>
</mapPoint>
<mapPoint id='4259802'>
<x>-81.61516</x>
<y>41.52222</y>
</mapPoint>
<mapPoint id='4259803'>
<x>-81.61508</x>
<y>41.52184</y>
</mapPoint>
</mapShape>
</mapQuery>
我想得到一个类似的数组
shapes[0].point[0].x[0] = first x point
shapes[0].point[0].y[0] = first y point
(此示例 XML 仅存在一个形状,但可能有多个。)
提前感谢您对一个简单问题的帮助 =)
这是一些骨架代码:
shapeXmlHandler : function(xml){
$(xml).find("mapShape").each(function(){
$(this).find("mapPoint").each(function() {
console.log('mapPoint: '+$(this).attr('id'));
console.log('x :'+$(this).find("x").text());
console.log('y :'+$(this).find("y").text());
});
});
}
【问题讨论】:
-
您遇到了什么问题?到目前为止看起来不错(除了我认为您实际上想要
shapes[0].point[0].x = first x point等) -
好电话。我不确定如何实现目标,但我已经很接近了。我真的不知道在解析它时将 xml 数据放入数组中的最佳方法是什么,所以我在寻求建议
标签: javascript jquery xml arrays