FeatureInfoParser { public static FeatureCollection parseAsFeatureCollection( XMLStreamReader xmlReader, String csvLayerNames ) throws XMLStreamException { try { if ( ( xmlReader.getNamespaceURI() == null || xmlReader.getNamespaceURI().isEmpty() || xmlReader.getNamespaceURI().equals( "http: && xmlReader.getLocalName().equals( "FeatureInfoResponse" ) ) { return readESRICollection( xmlReader, csvLayerNames ); } if ( ( xmlReader.getNamespaceURI() == null || xmlReader.getNamespaceURI().isEmpty() ) && xmlReader.getLocalName().equals( "featureInfo" ) ) { return readMyWMSCollection( xmlReader ); } if ( ( xmlReader.getNamespaceURI() == null || xmlReader.getNamespaceURI().isEmpty() ) && xmlReader.getLocalName().equals( "msGMLOutput" ) ) { return readUMNCollection( xmlReader ); } return readGml2FeatureCollection( xmlReader ); } catch ( Exception e ) { String msg = "Unable to parse WMS GetFeatureInfo response as feature collection: " + e.getMessage(); throw new XMLStreamException( msg, e ); } }  static FeatureCollection parseAsFeatureCollection( XMLStreamReader xmlReader, String csvLayerNames );  }
@Test public void testEsriCollection() throws XMLStreamException { InputStream in = FeatureInfoParserTest.class.getResourceAsStream( "esri1.xml" ); XMLInputFactory fac = XMLInputFactory.newInstance(); XMLStreamReader xin = fac.createXMLStreamReader( in ); xin.next(); FeatureCollection fc = FeatureInfoParser.parseAsFeatureCollection( xin, "test" ); Assert.assertEquals( 1, fc.size() ); }
@Test public void testEmptyEsriCollection() throws XMLStreamException { InputStream in = FeatureInfoParserTest.class.getResourceAsStream( "esri2.xml" ); XMLInputFactory fac = XMLInputFactory.newInstance(); XMLStreamReader xin = fac.createXMLStreamReader( in ); xin.next(); FeatureCollection fc = FeatureInfoParser.parseAsFeatureCollection( xin, "test" ); Assert.assertEquals( 0, fc.size() ); }
@Test public void testNamespacedEsriCollection() throws XMLStreamException { InputStream in = FeatureInfoParserTest.class.getResourceAsStream( "esriwithnamespace.xml" ); XMLInputFactory fac = XMLInputFactory.newInstance(); XMLStreamReader xin = fac.createXMLStreamReader( in ); xin.next(); FeatureCollection fc = FeatureInfoParser.parseAsFeatureCollection( xin, "test" ); Assert.assertEquals( 8, fc.size() ); }