如何在android中保存xml文件中链接的数据?

发布于 2024-11-30 16:37:01 字数 469 浏览 2 评论 0原文

我想将某个链接的数据保存在android中的xml文件中。我该怎么做?谁能帮助我,我不知道。

提前致谢。

链接中的数据如下所示:

 <elements>
   <element>
     <def>confirm</def>
     <text>Ok</text>
   </element>
  <element>
    <def>email</def>
    <text>Email</text>
  </element>
  <element>
   <def>firstname</def>
   <text>Prénom</text>
  </element>
</element>

I want to save the data from a certain link in a xml file in android. How can I do this? Can anyone help me, I have no idea.

Thanks in advance.

The data from link looks like this :

 <elements>
   <element>
     <def>confirm</def>
     <text>Ok</text>
   </element>
  <element>
    <def>email</def>
    <text>Email</text>
  </element>
  <element>
   <def>firstname</def>
   <text>Prénom</text>
  </element>
</element>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟织青萝梦 2024-12-07 16:37:01

你不是在问一个具体的问题。你不能指望其他人为你编写代码。抱歉,请不要刻薄。无论如何,为了让您开始,我假设您正在尝试从 http 链接下载文件?您可能想看看 httpClient。这是使用它的一个很好的例子:

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
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;
public class TestHttpGet {
    public void executeHttpGet() throws Exception {
        BufferedReader in = null;
        try {
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI("http://www.somewhere.com/somefile.xml"));
            HttpResponse response = client.execute(request);
            in = new BufferedReader
            (new InputStreamReader(response.getEntity().getContent()));
            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }
            in.close();
            String page = sb.toString();
            System.out.println(page);
            } finally {
            if (in != null) {
                try {
                    in.close();
                    } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

You are not asking a specific question. You can not expect other people to write code for you. Sorry, do not try to be mean. Anyways, to get you start, I assume you are trying to download a file from a http link? You might want to look at httpClient. This is a good example of using it:

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
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;
public class TestHttpGet {
    public void executeHttpGet() throws Exception {
        BufferedReader in = null;
        try {
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI("http://www.somewhere.com/somefile.xml"));
            HttpResponse response = client.execute(request);
            in = new BufferedReader
            (new InputStreamReader(response.getEntity().getContent()));
            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }
            in.close();
            String page = sb.toString();
            System.out.println(page);
            } finally {
            if (in != null) {
                try {
                    in.close();
                    } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文