|
Answer» Example:
ObjectFactory factory = new ObjectFactory();
Unmarshaller u = factory.createUnmarshaller();
Cars cars = (Cars) u.unmarshal(new FileInputStream(“cars.xml”));
unmarshal method ACCEPTS:
- java.io.File
- java.io.InputStream
- java.net.URL
- javax.xml.transform.Source
related to XSLT:
org.w3c.dom.Node
related to DOM:
org.xml.sax.InputSource
related to SAX:
• Other Unmarshaller methods void setValidating(boolean validating) • true to enable validation during unmarshalling; false to disable (the default) boolean setEventHandler(ValidationEventHandler handler) • handleEvent method of ValidationEventHandler is called if validation ERRORS are ENCOUNTERED during unmarshalling • default handler terminates marshalling after first error • return true to continue unmarshalling • return false to terminate with UnmarshalExceptio • SEE discussion of ValidationEventCollector later Example: ObjectFactory factory = new ObjectFactory(); Unmarshaller u = factory.createUnmarshaller(); Cars cars = (Cars) u.unmarshal(new FileInputStream(“cars.xml”)); unmarshal method accepts: related to XSLT: org.w3c.dom.Node related to DOM: org.xml.sax.InputSource related to SAX: • Other Unmarshaller methods void setValidating(boolean validating) • true to enable validation during unmarshalling; false to disable (the default) boolean setEventHandler(ValidationEventHandler handler) • handleEvent method of ValidationEventHandler is called if validation errors are encountered during unmarshalling • default handler terminates marshalling after first error • return true to continue unmarshalling • return false to terminate with UnmarshalExceptio • see discussion of ValidationEventCollector later
|