JAXB 면접 질문과 답변
Question: How to unmarshall XML into Java objects? Convert from XML to Java objects.Answer: • ExampleObjectFactory 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 |
복습용 저장
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
도움이 되었나요? 예 아니요
Most helpful rated by users:
- What Is XML Binding?
- What is XML Binding Relationships?
- Please explain JAXB Use Cases.
- Why Use XML Binding?
- What are the goals of JAXB?