可以通过将javax Transformer应用于输出来解决此烦人的问题。
import javax.xml.transform.*;import javax.xml.transform.dom.*;import javax.xml.transform.stream.StreamResult;Object jaxbElement = // The object you want to marshall using jaxb.JAXBContext context = JAXBContext.newInstance(jaxbElement.getClass());Marshaller marshaller = context.createMarshaller();OutputStream out = // Here your destination, FileOutStream, ByteOutStream etcDOMResult domResult = new DOMResult();marshaller.marshal(jaxbElement, domResult);Transformer transformer = TransformerFactory.newInstance().newTransformer();transformer.setOutputProperty(OutputKeys.INDENT, "yes");transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");transformer.transform(new DOMSource(domResult.getNode()), new StreamResult(out));
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)