M
M
Maxim Zelenkov2014-02-05 21:36:29
Android
Maxim Zelenkov, 2014-02-05 21:36:29

Loading XML into the phone's memory from the site?

Hello, I am creating an application that parses an XML file, the file is located in the res/xml project folder, it is parsed without problems. But I need this xml to be loaded into the phone's memory from the Internet at the first start and then parsed from the memory. Tell me how to do it, I could not find it myself.
Here's how I load xml into the parser

try {
            XmlPullParser parser = getResources().getXml(R.xml.troll);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
constv, 2014-02-06
@st1nger757

public Document getDocument(String url) throws MalformedURLException,
        IOException, Exception {
      URL documentUrl = new URL(url);
      URLConnection conn = documentUrl.openConnection();

      DocumentBuilderFactory factory = DocumentBuilderFactory
          .newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document document;
      InputStream stream = null;
      try {
        stream = conn.getInputStream();
        document = builder.parse(stream);
      } finally {
        if (stream != null)
          stream.close();
      }
      return document;
    }

B
Benderlidze, 2014-02-06
@Benderlidze

I think there is a mind to download xml to the phone and after it parse

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question