Answer the question
In order to leave comments, you need to log in
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
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;
}
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 questionAsk a Question
731 491 924 answers to any question