I have an xml file that looks like this :
<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>
I'm trying to get the X and Y values of each "Point" in "Limits" (not those in "Cell") using Javascript. I saw a lot of examples with getElementByTagName, childNodes, ... but I can't figure out how to get the data I'm looking for. I thought something like this would work:
var M = xmlDoc.getElementsByTagName("Limits")[0].childNodes;
for (i=0;i<M.length;i++){
console.log(M[i].childNodes.item(0));
}
I tried a few different things but I always end up either with a null value or with an error.
Is there any simple way to do what I need ?
I have an xml file that looks like this :
<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>
I'm trying to get the X and Y values of each "Point" in "Limits" (not those in "Cell") using Javascript. I saw a lot of examples with getElementByTagName, childNodes, ... but I can't figure out how to get the data I'm looking for. I thought something like this would work:
var M = xmlDoc.getElementsByTagName("Limits")[0].childNodes;
for (i=0;i<M.length;i++){
console.log(M[i].childNodes.item(0));
}
I tried a few different things but I always end up either with a null value or with an error.
Is there any simple way to do what I need ?
<Point>data</Point>
– coolguy
Commented
Mar 6, 2013 at 11:51
You need to get the attributes. With javascript:
M[i].getAttribute("X");
with jQuery:
M[i].attr("X");
var M = xmlDoc.getElementsByTagName("Limits");
for (i = 0; i < M.length; i++){
for(var j = 0; j < M[i].childNodes.length; j++){
console.log(M[i].childNodes[j].getAttribute('X'));
console.log(M[i].childNodes[j].getAttribute('Y'));
}
}