【发布时间】:2010-05-27 07:42:13
【问题描述】:
我正在编组(序列化)JAXB bean 以输出流。如何将 DOCTYPE 声明和 xml 处理指令添加到输出?
我目前正在这样编组:
JAXBContext jaxbContext = JAXBContext.newInstance("com.example.package");
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = schemaFactory.newSchema(schemaSource);
marshaller.setSchema(schema);
marshaller.marshal(object, output);
我希望输出看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Something SYSTEM "some.dtd">
<?xml-stylesheet type="text/xsl" href="some.xsl"?>
JAXB bean 是生成的代码,所以我不想更改它们。
添加xml processing instructions 和doctype 有一些技巧和未记录的技巧(请参阅Making JAXB generate an XML processing instruction)。但是,首选或正确的方法是什么?
【问题讨论】:
标签: java xml jaxb marshalling