probleme de validation xml/xsl
Bonjour,
J'ai un probleme pour valider une xml avec une xsd en java. Mon fichier xsd est imposé c'est le xml quil faut modifier. Voici son entête :
Code:
1 2 3 4
| <?xml version="1.0" encoding="ISO-8859-1"?>
<!-- edited with XMLSpy v2005 rel. 3 U (<a href="http://www.altova.com" target="_blank">http://www.altova.com</a>) by XXXXXXXXX -->
<?xml-stylesheet href="config_gpm.xsl" type="text/xsl"?>
<gpm xmlns="D:\xmlChecker\instantiation_scema.xsd" > |
L'erreur est la suivante :
cvc-elt.1: Cannot find the declaration of element 'gpm'.
(si je met juste <gpm> sans ses attributs c'est pareil)
Comme s'il ne trouvait pas la XSD, pourtant je l'indique en java et c'est le bon chemin.
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| public int XMLValidation(String pXmlPath) {
File lFichierXml;
DocumentBuilderFactory lDbf;
DocumentBuilder lDb;
if (fichierXsd == null) {
throw new NullPointerException();
}
else {
lFichierXml = new File(pXmlPath);
//Chargement du fichier d'instanciation en mémoire puis enregistrement temporaire sur le disque
//apres suppression des URI relatives au fichier XSD, de maniere a n'utiliser que le schema donné dans le fichier de conf
Document lDoc = XmlUtils.recupererDocument(pXmlPath);
if (lFichierXml.exists()) {
lDbf = DocumentBuilderFactory.newInstance();
lDbf.setValidating(true);
lDbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
lDbf.setAttribute(JAXP_SCHEMA_SOURCE, fichierXsd);
Node lSL = XmlUtils.getNode(lDoc, "/gpm").getAttributes().getNamedItem("xsi:schemaLocation");
//Je vide les valeur des attributs du tag gpm mais ca change rien.
if(lSL != null){
lSL.setNodeValue("");
}
Node lX = XmlUtils.getNode(lDoc, "/gpm").getAttributes().getNamedItem("xmlns:xsi");
if(lX != null){
lX.setNodeValue("");
}
String lFile = SaveDoc(lDoc);
try {
lDb = lDbf.newDocumentBuilder();
lDb.setErrorHandler(errorHandler);
lDb.parse(lFile);
if (errorHandler.isError()) {
throw new AdmExceptionErreurValidationXSD(
"Le fichier généré n'est pas un fichier gPM valide"
+ System.getProperty("line.separator")
+ "Vérifier que le fichier de transformation xsl est correct");
}
}
catch (ParserConfigurationException lPce) {
log.message("XMLValidation : " + lPce);
return 2;
}
catch (IOException lIoe) {
log.message("XMLValisation : " + lIoe);
return 2;
}
catch (SAXException lSae) {
log.message("XMLVAlidation : " + lSae);
return 2;
}
log.message("Le fichier XML a été validé par la XSD avec succes");
File lF = new File(lFile);
if(lF.exists()){
lF.delete();
}
}
else {
throw new FichierManquantException("Le fichier xml "
+ pXmlPath + " n'existe pas");
}
}
return 0;
} |
Si quelqu'un peut m'expliquer ce qui ne va pas.... merci.