Differences
This shows you the differences between two versions of the page.
validating_xml_with_xsd [2019/01/07 09:17] |
validating_xml_with_xsd [2021/04/05 11:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Validating XML with XSD (Java) ====== | ||
+ | This validates an XML with an XSD scheme which must not necessarily be stated in the XML file. By using the '' | ||
+ | |||
+ | <sxh java> | ||
+ | import javax.xml.transform.stream.StreamSource; | ||
+ | import javax.xml.validation.Schema; | ||
+ | import javax.xml.validation.SchemaFactory; | ||
+ | import javax.xml.validation.Validator; | ||
+ | |||
+ | import org.xml.sax.SAXException; | ||
+ | |||
+ | |||
+ | public class XmlValidator | ||
+ | { | ||
+ | | ||
+ | { | ||
+ | try { | ||
+ | | ||
+ | |||
+ | SchemaFactory schemaFactory = SchemaFactory.newInstance(" | ||
+ | |||
+ | Schema sch= schemaFactory .newSchema(new StreamSource(" | ||
+ | Validator validator = sch.newValidator(); | ||
+ | |||
+ | validator.validate(new StreamSource(" | ||
+ | | ||
+ | System.out.println(" | ||
+ | |||
+ | } catch (Exception e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | {{tag> |