0

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-saxparser/

there is a sax parser in which xml file is taken from the internet, using a URL path How to change that url to local path in which xml is stored in raw folder of the project,,can any one give me the syntax ,,thanx in advance

4 Answers 4

3

This is what I did,

InputStream is = res.openRawResource(R.raw.fileName);
xr.parse(new InputSource(is));
Sign up to request clarification or add additional context in comments.

7 Comments

thanx for ur reply theresia, but wat is "res"? am getting error res not declared,have u tried for that proj which is in that link,is that executing?
Resource res = getResources(); Your class has to extend Activity, or at least get access to it. Pass it as a parameter, if you put your code in another class that doesn't extend Activity. I haven't tried the IBM tutorial, but I take some essential code from there. It should work for you, too.
thank u,,,,can u please give me zip file of parsing local xml (with repitative tags) sample project
do you have any other problems with the repetitive tags? you can always ask. and i thought i read one post about the same question here. good luck!
no still am unable to do that,,if u hav any example please ill give me
|
1

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

Comments

1
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);
        }

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.