I'm using AJAX to load an XML file in to a HTML div. My XML looks like this:
<Incidents>
<Incident id="123">
<ModTime>2016-01-23T08:00:00Z</ModTime>
<comments>comments here</comments>
<currentUpdate>update</currentUpdate>
<status>Active</status>
</incident>
<Incidents>
<Incident id="456">
<ModTime>2016-01-23T08:00:00Z</ModTime>
<comments>comments here</comments>
<currentUpdate>update</currentUpdate>
<status>Active</status>
</incident>
//<![CDATA[
$.ajax({
type: "GET",
url: "feed.xml",
dataType: "xml",
success: function(xml) {
$('#table').append('<h2>XML</h2>');
$('#table').append('<table id="show_table" border="1" >');
$(xml).find('Incident').each(function() {
var $feed = $(this);
var id = $feed.attr("id");
var mod = $feed.find('ModTime').text();
var comments = $feed.find('comments').text();
var update = $feed.find('currentUpdate').text();
var status = $feed.find('status').text();
var html = ' <tr><td >' + id + '</td><td >' + mod + '<br>' + comments + '</td><td>' + update + '</td><td>' + status +'</td><td > </tr>';
$('#show_table').append(html);
});
}
});
Which works fine most of the time, however sometimes incidents in the XML will have two comment sections.
<Incidents>
<Incident id="123">
<ModTime>2016-01-23T08:00:00Z</ModTime>
<comments>comments here</comments>
<currentUpdate>update</currentUpdate>
<status>Active</status>
</incident>
<Incidents>
<Incident id="456">
<ModTime>2016-01-23T08:00:00Z</ModTime>
<comments>comments here</comments>
<comments>comments another comment</comments>
<currentUpdate>update</currentUpdate>
<status>Active</status>
</incident>
When that happens I want to separate them out but I can't work out how?
I first tried adding a line break in the table but realized that was too late as I'd already got the data.
I then tried adding the break when I find the comments but that also didn't work - it just added a break at the end of the
var comments = $feed.find('comments').text() + '<br>';