Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use a <code>javax.xml.bind.util.JAXBSource</code> (<a href="https://docs.oracle.com/javase/7/docs/api/javax/xml/bind/util/JAXBSource.html" rel="nofollow noreferrer">javadoc</a>) and a <code>javax.xml.validation.Validator</code> (<a href="https://docs.oracle.com/javase/7/docs/api/javax/xml/validation/Validator.html" rel="nofollow noreferrer">javadoc</a>), throw in an implementation of <code>org.xml.sax.ErrorHandler</code> (<a href="https://docs.oracle.com/javase/7/docs/api/org/xml/sax/ErrorHandler.html" rel="nofollow noreferrer">javadoc</a>) and do the following:</p> <pre><code>import java.io.File; import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.util.JAXBSource; import javax.xml.validation.*; public class Demo { public static void main(String[] args) throws Exception { Customer customer = new Customer(); customer.setName("Jane Doe"); customer.getPhoneNumbers().add(new PhoneNumber()); customer.getPhoneNumbers().add(new PhoneNumber()); customer.getPhoneNumbers().add(new PhoneNumber()); JAXBContext jc = JAXBContext.newInstance(Customer.class); JAXBSource source = new JAXBSource(jc, customer); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File("customer.xsd")); Validator validator = schema.newValidator(); validator.setErrorHandler(new MyErrorHandler()); validator.validate(source); } } </code></pre> <p><strong>For More Information, See My Blog</strong></p> <ul> <li><a href="http://blog.bdoughan.com/2010/11/validate-jaxb-object-model-with-xml.html" rel="nofollow noreferrer">http://blog.bdoughan.com/2010/11/validate-jaxb-object-model-with-xml.html</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload