Search code examples
androidxml-parsingapache-commons

Parsing XML file in raw folder using XMLConfiguration


I'm trying to use XMLConfigurable apache common XML parser to parse an XML file that I appended to the raw folder in android, but i cant find a way to actually get the xml path.

I have tried this but it wont work, XMLConfiguration throws error of file not found. Is there a way to actually get the full path?

I have also tried to use this:

context.getResources().openRawResource(R.raw.kmlsample);

But also can't figure out a way to use XMLConfiguration to take InputStream, all it takes is File or URL or String(as the filename/path).


Solution

  • I think you need to use method : load(InputStream in)

    XMLConfiguration config = new XMLConfiguration();
    try {
        config.load( context.getResources().openRawResource(R.raw.kmlsample));
    
    } catch (ConfigurationException e) {
        e.printStackTrace();
    } catch (NotFoundException e) {
        e.printStackTrace();
    }