Samples JDK
Test.java
1 package com.freemindcafe.xml.xsd.sample2;
2 
3 import java.io.File;
4 import java.io.InputStream;
5 import java.io.StringWriter;
6 import java.util.ArrayList;
7 
8 import junit.framework.Assert;
9 
10 import org.apache.xmlbeans.SchemaType;
11 import org.apache.xmlbeans.XmlObject;
12 import org.apache.xmlbeans.XmlOptions;
13 
15 
16 public class Test {
17 
18  @org.junit.Test
19  public void read_xml_and_validate_against_the_schema_succeeds() throws Exception{
20  InputStream stream = this.getClass().getResourceAsStream("/com/freemindcafe/xml/xsd/sample2/po.xml");
21  PurchaseOrderDocument document = PurchaseOrderDocument.Factory.parse(stream);
22  XmlOptions options = new XmlOptions();
23  ArrayList<Object> validationErrors=new ArrayList<Object>();
24  options.setErrorListener(validationErrors);
25  if (!document.validate(options)) {
26  StringWriter sW=new StringWriter();
27  for (Object o : validationErrors) {
28  sW.append(o + "\n");
29  }
30  System.out.println(sW.toString());
31  }
32  Assert.assertTrue(document.validate());
33 
34  }
35 
36 
37 }