小编Ted*_*Ted的帖子

从httppost响应中解析xml

在执行http POST期间,我将响应存储为String响应.

HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
response = EntityUtils.toString(resEntity);
Run Code Online (Sandbox Code Playgroud)

如果我打印响应,它看起来像:

<?xml version="1.0" encoding="UTF-8"?>
<response status="ok">
<sessionID>lo8mdn7bientr71b5kn1kote90</sessionID>
</response>
Run Code Online (Sandbox Code Playgroud)

我想将sessionID存储为字符串.我试过了

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
Run Code Online (Sandbox Code Playgroud)

和这样的各种方法,但它不会让我运行代码,因为DocumentBuildFactory和InputSource是无效的.

我应该怎么做才能从这个XML中提取特定的字符串?

java xml post android http

7
推荐指数
1
解决办法
3万
查看次数

标签 统计

android ×1

http ×1

java ×1

post ×1

xml ×1