I want to parse my StringBuffer with Jdom2 after a SOAP call. But I didn't find a solution anywhere.
I saw a few solutions with w3.jdom, but they asked me to do with jdom2.
HttpResponse response = client.execute(httppost);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
Create a
org.jdom2.input.SAXBuilderand use itsbuild(Reader)method to create a JDOM2Documentobject, where the Reader is created usingnew StringReader(result.toString()).However, copying all the data out of an HTTP response into a StringBuffer just so that you can then parse it is pretty inefficient. You're already getting an InputStream from the
HttpResponseusingresponse.getEntity().getContent(), and you can supply thisInputStreamdirectly to the SAXBuilder'sbuild(InputStream)method.