I tried to make a validator of XML in java, having the schema XSD. The beginning of my file.xml
<?xml version="1.0" encoding="UTF-8"?>
<Dataset xmlns:dc="http://purl.org/dc/terms/" xmlns:dwc="http://rs.tdwg.org/dwc/terms/" xmlns:tcs="http://www.tdwg.org/schemas/tcs/1.01" xmlns:eol="http://www.eol.org/transfer/content/0.3" xmlns:gisin="http://www.gisin.org/gisin/SpeciesStatus" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="AbstractModel.xsd">
<Metadata>...
The schema AbstractModel.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:plic="http://www.gbif.es/PliC/" xmlns:dc="http://purl.org/dc/terms/" xmlns:dcelem="http://purl.org/dc/elements/1.1/" xmlns:dwc="http://rs.tdwg.org/dwc/terms/" xmlns:abcd="http://www.tdwg.org/schemas/abcd/2.06" xmlns:tcs="http://www.tdwg.org/schemas/tcs/1.01" xmlns:simple="http://rs.tdwg.org/dwc/xsd/simpledarwincore/" xmlns:gisin="http://www.gisin.org/gisin/SpeciesStatus" xmlns:eol="http://www.eol.org/transfer/content/0.3" xmlns:eml="eml://ecoinformatics.org/eml-2.1.1" xmlns:sql="urn:schemas-microsoft-com:mapping-schema" xmlns:ns1="https://github.com/tdwg/dwc/tree/master/xsd">
<xs:import namespace="http://www.tdwg.org/schemas/abcd/2.06" schemaLocation="http://rs.tdwg.org/abcd/2.06/ABCD_2.06.xsd"/>
<xs:import namespace="http://www.tdwg.org/schemas/tcs/1.01" schemaLocation="http://www.tdwg.org/uploads/media/v101.xsd"/>
<xs:import namespace="http://www.gisin.org/gisin/SpeciesStatus" schemaLocation="http://www.gisin.org/GISIN/SpeciesStatus_4_0_0.xsd"/>
<xs:import namespace="http://rs.tdwg.org/dwc/terms/" schemaLocation="tdwg_dwc_extensions.xsd"/>
<xs:import namespace="eml://ecoinformatics.org/eml-2.1.1" schemaLocation="eml.xsd"/>
<xs:import namespace="http://www.eol.org/transfer/content/0.3" schemaLocation="content_0_3.xsd"/>
<xs:import namespace="http://purl.org/dc/terms/" schemaLocation="http://dublincore.org/schemas/xmls/qdc/dcterms.xsd"/>
<xs:import namespace="http://purl.org/dc/elements/1.1/" schemaLocation="http://dublincore.org/schemas/xmls/qdc/dc.xsd"/>
<xs:element name="Dataset">
<xs:annotation>.......
First I followed some examples on internet to make a simple validator class using Java API for XML
public static void validate(String xsdPath, String xmlPath){
try{
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new File(xsdPath));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new File(xmlPath)));
} catch (IOException | SAXException e){
System.out.println("Exception: "+e.getMessage());
}
}
I had read, for read imported XSD is necessary use LSResourceResolver and LSInput, but I don't have an idea how implement theses classes with several XSD's imported. Is possible to do this kind of validation using Java? Is more convenient use some library?
I don't get how I should use the possible answer :Validate an XML against an XSD in Java / Getting a hold of the schemaLocation in my particular problem. For instance, I have a class ResourceResolver that implements LSResourceResolver, but, according to the answer, the constructor of this class need two arguments public ResourceResolver(URL base, Map<URI, String> nsmap)
I don't know from which class or variable, I should pass these values.