Comment valider simplement un XML avec une XSD? - Java - Programmation
Marsh Posté le 17-10-2006 à 21:22:05
The simplest way to validate an XML document is to use a Validator object. This object will perform a validation against the Schema object from which the Validator was created. Schema objects are typically created from SchemaFactory objects. The static newInstance() object allows you to create a SchemaFactory using a preset XML schema. The following code demonstrates this:
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new File("mySchema.xsd" ));
Validator validator = schema.newValidator();
Calling the validate() method on the Validator object performs the actual validation. This method takes at least a javax.xml.transform.Source object, of which you can use a SAXSource or a DOMSource, depending on your preference.
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(new File("myXMLDocument.xml" ));
validator.validate(new DOMSource(document));
http://java.sun.com/developer/tech [...] tionxpath/
Marsh Posté le 16-10-2006 à 20:27:28
Bonjour,
Voilà tout est dans le titre.
D'un coté j'ai une feuille XML, de l'autre un fichier XSD comment puis -je valider , mon XML ?
J'suis super en galère.
d'Avance Merci