孤_0002
2017-10-13 18:03
public static String textMessageToXml(TextMessage textMessage) throws JAXBException{
JAXBContext jaxbContext = JAXBContext.newInstance(TextMessage.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "utf-8");
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, false);
StringWriter writer = new StringWriter();
jaxbMarshaller.marshal(textMessage, writer);
return writer.toString();
}
反正它已经生成xml了,把它当成xml进行解析吧。使用dom4j
,writer.toString().getRootElement();
初识Java微信公众号开发
158335 学习 · 469 问题
相似问题