I would like to control if my GML file is valid with my actual XSD using GeoTools.
I found something here: GML2 Parsing TestSchema Example. But I don't know if it's a good way to do what I want.
Configuration configuration = new org.geotools.gml3.GMLConfiguration();
Parser parser = new org.geotools.xsd.Parser(configuration);
//the xml instance document above
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream xsd = classloader.getResourceAsStream("gml/config.xsd");
int i =0;
//parse
SimpleFeatureCollection fc = (SimpleFeatureCollection) parser.parse(xsd);
fc.accepts( new AbstractFeatureVisitor(){
public void visit( Feature feature ) {
SimpleFeature f = (Feature) i.next();
Point point = (Point) f.getDefaultGeometry();
String name = (String) f.getAttribute( "name" );
}
}, new NullProgressListener() );
In my code I don't know where I can specify my GML file for validation.