【发布时间】:2012-06-14 01:13:57
【问题描述】:
我有一些从我创建的 xsd 生成的 jaxb 对象。以前当我编组内容时,xml 输出如下所示:
<report xmlns="urn:com-test-person-data:v3">
<person-data>
.......(Data)
</person-data>
</report>
我最近从在 Windows 机器上编码转换到在 Mac 上编码。我正在使用的 jaxb 对象没有任何变化。但现在我的编组输出看起来像这样。
<report>
<person-data>
.......(Data)
</person-data>
</report>
我已经尝试进行一些挖掘以查看可以删除 xmlns 属性的内容,但没有运气。我使用该属性来检查正在使用的架构版本,因此它在输出的 xml 片段中很重要。
这是我调用编组器的代码 sn-p:
final JAXBContext context = JAXBContext.newInstance(Report.class);
final Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); //$NON-NLS-1$
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(reportJaxBObject, sw);
有什么想法吗?
【问题讨论】:
-
你编组的
sw是什么样的对象? -
对不起,应该已经发布了。它是 java.io.StringWriter 的一个实例。
标签: xml xsd jaxb xml-namespaces