简体   繁体   English

为什么我只得到 <?xml version=“1.0” standalone=“no”?> 什么时候要求xml文件? 安卓系统

[英]Why am I only getting <?xml version=“1.0” standalone=“no”?> when request for a xml file? Android

I am using this method to get xml file from a remote server, I use another parser class to parse it, and it got parsed successfully. 我正在使用此方法从远程服务器获取xml文件,我使用另一个解析器类对其进行解析,然后成功解析了该文件。 However, when i use Log.d("get xml", xml) to check the content of the xml file, it only shows <?xml version="1.0" standalone="no"?> in logCat. 但是,当我使用Log.d("get xml", xml)检查xml文件的内容时,它仅在logCat中显示<?xml version="1.0" standalone="no"?> Why? 为什么?

public String getXmlFromUrl(String url) {
    String xml = null;

    try {
        // defaultHttpClient

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        if(httpPost != null){
            Log.d("httpPost", "httpPost not null");
        }
        HttpResponse httpResponse = httpClient.execute(httpPost);
        if(httpResponse != null){
            Log.d("httpResponse", "httpResponse not null");
        }
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // return XML
    Log.d("get xml", xml);
    if(xml!=null){
        Log.d("get http client", "get http client not null");
    }
    return xml;
}

I think the problem wasn't the request but the output in the LogCat. 我认为问题不在于请求,而是LogCat中的输出。 Logging every line separately obtained the desired full response!. 分别记录每行可获得所需的完整响应!

So check this by applying breakpoint in debug mode. 因此,通过在调试模式下应用断点来进行检查。 Might its help to you. 可能会为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Why am I getting this warning and how to resolve it "This version only understands SDK XML versions up to 2 but an SDK XML..." - Why am I getting this warning and how to resolve it "This version only understands SDK XML versions up to 2 but an SDK XML..." 我如何在没有XML的情况下解析XML文件 <?xml version=1.0> 对于Android - How can I parse XML file without <?xml version=1.0> for android 为什么我的 styles.xml 文件 (Android Studio) 中出现“Android 资源链接失败” - Why am I getting “Android resource linking failed” in my styles.xml file (Android Studio) 为什么我没有在XML中获取android:background选项 - why i am not getting android:background option in XML AndroidManifest.xml文件丢失! 我为什么得到这个? - AndroidManifest.xml file missing! Why am I getting this? 为什么我无法创建android xml文件? - Why am I not able to create android xml file? 在Android中创建xml文件时出错 - Error when I am creating xml file in Android 错误:不支持XML版本“2.0”,仅支持XML 1.0 - Error:XML version “2.0” is not supported, only XML 1.0 is supported 当我在xml中使用不同的背景时,为什么会出现错误 - why am I getting errors when I use different backgrounds in xml 我定义时为什么会收到ClassNotFoundException <shape> 在布局XML? - Why am I getting ClassNotFoundException when I define <shape> in layout XML?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM