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 5951053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:28:55+00:00 2026-05-22T17:28:55+00:00

Below is the code which displays all the xml. I don’t want to display

  • 0

Below is the code which displays all the xml. I don’t want to display all the xml content but only want to check if the id = 2 than display the description. Please help me modify the code.

private String getEventsFromAnXML(Activity activity)throws XmlPullParserException, IOException

    {
        StringBuffer stringBuffer = new StringBuffer();
           Resources res = activity.getResources();
           XmlResourceParser xrp = res.getXml(R.xml.books.xml);
           xrp.next();

         int eventType = xrp.getEventType();
          while (eventType != XmlPullParser.END_DOCUMENT)
           {
              if(eventType == XmlPullParser.START_DOCUMENT)
                {
                 stringBuffer.append(" ");
                }
            if(eventType == XmlPullParser.START_TAG)
            {
            stringBuffer.append("First Tag " + xrp.getName());
            }
         else if(eventType == XmlPullParser.TEXT)
            {
            stringBuffer.append("Second Tag "+xrp.getText());
            }
            else if(eventType == XmlPullParser.END_TAG)
            {
            stringBuffer.append("Third Tag "+xrp.getName());
           }

            eventType = xrp.next();
          }
           stringBuffer.append("\n--- End XML ---");
        return stringBuffer.toString();

    }

my xml file

<?xml version="1.0" encoding="utf-8" ?>
<Books>
  <Number id ="1">
    <Description>This is science book.
    </Description>
  </Number> 
  <Number id = "2">
    <Description>This is about cooking.
   </Description>
  </Number>
</Books> 
  • 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-05-22T17:28:56+00:00Added an answer on May 22, 2026 at 5:28 pm

    Heer is the code…..

    private String getEventsFromAnXML()throws IOException,XmlPullParserException
    
    {
           String attVal = null;
           String desc = null;
            String startTag = null;
           Resources res = this.getResources();
           XmlResourceParser xrp = res.getXml(R.xml.book);
           xrp.next();
    
         int eventType = xrp.getEventType();
          while (eventType != XmlPullParser.END_DOCUMENT)
           {
    
             if(eventType == XmlPullParser.START_TAG){
    
                startTag = xrp.getName();
                if(startTag.equals("Number")){
                 attVal =  xrp.getAttributeValue(0); 
                }   
            }
         else if(eventType == XmlPullParser.TEXT){
    
               if(startTag.equals("Description") && attVal.equals("2"))
                 desc =  xrp.getText(); 
            }
            else if(eventType == XmlPullParser.END_TAG)
            {
            }
            eventType = xrp.next();
          }
        return desc;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following unorderered list code which displays the list below: <ul> <li
I have the code below which is supposed to check the database for entries
In the code below (which shows all my neophyteness in Python), I took the
Currently i'm using below code which works well. $(#topperAtBaseLevel:visible, #lowerAtBaseLevel:visible, #midAtBaseLevel).hide(); any optimised code?
Can anyone help me to rewrite the below code which use a fade effect
Which code snippet will give better performance? The below code segments were written in
Below is my code which I am trying to find 'Username Ok' in the
So far i have got the code below which works lovely when trying an
I created a DatePicker user control (ASP code below, no code behind) which is
Below I present you some code which has completely been butchered by me. $(.gig).hover(function()

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.