je veux valider un fichier xml avec un xsd
le problème que mon xsd fait appel à d'autres fichiers xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:ean.ucc:2">
<xsd:include schemaLocation="ean.ucc/common/ApplicationReceiptAcknowledgement.xsd"/>
</xsd:schema>
je ne sais pas quel schéma (path) doit prendre ma méthode pour parcourir tous les fichiers xsd:
public static Vector validateXML(String xmlMessage,String path) {
final Vector errorsList = new Vector();
File f=new File(xmlMessage);
try{
FileInputStream is = new FileInputStream(f);
byte[] attBody = new byte[is.available()];
is.read(attBody);
String msg = new String(attBody);
InputStream IS = null;
try {
System.out.println("okkk" );
IS = new java.io.ByteArrayInputStream(msg.getBytes("UTF-8" ));
} catch (UnsupportedEncodingException e1) {e1.printStackTrace();}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringComments(true);
dbf.setNamespaceAware(true);
dbf.setValidating(true);
System.out.println("okkk2" );
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
SAXParser saxParser = null;
try {
System.out.println("okkk3" );
saxParser = factory.newSAXParser();
try {
System.out.println("okkk4" );
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
saxParser.setProperty(JAXP_SCHEMA_SOURCE, path);
} catch (SAXNotRecognizedException e) {} catch (SAXNotSupportedException e) {}
} catch (ParserConfigurationException e1) {e1.printStackTrace();
} catch (SAXException e1) {e1.printStackTrace();}
try {
System.out.println("okkk5" );
saxParser.parse(IS, new DefaultHandler(){
public void fatalError(SAXParseException e) {
errorsList.add("E516"+e.getMessage()+"" );
System.out.println("okkk" );
System.out.println(e.getMessage());
isValid=false;
}
public void error(SAXParseException e) {
errorsList.add("E516"+e.getMessage()+"" );
System.out.println("okkk1111" );
System.out.println(e.getMessage());
isValid=false;
}
public void warning(SAXParseException e) {
errorsList.add("E516"+e.getMessage()+"" );
System.out.println("okkk22222222222" );
System.out.println(e.getMessage());
isValid=false;
}
});
} catch (IOException ioe) {
System.out.println(ioe);
} catch (SAXException saxe) {
System.out.println(saxe);
isValid=false;}
/*}
else
{errorsList.add("E514"+""+"" );}*/
/*}
else {System.out.println("E515 jok" );errorsList.add(new gdpError("E515","","" ));}
*/
}catch(Exception e){System.out.println(e.getMessage());}
System.out.println(isValid);
return errorsList;
}
j'éspère que j'étais claire.