我的XML文档需要DOCTYPE
定义。
我使用以下API /框架:
Gradle的依赖关系:
dependencies {
compile('com.fasterxml.jackson.dataformat:jackson-dataformat-xml')
compile('org.springframework.boot:spring-boot-starter-freemarker')
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
串行:
public String createXMLDoc(Object request){
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);//XML declaration
try {
return xmlMapper.writeValueAsString(request);
}
catch(JsonProcessingException e){
log.log(Level.SEVERE, e.getMessage());
e.printStackTrace();
}
return "";
}
有没有办法像这样简单地添加DOCTYPE,例如:
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
是XML doc声明。
有什么想法吗?