Parsing local xml file in android

后端 未结 4 1535
轮回少年
轮回少年 2021-01-29 00:50

Hii every one, am brand new to android,i have a doubt can any one help me

In this following link

http://www.androidpeople.com/android-xml-parsing-tutorial-using

相关标签:
4条回答
  • 2021-01-29 00:54

    In Android you can store data in the assets folder, which can be entered by your code. To address your file use

    file:///android_asset/yourFile.xml
    

    I haven´t tried this yet, but I hope it will work

    0 讨论(0)
  • 2021-01-29 01:00

    In the link you provided, replace the line 47

    xr.parse(new InputSource(sourceUrl.openStream()));
    

    with

    xr.parse(getResources().getAssets().open(fileName));
    

    and place your xml file in /res/raw folder

    links: Asset Manager Docs and Resources Manager Docs

    0 讨论(0)
  • 2021-01-29 01:07
    try {
    //          InputStream is = getResources().getAssets().open("yourfilename.xml");
                InputStream is =getAssets().open("yourfilename.xml");
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();
    
                MyXMLHandler myXMLHandler = new MyXMLHandler();
                xr.setContentHandler(myXMLHandler);
    
                xr.parse(new InputSource(is));
    
            } catch (Exception e) {
                System.out.println("XML Pasing Excpetion = " + e);
            }
    
    0 讨论(0)
  • 2021-01-29 01:14

    This is what I did,

    InputStream is = res.openRawResource(R.raw.fileName);
    xr.parse(new InputSource(is));
    
    0 讨论(0)
提交回复
热议问题