Parse xml from httppost response

Viewed 30048

During the execution of a http POST i store the response as a String response.

HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
response = EntityUtils.toString(resEntity);

If I print response it looks like:

<?xml version="1.0" encoding="UTF-8"?>
<response status="ok">
<sessionID>lo8mdn7bientr71b5kn1kote90</sessionID>
</response>

I would like to store just the sessionID as a string. I've tried

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));

and various methods like this but it won't let me run the code since DocumentBuildFactory and InputSource are invalid.

What should I be doing to extract specific strings from this XML?

2 Answers
Related