如何保存来自服务器的excel文件并将其转换为字符串?

时间:2015-01-05 07:59:59

标签: android xml-parsing server

HY 我必须使用服务器移动应用程序。在这个应用程序中,我正在访问带有用户名和密码等参数的url,它返回服务器响应,它告诉服务器是否启用,表示是或否。但它返回xml文件。那么如何保存该xml文件,然后将其转换为字符串。我想将它转换为字符串,以便我可以向他显示服务器已启动是和否。如有任何帮助,将不胜感激

这是我正在使用的代码

`public String login(String uname,String password)
{
     InputStream is = null;
     String result = "";
     ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

     try 
     {  
           HttpClient httpclient = new DefaultHttpClient();
           HttpPost httppost = new HttpPost("Your Url");
           nameValuePairs.add(new BasicNameValuePair("emailid", uname));
           nameValuePairs.add(new BasicNameValuePair("password", password));
           httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
           HttpResponse response = httpclient.execute(httppost);
           HttpEntity entity = response.getEntity();

           is = entity.getContent();
      }

      catch (Exception e)
      {
       Log.e("log_tag", "Error in http connection " + e.toString());
      }
  // convert response to string
      try 
      {
           BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8);
           StringBuilder sb = new StringBuilder();
           String line = null;

       while ((line = reader.readLine()) != null) 
       {
           sb.append(line + "\n");
       }

        is.close();
        result = sb.toString();

       Log.v("log","Result :"+result);
  } 
  catch (Exception e)
  {
   Log.v("log", "Error converting result " + e.toString());
  }


    return result;
}`

但是在这里它正在为杰森工作而我正在获取xml文件,所以如何转换那个全是问题的文件

1 个答案:

答案 0 :(得分:0)

您可以保存文件并使用XmlPullParser进行解析。这很简单,从我的经验来看也很有效。