Samples JDK
Test.java
1 package com.freemindcafe.xml.xsd.sample4;
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 
16 
17 public class Test {
18 
19  @org.junit.Test
20  public void read_xml_and_validate_against_the_schema_succeeds() throws Exception{
21  InputStream stream = this.getClass().getResourceAsStream("/com/freemindcafe/xml/xsd/sample4/po.xml");
22  PurchaseOrderDocument document = PurchaseOrderDocument.Factory.parse(stream);
23  XmlOptions options = new XmlOptions();
24  ArrayList<Object> validationErrors=new ArrayList<Object>();
25  options.setErrorListener(validationErrors);
26  if (!document.validate(options)) {
27  StringWriter sW=new StringWriter();
28  for (Object o : validationErrors) {
29  sW.append(o + "\n");
30  }
31  System.out.println(sW.toString());
32  }
33  Assert.assertTrue(document.validate());
34  XmlObject xmlObject = document.getPurchaseOrder().getElement();
35  MessageType messageType = (MessageType)xmlObject.changeType(MessageType.type);
36  System.out.println(messageType.isSetComment1());
37  System.out.println(messageType.getGiftWrap());
38  //Assert.assertTrue(messageType.getGiftWrap());
39  System.out.println(messageType.getComment1());
40  }
41 
42 }
org.apache.xmlbeans.XmlObject getElement()
com.freemindcafe.purchase3.PurchaseOrderType getPurchaseOrder()
org.apache.xmlbeans.XmlObject getComment1()