Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:28:17+00:00 2026-06-15T22:28:17+00:00

I have a local xml file called data.xml . I have parsed it using

  • 0

I have a local xml file called data.xml. I have parsed it using PullParser. After parsing the logcat output is:

12-06 10:51:33.761: I/End:(5026): START_TAG: quiz
12-06 10:51:33.761: I/End:(5026): START_TAG: mchoice
12-06 10:51:33.761: I/End:(5026): START_TAG: question
12-06 10:51:33.761: I/End:(5026): TEXT: Not a team sport for sure
12-06 10:51:33.761: I/End:(5026): END_TAG: question
12-06 10:51:33.761: I/End:(5026): START_TAG: id
12-06 10:51:33.761: I/End:(5026): TEXT: 1
12-06 10:51:33.761: I/End:(5026): END_TAG: id
12-06 10:51:33.761: I/End:(5026): START_TAG: option1
12-06 10:51:33.761: I/End:(5026): TEXT: Cricket
12-06 10:51:33.761: I/End:(5026): END_TAG: option1
12-06 10:51:33.761: I/End:(5026): START_TAG: option2
12-06 10:51:33.761: I/End:(5026): TEXT: Tennis
12-06 10:51:33.761: I/End:(5026): END_TAG: option2
12-06 10:51:33.761: I/End:(5026): START_TAG: option3
12-06 10:51:33.761: I/End:(5026): TEXT: Rugby
12-06 10:51:33.761: I/End:(5026): END_TAG: option3
12-06 10:51:33.761: I/End:(5026): START_TAG: option4
12-06 10:51:33.761: I/End:(5026): TEXT: Soccer
12-06 10:51:33.761: I/End:(5026): END_TAG: option4
12-06 10:51:33.761: I/End:(5026): START_TAG: answer
12-06 10:51:33.761: I/End:(5026): TEXT: Tennis
12-06 10:51:33.761: I/End:(5026): END_TAG: answer
12-06 10:51:33.761: I/End:(5026): END_TAG: mchoice
12-06 10:51:33.761: I/End:(5026): START_TAG: mchoice
12-06 10:51:33.761: I/End:(5026): START_TAG: question
12-06 10:51:33.761: I/End:(5026): TEXT: I am the biggest planet in the Solar System
12-06 10:51:33.761: I/End:(5026): END_TAG: question
12-06 10:51:33.761: I/End:(5026): START_TAG: id
12-06 10:51:33.761: I/End:(5026): TEXT: 2
12-06 10:51:33.761: I/End:(5026): END_TAG: id
12-06 10:51:33.761: I/End:(5026): START_TAG: option1
12-06 10:51:33.761: I/End:(5026): TEXT: Saturn
12-06 10:51:33.761: I/End:(5026): END_TAG: option1
12-06 10:51:33.761: I/End:(5026): START_TAG: option2
12-06 10:51:33.761: I/End:(5026): TEXT: Jupiter
12-06 10:51:33.761: I/End:(5026): END_TAG: option2
12-06 10:51:33.761: I/End:(5026): START_TAG: option3
12-06 10:51:33.761: I/End:(5026): TEXT: Neptune
12-06 10:51:33.761: I/End:(5026): END_TAG: option3
12-06 10:51:33.761: I/End:(5026): START_TAG: option4
12-06 10:51:33.761: I/End:(5026): TEXT: Pluto
12-06 10:51:33.761: I/End:(5026): END_TAG: option4
12-06 10:51:33.761: I/End:(5026): START_TAG: answer
12-06 10:51:33.761: I/End:(5026): TEXT: Jupiter
12-06 10:51:33.761: I/End:(5026): END_TAG: answer
12-06 10:51:33.761: I/End:(5026): END_TAG: mchoice
12-06 10:51:33.761: I/End:(5026): START_TAG: mchoice
12-06 10:51:33.761: I/End:(5026): START_TAG: question
12-06 10:51:33.761: I/End:(5026): TEXT: I am the closest star to the earth
12-06 10:51:33.761: I/End:(5026): END_TAG: question
12-06 10:51:33.761: I/End:(5026): START_TAG: id
12-06 10:51:33.761: I/End:(5026): TEXT: 3
12-06 10:51:33.761: I/End:(5026): END_TAG: id
12-06 10:51:33.761: I/End:(5026): START_TAG: option1
12-06 10:51:33.761: I/End:(5026): TEXT: Milky way
12-06 10:51:33.761: I/End:(5026): END_TAG: option1
12-06 10:51:33.761: I/End:(5026): START_TAG: option2
12-06 10:51:33.761: I/End:(5026): TEXT: Moon
12-06 10:51:33.761: I/End:(5026): END_TAG: option2
12-06 10:51:33.761: I/End:(5026): START_TAG: option3
12-06 10:51:33.761: I/End:(5026): TEXT: Sun
12-06 10:51:33.761: I/End:(5026): END_TAG: option3
12-06 10:51:33.761: I/End:(5026): START_TAG: option4
12-06 10:51:33.761: I/End:(5026): TEXT: North Star
12-06 10:51:33.761: I/End:(5026): END_TAG: option4
12-06 10:51:33.761: I/End:(5026): START_TAG: answer
12-06 10:51:33.761: I/End:(5026): TEXT: Sun
12-06 10:51:33.761: I/End:(5026): END_TAG: answer
12-06 10:51:33.761: I/End:(5026): END_TAG: mchoice
12-06 10:51:33.761: I/End:(5026): START_TAG: mchoice
12-06 10:51:33.761: I/End:(5026): START_TAG: question
12-06 10:51:33.761: I/End:(5026): TEXT: A number which is not prime
12-06 10:51:33.761: I/End:(5026): END_TAG: question
12-06 10:51:33.761: I/End:(5026): START_TAG: id
12-06 10:51:33.761: I/End:(5026): TEXT: 4
12-06 10:51:33.761: I/End:(5026): END_TAG: id
12-06 10:51:33.761: I/End:(5026): START_TAG: option1
12-06 10:51:33.761: I/End:(5026): TEXT: 31
12-06 10:51:33.761: I/End:(5026): END_TAG: option1
12-06 10:51:33.761: I/End:(5026): START_TAG: option2
12-06 10:51:33.761: I/End:(5026): TEXT: 61
12-06 10:51:33.761: I/End:(5026): END_TAG: option2
12-06 10:51:33.761: I/End:(5026): START_TAG: option3
12-06 10:51:33.761: I/End:(5026): TEXT: 71
12-06 10:51:33.761: I/End:(5026): END_TAG: option3
12-06 10:51:33.761: I/End:(5026): START_TAG: option4
12-06 10:51:33.761: I/End:(5026): TEXT: 91
12-06 10:51:33.761: I/End:(5026): END_TAG: option4
12-06 10:51:33.761: I/End:(5026): START_TAG: answer
12-06 10:51:33.761: I/End:(5026): TEXT: 91
12-06 10:51:33.761: I/End:(5026): END_TAG: answer
12-06 10:51:33.761: I/End:(5026): END_TAG: mchoice
12-06 10:51:33.761: I/End:(5026): START_TAG: mchoice
12-06 10:51:33.761: I/End:(5026): START_TAG: question
12-06 10:51:33.761: I/End:(5026): TEXT: Which is correct?
12-06 10:51:33.761: I/End:(5026): END_TAG: question
12-06 10:51:33.761: I/End:(5026): START_TAG: id
12-06 10:51:33.761: I/End:(5026): TEXT: 5
12-06 10:51:33.761: I/End:(5026): END_TAG: id
12-06 10:51:33.761: I/End:(5026): START_TAG: option1
12-06 10:51:33.761: I/End:(5026): TEXT: Foreine
12-06 10:51:33.761: I/End:(5026): END_TAG: option1
12-06 10:51:33.761: I/End:(5026): START_TAG: option2
12-06 10:51:33.761: I/End:(5026): TEXT: Fariegn
12-06 10:51:33.761: I/End:(5026): END_TAG: option2
12-06 10:51:33.761: I/End:(5026): START_TAG: option3
12-06 10:51:33.761: I/End:(5026): TEXT: Foreig
12-06 10:51:33.761: I/End:(5026): END_TAG: option3
12-06 10:51:33.761: I/End:(5026): START_TAG: option4
12-06 10:51:33.761: I/End:(5026): TEXT: Foreign
12-06 10:51:33.761: I/End:(5026): END_TAG: option4
12-06 10:51:33.761: I/End:(5026): START_TAG: answer
12-06 10:51:33.761: I/End:(5026): TEXT: Foreign
12-06 10:51:33.761: I/End:(5026): END_TAG: answer

I have used this method to parse the XML file:

//local XML
         private String getEventsFromAnXML(Activity activity)
                    throws XmlPullParserException, IOException
                    {
                     StringBuffer stringBuffer = new StringBuffer();
                     Resources res = activity.getResources();
                     XmlResourceParser xpp = res.getXml(R.xml.data);
                     xpp.next();

                     int eventType = xpp.getEventType();
                     while (eventType != XmlPullParser.END_DOCUMENT)
                     {
                      if(eventType == XmlPullParser.START_DOCUMENT)
                      {
                      // stringBuffer.append("--- Start XML ---");
                       Log.i("Start:", "--- Start XML ---");
                      }
                      else if(eventType == XmlPullParser.START_TAG)
                      {
                       stringBuffer.append("\nSTART_TAG: "+xpp.getName());

                       Log.i("Start:", stringBuffer.toString());
                      }
                      else if(eventType == XmlPullParser.END_TAG)
                      {
                       stringBuffer.append("\nEND_TAG: "+xpp.getName());
                       Log.i("End:", stringBuffer.toString());
                      }
                      else if(eventType == XmlPullParser.TEXT)
                      {
                       stringBuffer.append("\nTEXT: "+xpp.getText());
                       Log.i("Text:", stringBuffer.toString());
                      }
                      eventType = xpp.next();
                     }
                     stringBuffer.append("\n--- End XML ---");
                     return stringBuffer.toString();
                    }

But, I want the output to be like this:

<?xml version="1.0" encoding="utf-8"?>
12-06 10:51:34.891: I/XML:(5026): <quiz>
12-06 10:51:34.891: I/XML:(5026):   <mchoice>
12-06 10:51:34.891: I/XML:(5026):     <question>Not a team sport for sure</question>
12-06 10:51:34.891: I/XML:(5026):   <id>1</id>
12-06 10:51:34.891: I/XML:(5026):     <option1>Cricket</option1>
12-06 10:51:34.891: I/XML:(5026):     <option2>Tennis</option2>
12-06 10:51:34.891: I/XML:(5026):     <option3>Rugby</option3>
12-06 10:51:34.891: I/XML:(5026):     <option4>Soccer</option4>
12-06 10:51:34.891: I/XML:(5026):   <answer>Tennis</answer>
12-06 10:51:34.891: I/XML:(5026):   </mchoice>
12-06 10:51:34.891: I/XML:(5026):   <mchoice>
12-06 10:51:34.891: I/XML:(5026):     <question>I am the biggest planet in the Solar System</question>
12-06 10:51:34.891: I/XML:(5026):   <id>2</id>
12-06 10:51:34.891: I/XML:(5026):     <option1>Saturn</option1>
12-06 10:51:34.891: I/XML:(5026):     <option2>Jupiter</option2>
12-06 10:51:34.891: I/XML:(5026):     <option3>Neptune</option3>
12-06 10:51:34.891: I/XML:(5026):     <option4>Pluto</option4>
12-06 10:51:34.891: I/XML:(5026):     <answer>Jupiter</answer>
12-06 10:51:34.891: I/XML:(5026):   </mchoice>
12-06 10:51:34.891: I/XML:(5026):   <mchoice>
12-06 10:51:34.891: I/XML:(5026):     <question>I am the closest star to the earth</question>
12-06 10:51:34.891: I/XML:(5026):   <id>3</id>
12-06 10:51:34.891: I/XML:(5026):     <option1>Milky way</option1>
12-06 10:51:34.891: I/XML:(5026):     <option2>Moon</option2>
12-06 10:51:34.891: I/XML:(5026):     <option3>Sun</option3>
12-06 10:51:34.891: I/XML:(5026):     <option4>North Star</option4>
12-06 10:51:34.891: I/XML:(5026):     <answer>Sun</answer>
12-06 10:51:34.891: I/XML:(5026):   </mchoice>
12-06 10:51:34.891: I/XML:(5026):   <mchoice>
12-06 10:51:34.891: I/XML:(5026):     <question>A number which is not prime</question>
12-06 10:51:34.891: I/XML:(5026):   <id>4</id>
12-06 10:51:34.891: I/XML:(5026):     <option1>31</option1>
12-06 10:51:34.891: I/XML:(5026):     <option2>61</option2>
12-06 10:51:34.891: I/XML:(5026):     <option3>71</option3>
12-06 10:51:34.891: I/XML:(5026):     <option4>91</option4>
12-06 10:51:34.891: I/XML:(5026):     <answer>91</answer>
12-06 10:51:34.891: I/XML:(5026):    </mchoice>
12-06 10:51:34.891: I/XML:(5026):   <mchoice>
12-06 10:51:34.891: I/XML:(5026):     <question>Which is correct?</question>
12-06 10:51:34.891: I/XML:(5026):   <id>5</id>
12-06 10:51:34.891: I/XML:(5026):     <option1>Foreine</option1>
12-06 10:51:34.891: I/XML:(5026):     <option2>Fariegn</option2>
12-06 10:51:34.891: I/XML:(5026):     <option3>Foreig</option3>
12-06 10:51:34.891: I/XML:(5026):     <option4>Foreign</option4>
12-06 10:51:34.891: I/XML:(5026):     <answer>Foreign</answer>
12-06 10:51:34.891: I/XML:(5026):      </mchoice>
12-06 10:51:34.891: I/XML:(5026): </quiz>

Where am I going wrong? It will be best if I can store the xml data in a String variable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:28:19+00:00Added an answer on June 15, 2026 at 10:28 pm

    Try this :

                int eventType = parser.getEventType();
    
                done = false;
    
                while (eventType != XmlPullParser.END_DOCUMENT && !done) {
                    String name = null;
                    switch (eventType) {
                    case XmlPullParser.START_DOCUMENT:
    
                        break;
    
                    case XmlPullParser.START_TAG:
                        name = parser.getName();
    
    
                        if (name.equalsIgnoreCase("mchoice")) {
    
                            // Initialize your list
    
                        } else if (list!= null) {
    
                            if (name.equals(question)) {
    
                                System.out.println("question : " + parser
                                        .nextText());
    
                            }
    
                            else if (name.equalsIgnoreCase("id")) {
    
                                System.out.println("id : " + parser
                                        .nextText());
    
                            }
    
                            else if (name.equalsIgnoreCase("option1")) {
    
                                System.out.println("option 1 : " + parser
                                        .nextText());
    
                            }
    
                            else if (name.equalsIgnoreCase("option2")) {
    
                                System.out.println("option 2 : " + parser
                                        .nextText());
    
                            }
    
                            else if (name.equalsIgnoreCase("option3")) {
    
                                System.out.println("option 3 : " + parser
                                        .nextText());
    
                            }
    
                            else if (name.equalsIgnoreCase("option4")) {
    
                                System.out.println("option 4 :" + parser
                                        .nextText());
    
                            }
    
                            else if (name.equalsIgnoreCase("answer")) {
    
                                System.out.println("answer :" + parser
                                        .nextText());
    
                            }                       
                        }
    
                        // -------------
    
                        break;
    
                    case XmlPullParser.END_TAG:
                        name = parser.getName();
                        if (name.equalsIgnoreCase("mchoice")
                                && list != null) {  
    
                            // add elements in list
    
                        } else if (name.equalsIgnoreCase("quiz")) {
    
    
                            done = true;
                        }
                        break;
                    }
                    eventType = parser.next();
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PhoneGap, jQuery mobile in Xcode. I have a local xml (data.xml)
I have removed the wishlist link from my top.links using my local.xml file: <remove
I have built a Vista Gadget. It grabs a local XML file called settings.xml.
I have an application which pulls its data from a local XML file. However,
I have defined a local mirror for all repositories in the settings.xml file: <mirror>
Is it possible to delete the contents of a local XML file using a
I have put a file in my grails-app/conf package called size_config.xml . When the
I have created a HTML file to load local XML file and read contents
I have one local xml file. I am storing here : res/xml/myxml.xml <?xml version=1.0
I have a main page which gets the information from a local xml file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.