问题
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