我有这种方法:
public StampaModuloPrivacyResponse generaXmlALC(StampaModuloPrivacyRequest input)
{
final StampaModuloPrivacyResponse stampaModuloPrivacyResponse = new StampaModuloPrivacyResponse();
try {
JAXBContext jaxbContext = JAXBContext.newInstance(StampaModuloPrivacyRequest.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(input, System.out);
/*HERE*/
} catch (JAXBException e) {
e.printStackTrace();
}
return stampaModuloPrivacyResponse;
}
}
我需要将从marshaller返回的xml转换为字符串,因为我必须在stampamoduloPrivacyResponse.setXMLString()中进行设置...我该怎么办?
谢谢
最佳答案
使用StringWriter:
StringWriter out = new StringWriter();
jaxbMarshaller.marshal(input, out);
stampamoduloPrivacyResponse.setXMLString(out.toString());
关于java - 将XML转换为字符串JAVA,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48249712/