I would like to read the German railway (DB Netze) network XML available at https://data.deutschebahn.com/dataset/data-streckennetz.html (file Streckennetz (Stand 11/2019))
I went according the example posted 3 years ago here: https://gis.stackexchange.com/questions/353860/read-gml-using-java.
I am however getting multiple messages in the console about XSD files not having been resolved, not only the Inspire ones, but also the GML ones and even the basic XML.XSD (http://www.w3.org/XML/1998/namespace).
How can I properly "register" the XSDs so that they are successfully resolved by geotools?
The executable:
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import org.eclipse.xsd.util.XSDSchemaLocationResolver;
import org.eclipse.xsd.util.XSDSchemaLocator;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.gml3.GMLConfiguration;
import org.geotools.xsd.Configuration;
import org.geotools.xsd.Parser;
import org.opengis.feature.simple.SimpleFeature;
public class Loader {
public static void main(String[] args) throws Exception {
Configuration configuration = new GMLConfiguration();
File initialFile = new File("DB-Netz_INSPIRE_20200217.xml");
InputStream in = new FileInputStream(initialFile);
Parser parser = new Parser(configuration);
SimpleFeatureCollection fc = (SimpleFeatureCollection) parser.parse(in);
SimpleFeatureIterator iterator = fc.features();
try {
while (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
System.out.println("Feature ID: " + feature.getID());
}
} finally {
iterator.close();
}
}
}
The whole console log output looks as follows:
Jun 05, 2023 3:21:12 PM org.geotools.xsd.impl.HTTPURIHandler getConnection
INFO: inspire.ec.europa.eu/schemas/tn-ra/3.0/RailwayTransportNetwork.xsd
Jun 05, 2023 3:21:15 PM org.geotools.xsd.impl.HTTPURIHandler getConnection
INFO: schemas.opengis.net/wfs/2.0/wfs.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.impl.HTTPURIHandler getConnection
INFO: schemas.opengis.net/gml/3.2.1/gml.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.impl.HTTPURIHandler getConnection
INFO: schemas.opengis.net/iso/19139/20070417/gco/gco.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.impl.HTTPURIHandler getConnection
INFO: schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.impl.HTTPURIHandler getConnection
INFO: inspire.ec.europa.eu/schemas/base/3.2/BaseTypes.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.impl.HTTPURIHandler getConnection
INFO: inspire.ec.europa.eu/schemas/gn/3.0/GeographicalNames.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.impl.HTTPURIHandler getConnection
INFO: inspire.ec.europa.eu/schemas/net/3.2/Network.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.impl.HTTPURIHandler getConnection
INFO: inspire.ec.europa.eu/schemas/tn/3.0/CommonTransportElements.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.impl.HTTPURIHandler getConnection
INFO: inspire.ec.europa.eu/schemas/tn-ro/3.0/RoadTransportNetwork.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:Network:3.2 declared location: inspire.ec.europa.eu/schemas/net/3.2/Network.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:CommonTransportElements:3.0 declared location: inspire.ec.europa.eu/schemas/tn/3.0/CommonTransportElements.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:RoadTransportNetwork:3.0 declared location: inspire.ec.europa.eu/schemas/tn-ro/3.0/RoadTransportNetwork.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.opengis.net/gml/3.2 declared location: schemas.opengis.net/gml/3.2.1/gml.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.w3.org/XML/1998/namespace declared location: www.w3.org/2001/xml.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.opengis.net/ows/1.1 declared location: schemas.opengis.net/ows/1.1.0/owsAll.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.opengis.net/fes/2.0 declared location: schemas.opengis.net/filter/2.0/filterAll.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.isotc211.org/2005/gmd declared location: schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.opengis.net/gml/3.2 declared location: schemas.opengis.net/gml/3.2.1/gml.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:BaseTypes:3.2 declared location: inspire.ec.europa.eu/schemas/base/3.2/BaseTypes.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.opengis.net/gml/3.2 declared location: schemas.opengis.net/gml/3.2.1/gml.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.isotc211.org/2005/gmd declared location: schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.opengis.net/gml/3.2 declared location: schemas.opengis.net/gml/3.2.1/gml.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:BaseTypes:3.2 declared location: inspire.ec.europa.eu/schemas/base/3.2/BaseTypes.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:GeographicalNames:3.0 declared location: inspire.ec.europa.eu/schemas/gn/3.0/GeographicalNames.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:BaseTypes:3.2 declared location: inspire.ec.europa.eu/schemas/base/3.2/BaseTypes.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:Network:3.2 declared location: inspire.ec.europa.eu/schemas/net/3.2/Network.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.opengis.net/gml/3.2 declared location: schemas.opengis.net/gml/3.2.1/gml.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:GeographicalNames:3.0 declared location: inspire.ec.europa.eu/schemas/gn/3.0/GeographicalNames.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.isotc211.org/2005/gmd declared location: schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:GeographicalNames:3.0 declared location: inspire.ec.europa.eu/schemas/gn/3.0/GeographicalNames.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:CommonTransportElements:3.0 declared location: inspire.ec.europa.eu/schemas/tn/3.0/CommonTransportElements.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: urn:x-inspire:specification:gmlas:Network:3.2 declared location: inspire.ec.europa.eu/schemas/net/3.2/Network.xsd
Jun 05, 2023 3:21:16 PM org.geotools.xsd.Schemas getImports
INFO: Schema import wasn't resolved: www.opengis.net/gml/3.2 declared location: schemas.opengis.net/gml/3.2.1/gml.xsd
Exception in thread "main" java.lang.ClassCastException: java.util.HashMap cannot be cast to org.geotools.data.simple.SimpleFeatureCollection
I tried different versions of geotools, I tried to download XSDs and resolve them locally from file system, which succeeded to a certain level, but 1) it seems to be a dirty hack, 2) it did not resolve the problem with http://www.w3.org/2001/xml.xsd
P.S. (Moved from answer by editor):
Please note that I had to edit the log messages due to https://meta.stackexchange.com/a/209517/1374413
I had to strip all http://
and https://
prefixes so that my question is not considered as spam.