Reputation: 71
I have an xml document that returns a list of map markers.
<markers>
<marker name="Marker 1 name" theid="100">
<content>Text goes here</content>
</marker>
<marker name="Marker 2 name" theid="101">
<content>Other text goes here</content>
</marker>
...
</markers>
I have some javascript to read through the list of markers and it successfully returns their attributes as variables like name
and theid
.
<script>
...
var xml = parseXml(data);
var markerNodes = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markerNodes.length; i++) {
var name = markerNodes[i].getAttribute("name");
var theid = markerNodes[i].getAttribute("theid");
var content = markerNodes[i].getElementsByTagName("content");
...
</script>
However I cannot get the javascript to return the contents of the element tag content
. In place of the text content I get the message [object HTMLCollection]
. Would anyone be kind enough to help me fix this please?
Upvotes: 4
Views: 3790
Reputation: 71
The bit I was missing was textContent:
var content = markerNodes[i].getElementsByTagName("content")[0].textContent;
Upvotes: 2