Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm getting a following XML response:

<wfs:FeatureCollection xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:Alexandria="http://www.opengeo.org/alexandria" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengeo.org/alexandria http://localhost:8080/geoserver/wfs?service=WFS&version=1.0.0&request=DescribeFeatureType&typeName=Alexandria%3ALink http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd"> <gml:boundedBy> <gml:null>unknown</gml:null> </gml:boundedBy> <gml:featureMember> <Alexandria:Link fid="Link.3606"> <Alexandria:link>10011</Alexandria:link> <Alexandria:street>MetroRail</Alexandria:street> <Alexandria:anode>7809</Alexandria:anode> <Alexandria:bnode>7810</Alexandria:bnode> <Alexandria:length>5900.0</Alexandria:length> <Alexandria:setback_a>7.5</Alexandria:setback_a> <Alexandria:setback_b>7.5</Alexandria:setback_b> <Alexandria:bearing_a>258</Alexandria:bearing_a> <Alexandria:bearing_b>264</Alexandria:bearing_b> <Alexandria:type>HEAVYRAIL</Alexandria:type> <Alexandria:lanes_ab>1</Alexandria:lanes_ab> <Alexandria:left_ab>0</Alexandria:left_ab> <Alexandria:right_ab>0</Alexandria:right_ab> <Alexandria:speed_ab>24.0</Alexandria:speed_ab> <Alexandria:fspd_ab>15.0</Alexandria:fspd_ab> <Alexandria:cap_ab>800</Alexandria:cap_ab> <Alexandria:lanes_ba>1</Alexandria:lanes_ba> <Alexandria:left_ba>0</Alexandria:left_ba> <Alexandria:right_ba>0</Alexandria:right_ba> <Alexandria:speed_ba>24.0</Alexandria:speed_ba> <Alexandria:fspd_ba>15.0</Alexandria:fspd_ba> <Alexandria:cap_ba>800</Alexandria:cap_ba> <Alexandria:use>RAIL</Alexandria:use> <Alexandria:notes>Network Link</Alexandria:notes> <Alexandria:the_geom> <gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#26918"> <gml:lineStringMember> <gml:LineString> <gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" "> 320695.41213026,4297152.0969028 320640.19318712,4297139.92142997 320587.60391463,4297132.73849488 320507.99922226,4297125.6462426 320372.01896506,4297122.04868058 320139.61381536,4297133.2460428 319570.57549324,4297180.04088008 319077.50062411,4297238.93844794 318769.48314967,4297273.2403574 318384.07201306,4297311.44152552 318358.66079594,4297313.94256447 318010.3407805,4297343.94430273 317699.46222885,4297367.34752366 317497.16184099,4297366.53956364 317208.71190984,4297321.60207638 316919.31081203,4297234.0455083 316803.6568586,4297185.98240055 316572.93697881,4297064.62138347 316385.3476619,4296950.17015898 316099.77576633,4296847.2680627 315736.80626258,4296749.50396585 315523.91602008,4296708.32610939 315280.39092313,4296675.23725991 314961.76338186,4296641.82134139 </gml:coordinates> </gml:LineString> </gml:lineStringMember> <gml:lineStringMember> <gml:LineString> <gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" "> 314962.12893922,4296638.34050277 315280.80907687,4296671.76274009 315524.48397992,4296704.87389061 315737.59373742,4296746.09603415 316100.82423367,4296843.9319373 316386.8523381,4296947.02984102 316574.66302119,4297061.57861653 316805.1431414,4297182.81759945 316920.48918797,4297230.7544917 317209.48809016,4297318.19792362 317497.43815901,4297363.06043636 317699.33777115,4297363.85247634 318010.0592195,4297340.45569728 318358.33920406,4297310.45743553 318383.72798694,4297307.95847448 318769.11685033,4297269.7596426 319077.09937589,4297235.46155206 319570.22450676,4297176.55911992 320139.38618464,4297129.7539572 320371.98103494,4297118.55131942 320508.20077774,4297122.1537574 320587.99608537,4297129.26150512 320640.80681288,4297136.47857003 320696.1649725,4297148.67951847 </gml:coordinates> </gml:LineString> </gml:lineStringMember> </gml:MultiLineString> </Alexandria:the_geom> </Alexandria:Link> </gml:featureMember> </wfs:FeatureCollection>

This response is stored in a variable named response. I try to convert it into list of feature objects by the following code:

var features = new OpenLayers.Format.GML().read(response);

I get an empty array ([]) when I print features. Can anybody point me out what I'm doing wrong?

share|improve this question
    
could you use a WFS layer and then query the layer for the features? ian01.geog.psu.edu/geoserver/www/wfs/wfs-baselayer.js –  iant Nov 14 '12 at 13:52
    
@iant My aim is to highlight the feature as mentioned in the link using method 1 there. But thanks, I will look down on your method. –  Sibi Nov 14 '12 at 17:10

2 Answers 2

Try to use V3:

var format = new OpenLayers.Format.GML.v3();    
var features = format.read(response);

i hope it helps you...

share|improve this answer
    
Still I get an empty array. –  Sibi Nov 14 '12 at 12:15
    
do you have this service any place to test it? –  Aragon Nov 14 '12 at 12:19
    
No i don't have any service to test it. I'm printing the variable and it shows me a clean XML response from the server. But I'm not able to convert it to feature list. –  Sibi Nov 14 '12 at 12:29
up vote 0 down vote accepted

Things to do when error like this happen:

  1. Check that in the WFS request you are passing version parameter as version=1.0.0. Version 1.1.0 doesn't work for me.
  2. Check that the XML passed by the server as response is valid. This check can be easily carried out by pasting your XML content in this link.

In the above question, XML is not valid because of the presence of some unescaped ampersand (&) in the request parameter.

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.