2

I am trying to parse a rather large XML file - 1MB+, but I am having some difficulties. I first tried to add the xml file to the res/xml and parse it with the XmlResourceParser, but I got an exception saying "Data exceeds UNCOMPRESS_DATA_MAX". After a bit of research I found out that the compressed files have to be uncompressed in memory before reading and that this restriction doesnt apply for raw files. However when trying to parse the xml file from the res/raw folder with the SAXParser, I get an IOException, without any message and stacktrace:

SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(myXMLHandler);
InputSource src = new InputSource(stream);
xr.parse(src); // IOException

From what I understand those memory restrictions do not apply to raw resources, but what is causing this exception then?

Here is the stacktrace from logcat:

11-11 23:47:50.729: WARN/System.err(4886): java.io.IOException
11-11 23:47:50.739: WARN/System.err(4886):     at android.content.res.AssetManager.readAsset(Native Method)
11-11 23:47:50.749: WARN/System.err(4886):     at android.content.res.AssetManager.access$800(AssetManager.java:36)
11-11 23:47:50.759: WARN/System.err(4886):     at android.content.res.AssetManager$AssetInputStream.read(AssetManager.java:542)
11-11 23:47:50.759: WARN/System.err(4886):     at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:504)
11-11 23:47:50.769: WARN/System.err(4886):     at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
11-11 23:47:50.779: WARN/System.err(4886):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
11-11 23:47:50.790: WARN/System.err(4886):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)
Krassi
  • 2,336
  • 3
  • 22
  • 30
  • Please post the output of logcat. It is not possible to have an exception thrown without getting at least a logcat error level output. – Octavian Helm Nov 11 '10 at 22:39
  • I copied the output from logcat. – Krassi Nov 11 '10 at 22:50
  • did you try this method with an XML < 1MB. Just to rule it out – Mikpa Nov 14 '10 at 22:24
  • Answer is here [http://stackoverflow.com/questions/2860157/load-files-bigger-than-1m-from-assets-folder](http://stackoverflow.com/questions/2860157/load-files-bigger-than-1m-from-assets-folder) –  Mar 31 '11 at 20:52

1 Answers1

0

Split your file using this linux command split -l 1 main.xml

private String readTxt()
{
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    for(int J=1;J<15;J++)
    {
        int i;
        try
        {
            InputStream raw = this.getAssets().open("xa"+J);    
            i = raw.read();
            while (i != -1)
            {
                byteArrayOutputStream.write(i);
                i = raw.read();
            }
            raw.close();
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

Use as string into your SAX parsing.

Tisho
  • 8,320
  • 6
  • 44
  • 52
iAndroid
  • 951
  • 7
  • 18