1

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>
BobadKanda
  • 183
  • 3
  • 10

1 Answers1

0

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;
}
librucha
  • 635
  • 8
  • 13