Jesus Loves GRASS

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

Thursday, September 20, 2007

Junk after XML (0 at the end of reply)

I am finally back to programming and I am currently working in providing Web Processing Service.

I started to use PyWPS implementation for it (it is very well done, complements to Jachym Cepicky) but PyWPS runs as a CGI script and not from inside mod_python, the possibility of running it using the cgihandler from mod_python is a limited option.....

So I am making a new version of PyWPS crafted to my needs, I managed to get a Request=GetCapabilities working, but I got stuck with this error:

XML Parsing Error: junk after document element
Location: http://localhost/test/wps/wps2.py/main?version=0.4.0&Request=GetCapabilities
Line Number 104, Column 1:0
^
0

Well it seems there is an "extra" after the XML document, the problem is related to the req object of mod_python and how the HTTP is processed.

This 0 indicates that there is no more HTTP chunks (more or less EOF).

To disable chunked encoding, it is necessary to specify content length:

req.send_http_header()
req.content_type = 'text/xml'
req.set_content_length(len(getCapabilities.document.toprettyxml()))
req.write(getCapabilities.document.toprettyxml())
return apache.OK

The getCapabilities.document.toprettyxml() creates my XML document that then is checked for lenght, after it will be flushed with req.write

Labels: , , , , ,

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: , , , , ,

Friday, May 18, 2007

WFS XML verbose to Array structure

I was expecting for the WFS reply to be more "friendly" meaning the Mapserver dump in GML to be easily openned by other programs like ArcGIS. But is not the case....since my supervisor wants the results to be in CSV I have to send sometime on it.

Meanwhile I have a nice way of concerting the mapserver WFS reply to an array structure using PHP XML Parser (I should have used the XML-DOM parser but it was a bit to advanced..., also I couldn't find any nice class to deal with it in the website php classes)

(programming requesting the WFS layer)

$buffer = ms_iogetstdoutbufferstring();
ms_ioresethandlers();

//creation of the values and keys containing the DescribeFeatureType or GetFeature
$xp = xml_parser_create();
xml_parse_into_struct($xp,$buffer,$values_meta,$keys_meta);
xml_parser_free($xp);

//dumping all the array structure for checking
echo "Keys array_meta<br><br><pre>";
print_r($keys_data);
echo "</pre><br><br>Values array_meta<br><br><pre>";
print_r($values_data);
echo "</pre>";

The example is from the book "Beginning PHP5" and it was the simplest way I found to pass everything to arrays

Labels: , , , ,