我正在使用 Spring 的 Jaxb2Marshaller 将 java 对象解码到 XML 文件中。 解码已成功。但我想将 doctype 声明添加到 XML 中。
我已经搜索了很多。这里有人知道如何将 doctype 声明添加到 xml 吗?请帮忙
当前 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;
}
关于java - 包括 Spring Jaxb2Marshaller 的 DOCTYPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19365002/