Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

JAXB%20Interview%20Questions%20and%20Answers

Question: How to unmarshall XML into Java objects? Convert from XML to Java objects.
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 UnmarshalException
• see discussion of ValidationEventCollector later
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook