Skip to content

Commit

Permalink
#4 example page
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Nov 6, 2013
1 parent 3659e1f commit 71250ac
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/site/markdown/example-xsd.md.vm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# How to validate XML with XSD Schema

You need two classes:
[`XMLDocument`](./apidocs-${project.version}/com/jcabi/xml/XMLDocument.html)
and [`XSDDocument`](./apidocs-${project.version}/com/jcabi/xml/XSDDocument.html)
which implement
[`XML`](./apidocs-${project.version}/com/jcabi/xml/XML.html)
and [`XSD`](./apidocs-${project.version}/com/jcabi/xml/XSD.html)
interfaces respectfully. They work with your default DOM implementation.
For example:

```java
XML first = new XMLDocument(
"<orders><order id="4">Coffee to go</order></orders>"
);
String xsd = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>",
+ "<xs:element name='payments'/>",
+ "</xs:schema>";
Collection<SAXParseException> errors = new XSDDocument(xsd).validate(xml);
if (errors.isEmpty()) {
System.out.println("XML is valid");
} else {
System.out.println("XSD validation failed: " + errors);
}
```

0 comments on commit 71250ac

Please sign in to comment.