JAXB 면접 질문과 답변
Question: Java code for marshalling Java objects into XML.Answer: • ExampleMarshaller m = factory.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Writer fw = new FileWriter("newCars.xml"); m.marshal(cars, fw); • marshal method accepts – java.io.OutputStream – java.io.Writer – javax.xml.transform.Result • related to XSLT – org.w3c.dom.Node • related to DOM – org.xml.sax.ContentHandler • related to SAX • Other Marshaller methods – boolean setEventHandler(ValidationEventHandler handler) • same as use with Unmarshaller, but validation events are delivered during marshalling – void setProperty(String name, Object value) • supported properties are – jaxb.encoding - value is a String » the encoding to use when marshalling; defaults to “UTF-8” – jaxb.formatted.output - value is a Boolean » true to output line breaks and indentation; false to omit (the default) – jaxb.schemaLocation - value is a String » to specify xsi:schemaLocation attribute in generated XML – jaxb.noNamespaceSchemaLocation - value is a String » to specify xsi:noNamespaceSchemaLocation attribute in generated XML |
복습용 저장
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
도움이 되었나요? 예 아니요
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?