Include DOCTYPE for Spring Jaxb2Marshaller

我的未来我决定 提交于 2019-12-24 14:44:28

问题


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.

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

Current XML

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

Expected XML

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

回答1:


Try this.

@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;
}


来源:https://stackoverflow.com/questions/19365002/include-doctype-for-spring-jaxb2marshaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!