I have an XML file with the following structure (this structure repeats):
<File>
<scanRange>0,887</scanRange>
<name>HARMONY __050.DZT</name>
<Profile>
<scanRange>0,887</scanRange>
<Comment>
<scan>0</scan>
<description>Data Collection Notes: </description>
</Comment>
<WayPt>
<scan>0</scan>
<mark>User</mark>
<name>Mark2</name>
<distance>0.0000000</distance>
<localCoords>0.0000000,0.5000000,0.0000000</localCoords>
</WayPt>
<WayPt>
<scan>887</scan>
<distance>18.000000</distance>
<localCoords>18.000000,0.5000000,0.0000000</localCoords>
</WayPt>
</Profile>
</File>
What I need to get are the name of the file, the distance and localCoords into a table. But what I have right now combines the duplicate entries together.
$(document).ready(function() {
$("#XML").append('<table><tr><th>File</th><th>Distance</th> <th>LocalCoords</th>');
$.ajax({
type: "GET",
url: "HARMONY01.DZX",
dataType: "xml",
success: function(xmlData) {
$("File", xmlData).each(function() {
var name = $(this).find("name").text(),
distance = $(this).find("distance").text(),
localCoords = $(this).find("localCoords").text();
$("#XML").append('<tr>');
$("#XML").append('<td class="name">' + name + '</td>');
$("#XML").append('<td class="Distance">' + distance + '</td>');
$("#XML").append('<td class="localCoords">' + localCoords + '</td>');
$("#XML").append('</tr>');
});
}
});
$("#XML").append('</table>');
});
I also tried this:
var name1 = $(this).find("name").text(),
name2 = $(this).find("name").text(),
distance1 = $(this).find("distance").text(),
distance2 = $(this).find("distance").text(),
localCoords1 = $(this).find("localCoords").text();
localCoords2 = $(this).find("localCoords").text();
$("#XML").append('<tr>');
$("#XML").append('<td class="name">'+name1+'</td>');
$("#XML").append('<td class="Distance">'+distance1+'</td>');
$("#XML").append('<td class="localCoords">'+localCoords1+'</td>');
$("#XML").append('<td class="Distance">'+distance2+'</td>');
$("#XML").append('<td class="localCoords">'+localCoords2+'</td>');
$("#XML").append('</tr>');
but it just duplicated the same thing.
What would be even better, would have the localCoords field broken into three sub-columns of values.
Can anyone lend a hand on this issue? Much appreciated.