在Java中将JDom Document转换为SOAPMessage

时间:2010-12-03 07:34:58

标签: java

如何在java中将org.jdom.Document转换为javax.xml.soap.SOAPMessage?

1 个答案:

答案 0 :(得分:2)

像这样的东西应该有用,虽然它有点笨重但不会很快:

MessageFactory messageFactory = MessageFactory.newInstance();

public SOAPMessage toMessage(Document jdomDocument) throws IOException, SOAPException {
   String xml = new XMLOutputter().outputString(jdomDocument);
   InputStream inputStream = new StringBufferInputStream(xml);
   return messageFactory.createMessage(null, inputStream);
}

这假定JDOM文档在其整体,标题和所有内容中表示有效的SOAP消息结构。