在执行 http POST 期间,我将响应存储为字符串响应。
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
response = EntityUtils.toString(resEntity);
如果我打印响应,它看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<response status="ok">
<sessionID>lo8mdn7bientr71b5kn1kote90</sessionID>
</response>
我只想将 sessionID 存储为字符串。我试过了
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
以及像这样的各种方法,但它不会让我运行代码,因为 DocumentBuildFactory 和 InputSource 是无效的。
我应该怎么做才能从这个 XML 中提取特定的字符串?