包含Spring Jaxb2Marshaller的DOCTYPE [英] Include DOCTYPE for Spring Jaxb2Marshaller

查看:95
本文介绍了包含Spring Jaxb2Marshaller的DOCTYPE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Spring的Jaxb2Marshaller将java对象解组为XML文件。
解组已成功。但我想将doctype声明添加到XML中。

I am using Spring's Jaxb2Marshaller to unmarshall a java object into an XML file. The unmarshalling has been successful. But I want to add the doctype declaration to the XML.

我搜索了很多。这里有人知道如何将doctype声明添加到xml中吗?请帮助

I have searched a lot. Does here anybody knows how to add the doctype declaration to the xml ? Please help

当前XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<rootElement>

预期XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE XYZ PUBLIC "FPNID" "ABC.dtd">
<rootElement>


推荐答案

试试这个。

@Bean
public Jaxb2Marshaller getMarshaller() {
  Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
  marshaller.setMarshallerProperties(ImmutableMap.<String, Object> of("com.sun.xml.bind.xmlHeaders",
            "<!DOCTYPE XYZ PUBLIC \"FPNID\" \"ABC.dtd\">"));
return marshaller;
}

这篇关于包含Spring Jaxb2Marshaller的DOCTYPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆