我有一个像这样的XML文件:
<Factory>
<Limits>
<Point X="92" Y="489"/>
<Point X="570" Y="487"/>
<Point X="570" Y="138"/>
<Point X="92" Y="140"/>
<Point X="92" Y="139"/>
</Limits>
<Cells>
<Cell>
<Point X="358" Y="138"/>
<Point X="361" Y="487"/>
<Point X="570" Y="487"/>
<Point X="570" Y="138"/>
<Point X="358" Y="138"/>
</Cell>
<Cell>
<Point X="311" Y="139"/>
<Point X="311" Y="488"/>
<Point X="92" Y="489"/>
<Point X="92" Y="140"/>
<Point X="311" Y="139"/>
</Cell>
</Cells>
我正在尝试使用Javascript获取“Limits”中每个“Point”的X和Y值(而不是“Cell”中的值)。我看到了很多使用getElementByTagName、childNodes等方法的示例,但我无法弄清楚如何获取我要查找的数据。 我想这样做可能有效:
var M = xmlDoc.getElementsByTagName("Limits")[0].childNodes;
for (i=0;i<M.length;i++){
console.log(M[i].childNodes.item(0));
}
我尝试了几种方法,但最终要么得到 null 值,要么出现错误。
有没有简单的方法来实现我需要的功能?