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

  • Home
  • SEARCH
  • 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 8464917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:53:37+00:00 2026-06-10T14:53:37+00:00

I am reading from an XML file using XML Parser. XML Parser is reading

  • 0

I am reading from an XML file using XML Parser.

XML Parser is reading the first line as null and then returns other data from the xml file so created.

Following is the XML Parsing Code:

XmlResourceParser parser = getResources().getXml(R.xml.contacts);

        int eventType = -1;
        try {
            while (eventType != XmlResourceParser.END_DOCUMENT) 
            {
                if(eventType == XmlResourceParser.START_TAG) 
                {
                    if(parser.getName().toString().equals("contact") && parser.getName().toString().equals("null"))
                        col.append(parser.getAttributeValue(null, "name") + "\n");
                        col.append(parser.getAttributeValue(null, "phone") + "\n \n");
                }
                eventType = parser.next();
            }
        }
        catch (XmlPullParserException e) {

            e.printStackTrace();
        }

Following is the XML File:

<?xml version="1.0" encoding="utf-8"?>
<contacts>
    <contact name="Prathama Blood Center" phone="079 26600101" />
    <contact name="Green Cross" phone="079 25507013"/>
    <contact name="Crossworld Blood Bank" phone="079 26568004"/>
    <contact name="Adarsh Voluntary Blood Bank" phone="079 22746672"/>
    <contact name="Red Cross" phone="079 27551790"/>
</contacts>

Following is the Screen I am getting:

enter image description here

  • 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-10T14:53:39+00:00Added an answer on June 10, 2026 at 2:53 pm

    Right now the scope of your if only extends to the first col.append I’m not sure why you need that if statement (because its never true) Here’s what the scope should be:

    if(parser.getName().toString().equals("contact") && parser.getName().toString().equals("null"))
    { //here
        col.append(parser.getAttributeValue(null, "name") + "\n");
        col.append(parser.getAttributeValue(null, "phone") + "\n \n");
    }//and here 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading data from XML file using from..select linq query, the data is
I planning on reading profile data from a xml file in JSP. Now i
I'm reading from a binary data file which is written by invoking the following
I am reading HTML files from a folder using xml parser that store the
I am having a xml file and i am reading the data from that
I am currently using SimpleXML to reading an xml file to generate my first
I'm reading XML file using Etree module. Im using following code to print the
My asp.net web application is reading and decrypting the password from a XML file
I am reading data from XML like this: (Contacts.xml) <?xml version=1.0 encoding=utf-8 standalone=yes?> <!--LINQ
what is the best way of reading xml file using linq and the below

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.