Validation une instance XML avec schéma(plusieurs fichiers XSD)
Bonjour,
J'ai parcouru sur Internet pour la validation un fichier XML avec un schéma constituant des fichiers XSD en java: mais je n'ai rien trouvé, seulement la validation un XML contre un XSD simple. Il existe en C# des articles/API traités sur ce sujet mais aucun pour Java.
Données en entrée du problème:
- un fichier XML (instance) à valider.
- un schéma constituant des fichiers XSD dans un répertoire
J'ai essayé avec ceci mais il ne marche pas
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
|
public void validatorWithDom()
{
try
{
DocumentBuilderFactory documentFactory =
DocumentBuilderFactory.newInstance();
documentFactory.setValidating(false);
documentFactory.setNamespaceAware(true);
SchemaFactory schemaFactory =
SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
documentFactory.setSchema(schemaFactory.newSchema(
new Source[]
{
new StreamSource("C:/XmlSchemes/musiml_All.xsd"),
new StreamSource("C:/XmlSchemes/musiml_instance.xsd"),
new StreamSource("C:/XmlSchemes/Generic/musiml_container.xsd"),
new StreamSource("C:/XmlSchemes/Generic/musiml_curve.xsd"),
new StreamSource("C:/XmlSchemes/Generic/musiml_enum.xsd"),
new StreamSource("C:/XmlSchemes/Generic/musiml_error.xsd"),
new StreamSource("C:/XmlSchemes/Generic/musiml_generic.xsd"),
new StreamSource("C:/XmlSchemes/Generic/musiml_main.xsd"),
new StreamSource("C:/XmlSchemes/Generic/musiml_matrix.xsd"),
new StreamSource("C:/XmlSchemes/Generic/musiml_primitive.xsd"),
new StreamSource("C:/XmlSchemes/Generic/musiml_vectors.xsd"),
}
)
);
DocumentBuilder documentBuilder =documentFactory.newDocumentBuilder();
documentBuilder.setErrorHandler(new ErrorChecker());
Document document =
documentBuilder.parse(new InputSource("C:/Response/result.xml"));
}
catch (SAXException e)
{
// we are here if the document is not valid:
// ... process validation error...
System.err.println("===>" + e.getMessage());
}
catch (Exception e)
{
e.printStackTrace();
}
} |
Quand j'ai exécuté j'ai des erreurs suivantes:
ERROR [2008-12-16 16:40:51.411] validationXSD.ErrorChecker " Line number: 6
Column number: 52
Message: cvc-elt.1: Cannot find the declaration of element 'resDoc'."
ERROR [2008-12-16 16:40:51.427] validationXSD.ErrorChecker " Line number: 6
Column number: 52
Message: cvc-elt.1: Cannot find the declaration of element 'resDoc'."
ERROR [2008-12-16 16:40:51.427] validationXSD.ErrorChecker " Line number: 11
Column number: 23
Message: cvc-elt.4.2: Cannot resolve 'ListResultMktData' to a type definition for element 'results'."
Contenu de response.xml
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
|
<?xml version="1.0" encoding="utf-8"?>
<resDoc
xmlns = "http://www.test.org"
version = "1.2.3.1"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<results
xsi:type = "ListResultMktData"
source = "PC Client"
destination = "Marketdata connector"
conf = "NONE">
<resMktData
xsi:type = "CorrelMatrixExtended"
specificParameter = "Closing"
asOfDate = "2008-11-10T13:13:13">
<maturities>2008-11-11T00:00:00</maturities>
<correls>
<maturity>2008-11-11T00:00:00</maturity>
<matrix>
<vector>
<value>1.00000000</value>
<value>-0.10941950</value>
</vector>
<vector>
<value>-0.10941950</value>
<value>1.00000000</value>
</vector>
</matrix>
</correls>
<names>NIKKEI 225</names>
<names>JPY LIB 3M</names>
</resMktData>
</results>
</resDoc>
|
Pourriez-vous m'indiquer comment valider ce XML (instance) avec l'ensemble des XSD?
Merci