I’m using the following code to read data from an XML file stored in my assets folder. It’s a simple XML file with the structure as below. The file has about 10 nodes (about 100 rows in total). But on my Galaxy S2 this piece of code takes 10 seconds to execute. Is ther a way to do this faster? THank you!
XML Structure:
<?xml version="1.0" encoding="utf-8"?>
<root>
<node>
<name>test</name>
<picture>test1</picture>
<thumbnail>asa</thumbnail>
<location>fdsf</location>
<description>sdfsd</description>
</node>
<node>
<name>test</name>
<picture>test1</picture>
<thumbnail>asa</thumbnail>
<location>fdsf</location>
<description>sdfsd</description>
</node>
<node>
<name>test</name>
<picture>test1</picture>
<thumbnail>asa</thumbnail>
<location>fdsf</location>
<description>sdfsd</description>
</node>
.......
</root>
And the code snippet :
String XMLText = "";
InputStream raw = getApplicationContext().getAssets().open(fileName);
InputStreamReader inputStreamReader = new InputStreamReader(raw);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line = "";
while ((line = bufferedReader.readLine()) != null) {
XMLText += line;
}
You should have to use SAX parser or XmlPullParser. In case if you want to concat/append data to the string then use
StringBuilderinstead ofStringtype.