如何从给定的String中分离'xml'标记

时间:2015-07-14 07:17:57

标签: java xml apache http

我是暂停API的新手,我尝试使用Apache http在一个安静的API中读取xml标签。在这里我已经将所有xml标签放在一起,但实际上我想要把它作为标签。如下所示

<xml>something</xml>

这是我的ClientProtocol类,用于读取restful API。

package web;

import java.io.BufferedInputStream;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

/**
 *
 * @author user
 */
public class ClientProtocal
{

    public static void main(String[] args)
    {

        HttpClient httpClient = new DefaultHttpClient();
        try
        {
            HttpGet httpGetRequest = new HttpGet("https://xxxxredddd");
            HttpResponse httpResponse = httpClient.execute(httpGetRequest);

            System.out.println("----------------------------------------");
            System.out.println(httpResponse.getStatusLine());
            System.out.println("----------------------------------------");

            HttpEntity entity = httpResponse.getEntity();

            byte[] buffer = new byte[1024];
            if (entity != null)
            {
                InputStream inputStream = entity.getContent();
                try
                {
                    int bytesRead = 0;
                    BufferedInputStream bis = new BufferedInputStream(inputStream);
                    while ((bytesRead = bis.read(buffer)) != -1)
                    {
                        String chunk = new String(buffer, 0, bytesRead);
                        System.out.println(chunk);
                    }
                } catch (Exception e)
                {
                    e.printStackTrace();
                } finally
                {
                    try
                    {
                        inputStream.close();
                    } catch (Exception ignore)
                    {
                        ignore.printStackTrace();
                    }
                }
            }
        } catch (Exception e)
        {
            e.printStackTrace();
        } finally
        {
            httpClient.getConnectionManager().shutdown();
        }

    }
}

0 个答案:

没有答案