Jesus Loves GRASS

Technical blog about GRASS/GIS,open source geoinformatics and MAPSERVER.

Sunday, June 10, 2007

XML parse problem with getElementsByTagName()

Today a college checked the WebGIS and she noticed the WCS request was not working. With me everything was fine but not with her, the difference is that I use Firefox while she is on IE6

So I have discovered that there is a problem parsing the XML of the describeCoverage request of the WCS.

I was using something like this to get the pixel resolution from the offsetVector information of the XML reply

var RESnode=xmldoc.getElementsByTagName("offsetVector");
var sRESX=RESnode[0].firstChild.nodeValue;
var RESX=sRESX.split(" "); //array with resx in this case the first value is the important one
var sRESY=RESnode[1].firstChild.nodeValue;
var RESY=sRESY.split(" ");

This gets the X,Y resolution of the image using FireFox

The problem is that tag offsetVector is in reality gml:offsetVector, as the specification of the WCS is to include the type of XML structure, well FireFox doesn't care about anything before the :

I have found a simple solution in this blog:
http://learningremix.net/w2007integ/jeff/2007/03/re_problem_related_to_parsing_xml.shtml

So in case the XML reply is empty I am using another tag name:

var RESnode=xmldoc.getElementsByTagName("offsetVector");
if (RESnode.length == 0) {
var RESnode = xmldoc.getElementsByTagName("gml:offsetVector");
}
var sRESX=RESnode[0].firstChild.nodeValue;
var RESX=sRESX.split(" "); //array with resx in this case the first value is the important one
var sRESY=RESnode[1].firstChild.nodeValue;
var RESY=sRESY.split(" ");

PROBLEM SOLVED !!!

Labels: , , , , ,

0 Comments:

Post a Comment

<< Home