[Xerces] pb de validation xml avec un schema stocké dans un jar
Salut à tous,
je sais que cela revient souvent mais j'utilise Xerces pour valider un xml avec mon schema stocké dans un jar.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
URL xsdURL = Thread.currentThread().getContextClassLoader().getResource( "config/maven-dashboard-config.xsd" );
try
{
InputSource xmlFile = new InputSource( new FileInputStream( this.configfile ) );
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringComments(true);
dbf.setNamespaceAware(true);
dbf.setValidating(true);
dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
dbf.setAttribute(JAXP_SCHEMA_SOURCE, new File(xsdURL.getFile()));
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(new MyDefaultHandler() );
Document doc = db.parse(xmlFile);
}
catch ( SAXException e )
{
isValidXSD = false;
e.printStackTrace();
}
catch ( IOException e )
{
isValidXSD = false;
e.printStackTrace();
}
catch ( ParserConfigurationException e )
{
isValidXSD = false;
e.printStackTrace();
} |
ça ne fonctionne pas , j'ai l'erreur suivante :
Code:
1 2 3 4 5 6
|
Error Line 3: schema_reference.4: Failed to read schema document 'file:\C:\PIC\maven-repo-sonate5\org\codehaus\mojo\dashboarddb-maven-plugin\1.0-SNAPSHOT\dashboarddb-maven-plugin-1.0-SNAPSHOT.jar!\config\maven-dashboard-config.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
Error Line 3: schema_reference.4: Failed to read schema document 'null', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
Error Line 3: cvc-elt.1: Cannot find the declaration of element 'configuration'. |
par contre si je remplace :
Code:
1 2
|
dbf.setAttribute(JAXP_SCHEMA_SOURCE, new File(xsdURL.getFile())); |
par un accés en dur sur mon schema (sur mon disque)
Code:
1 2
|
dbf.setAttribute(JAXP_SCHEMA_SOURCE, new File("F:\\projects\\dashdb-maven-plugin\\src\\main\\resources\\config\\maven-dashboard-config.xsd")); |
là ça marche nickel !!!
Quelqu'un a-t'il pu résoudre ce souci, sachant que mon xsd doit être obligatoirement dans mon jar ?
merci d'avance