I hope someone can help me. I'm using geotools to parse gml v.2 (below is a snippet) to extract the point and its annotation.
<osgb:FeatureCollection xmlns:osgb="http://www.ordnancesurvey.co.uk/xml/namespaces/osgb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.ordnancesurvey.co.uk/xml/namespaces/osgb http://www.ordnancesurvey.co.uk/xml/schema/v6/OSDNFFeatures.xsd"> <gml:boundedBy> <gml:null>unknown</gml:null> </gml:boundedBy> <osgb:queryTime>2008-09-17T15:33:53</osgb:queryTime> <osgb:cartographicMember> <osgb:CartographicSymbol fid="osgb1000001593686200"> <osgb:featureCode>10066</osgb:featureCode> <osgb:version>3</osgb:version> <osgb:versionDate>2008-05-21</osgb:versionDate> <osgb:theme>Terrain And Height</osgb:theme> <osgb:changeHistory> <osgb:changeDate>1990-12-20</osgb:changeDate> <osgb:reasonForChange>New</osgb:reasonForChange> </osgb:changeHistory> <osgb:changeHistory> <osgb:changeDate>2005-06-07</osgb:changeDate> <osgb:reasonForChange>Position</osgb:reasonForChange> </osgb:changeHistory> <osgb:changeHistory> <osgb:changeDate>2008-05-20</osgb:changeDate> <osgb:reasonForChange>Attributes</osgb:reasonForChange> </osgb:changeHistory> <osgb:descriptiveGroup>Height Control</osgb:descriptiveGroup> <osgb:descriptiveTerm>Bench Mark</osgb:descriptiveTerm> <osgb:orientation>2194</osgb:orientation> <osgb:physicalLevel>50</osgb:physicalLevel> <osgb:point> <gml:Point srsName="osgb:BNG"> <gml:coordinates>551974.51,256270.77</gml:coordinates> </gml:Point> </osgb:point> </osgb:CartographicSymbol> </osgb:cartographicMember> I follow the manual (http://docs.codehaus.org/display/GEOTDOC/GML+XML+Support) to compile and run with the code (snippet) below. //create the parser with the gml 2.0 configuration Configuration configuration = new GMLConfiguration(); Parser parser = new Parser(configuration); //the xml instance document above InputStream xml = new FileInputStream(c:/tmp/test.gml) //parse FeatureCollection fc = (FeatureCollection) parser.parse(xml); for ( Iterator i = fc.iterator(); i.hasNext();) { Feature f = (Feature) i.next(); Point point = (Point) f.getDefaultGeometry(); String name = (String) f.getAttribute("toString"); System.out.println("Coordinate: " + point); System.out.println("Location Name: " + name); } It occurs the error during execution time like this, org.geotools.xml.impl.ParserHandler startElement WARNING:Error parsing: http://www.ordnancesurvey.co.uk/xml/schema/v6/OSDNFFeatures.xsd org.geotools.xml.impl.ParserHandler startElement WARNING:Could not find a schema org.geotools.xml.impl.ParserHandler startElement INFO:Could not find declaration for: {http://www.ordnancesurvey.co.uk/xml/namespaces/osgb}FeatureCollection. Creating a mock element declaration and parsing anyways... org.geotools.xml.impl.ParserHandler startElement INFO:Could not find declaration for: {http://www.ordnancesurvey.co.uk/xml/namespaces/osgb}queryTime. Creating a mock element declaration and parsing anyways... .... .... Then, I read the manual for the problem with Application Schema Support and change some code below String namespace = "http://www.ordnancesurvey.co.uk/xml/namespaces/osgb"; String schemaLocation = "http://www.ordnancesurvey.co.uk/xml/schema/v6/OSDNFFeatures.xsd"; try { Configuration configuration = new ApplicationSchemaConfiguration(namespacee, schemaLocation); Parser parser = new Parser(configuration); InputStream xml = new FileInputStream(c:/tmp/test.gml); FeatureCollection fc = (FeatureCollection) parser.parse(xml); for ( Iterator i = fc.iterator(); i.hasNext();) { Feature f = (Feature) i.next(); Point point = (Point) f.getDefaultGeometry(); String name = (String) f.getAttribute("textString"); System.out.println("Coordinate: " + point); System.out.println("Location Name: " + name); } } ... ... Another error code occurs during execution time below: java.lang.NullPointerException at org.eclipse.emf.common.util.URI.createURIWithCache(URI.java:655) at org.eclipse.emf.common.util.URI.createURI(URI.java:535) at org.eclipse.xsd.impl.XSDSchemaDirectiveImpl.resolve(XSDSchemaDirectiveImpl.java:343) at org.eclipse.xsd.impl.XSDIncludeImpl.patch(XSDIncludeImpl.java:233) at org.eclipse.xsd.impl.XSDConcreteComponentImpl.patch(XSDConcreteComponentImpl.java:526) at org.eclipse.xsd.impl.XSDSchemaImpl.patch(XSDSchemaImpl.java:1505) at org.eclipse.xsd.impl.XSDSchemaImpl.changeAttribute(XSDSchemaImpl.java:2335) at org.eclipse.xsd.impl.XSDConcreteComponentImpl.eNotify(XSDConcreteComponentImpl.java:1240) at org.eclipse.xsd.impl.XSDSchemaImpl.setSchemaLocation(XSDSchemaImpl.java:829) at org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl.java:756) at org.eclipse.xsd.util.XSDResourceImpl.doLoad(XSDResourceImpl.java:784) at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1094) at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:900) at org.geotools.xml.Schemas.parse(Schemas.java:247) at org.geotools.xml.XSD.buildSchema(XSD.java:170) at org.geotools.xml.XSD.getSchema(XSD.java:127) at org.geotools.xml.SchemaLocator.locateSchema(SchemaLocator.java:92) ..... ..... I am using geotools v.2.5.0. Please help me why the errors still occur during parsing. Thank you, Wichai ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
