Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to parse WFS reponse using OpenLayers.Format.GML parser. However, an exception thrown in my try-catch block is TypeError: a is undefined.

protocol = new OpenLayers.Protocol.WFS({
    version: "1.1.0",
    url: WFS_HOST,
    featureType: "pl",
    featureNS: "ws",
    srsName: "EPSG:900913"
});

wfsLayer = new OpenLayers.Layer.Vector("PE Vector", {
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: protocol
});

var _Callback = function(resp) {
    console.log(resp);
    console.log(resp.error);

    try {
        var gmlParser = new OpenLayers.Format.GML();
        gmlParser.extractAttributes = true;
        var features = gmlParser.read(resp.responseText);

        if(features){
            for(var i = 0; i < features.length; i++) {
                var feature = features[i];
                                    // More operations
            }
        }
    } catch(e) {
        alert("Error: " + e);
    }
};

response = protocol.read({
    maxFeatures: 100,
    callback: _Callback
});

My environment: GeoServer 2.1.3, OpenLayers 2.11, PostGIS 1.5.

share|improve this question
up vote 1 down vote accepted

I got it working by updating the _Callback variable to:

var _Callback = function(resp) {
    console.log(resp);
    console.log(resp.error);

    try {
        var gmlParser = new OpenLayers.Format.GML.v3();
        gmlParser.extractAttributes = true;
        var features = gmlParser.read(resp.priv.responseXML);

        if(features){
            for(var i = 0; i < features.length; i++) {
                var feature = features[i];
                // TODO: More operations
            }
        }
    } catch(e) {
        alert("Error: " + e);
    }
};
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.