java - How to add raw XML text to SOAPBody element -
i have xml text generated application, , need wrap soap envelope around , later make web service call.
the following code builds envelope, don't know how add existing xml data soapbody
element.
string rawxml = "<some-data><some-data-item>1</some-data-item></some-data>"; // start api messagefactory mf = messagefactory.newinstance(); soapmessage request = mf.createmessage(); soappart part = request.getsoappart(); soapenvelope env = part.getenvelope(); // body. how add raw xml directly body? soapbody body = env.getbody();
i have tried body.addtextnode()
adds content <
, others escaped.
the following adds xml document:
document document = convertstringtodocument(rawxml); body.adddocument(document);
document creation:
private static document convertstringtodocument(string xmlstr) { documentbuilderfactory factory = documentbuilderfactory.newinstance(); documentbuilder builder; try { builder = factory.newdocumentbuilder(); document doc = builder.parse(new inputsource(new stringreader(xmlstr))); return doc; } catch (exception e) { e.printstacktrace(); } return null; }
i took convertstringtodocument()
logic this post.
Comments
Post a Comment