I have a handler which returns me a XML Request as an alert() with the following
<?xml version="1.0" encoding="UTF-8"?>
<gml:TimePeriod xmlns:gml="http://www.opengis.net/gml">
<gml:beginPosition>2011-10-18T15:15:00.000+02:00</gml:beginPosition>
<gml:endPosition>2014-11-23T14:45:00.000+01:00</gml:endPosition>
</gml:TimePeriod>
The handler looks like that:
function handler(request) {
alert(request.responseText);
};
Now I would like parse the xml tag “beginPosition” to an array. I used the following code within the handler:
function handler(request) {
alert(request.responseText);
var xmlDoc = request.responseXML;
timeArray = xmlDoc.getElementByTagName('beginPosition').value= new Date(request.responseText).toTimeString();
console.log(timeArray);
};
var timeArray;
alert(timeArray);
Finally I got the error message: TypeError: xmlDoc.getElementByTagName is not a function
How can I parse the date value in that array from the xml request?
You can have more than one element of a given tag name in a document, so the method you are looking for is
getElementsByTagName
(plural) which returns a NodeList (which is like an array).