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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:43:22+00:00 2026-06-07T12:43:22+00:00

I am using a SAX Parser for an android app I am working on

  • 0

I am using a SAX Parser for an android app I am working on and I am having a hard time trying to save the name tag of Project from being overwritten. The problem here is that my name tag within the project is getting overwritten by the name tag within license since the tags are identical. The rest is getting parsed beautifully. Also, this xml is being generated by passing a GET Request to an API, so I can’t edit it. Is there a way to maybe omit the name tag within the license field or maybe try to get a sense of where I’m at inside the document which is a problem since SAX is even driven. Also, I realize that I could accomplish this pretty easily using DOM but I have come way too far now to switch to DOM. I’ve attached snippets of my XML Handling code and the xml file I am trying to parse.

Thanks

@Override
public void startElement (String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException 
{
    buffer.setLength(0);

    if (localName.equalsIgnoreCase("result"))
    {
        results = new ArrayList <Result> ();
    }

    if (localName.equalsIgnoreCase("project"))
    {
        result = new Result ();
    }

    if (localName.equalsIgnoreCase("name"))
    {
        result.name = buffer.toString ();
        Log.v("PROJECT NAME: ", result.name);
    }
} // end of startElement ()

@Override
public void endDocument () throws SAXException
{}

@Override
public void endElement (String namespaceURI, String localName, String qName) throws SAXException
{       
    if (localName.equalsIgnoreCase("project") || localName.equalsIgnoreCase("account"))
    {
            this.entries++;
            results.add(result);
    }

    else if (localName.equalsIgnoreCase("id"))
    {
        result.id = buffer.toString ();
        Log.v("Id: ", result.id);
    }

    else if (localName.equalsIgnoreCase("created_at"))
    {
        try 
        {
            result.date_created = ResultHandlerProject.DATE_FORMAT.parse(buffer.toString());
        } 
        catch (ParseException e) 
        {
            e.printStackTrace();
        }
    }

    else if (localName.equalsIgnoreCase("updated_at"))
    {
        try 
        {
            result.date_updated = ResultHandlerProject.DATE_FORMAT.parse(buffer.toString());
        } 
        catch (ParseException e) 
        {
            e.printStackTrace();
        }
    }

    else if (localName.equalsIgnoreCase("description"))
    {
        result.description = buffer.toString ();
    }

    else if (localName.equalsIgnoreCase("homepage_url"))
    {
        result.url_homepage = buffer.toString ();
    }

    else if (localName.equalsIgnoreCase("download_url"))
    {
        result.url_download = buffer.toString ();
    }

    else if (localName.equalsIgnoreCase("medium_logo_url"))
    {
        result.image_link = buffer.toString ();
    }

    else if (localName.equalsIgnoreCase("user_count"))
    {
        result.user_count = buffer.toString ();
    }

    else if (localName.equalsIgnoreCase("average_rating"))
    {
        result.rating = buffer.toString ();
    }

    else if (localName.equalsIgnoreCase("rating_count"))
    {
        result.rating_count = buffer.toString ();
    }

    else if (localName.equalsIgnoreCase("analysis_id"))
    {
        result.analysis_id = buffer.toString ();
    }

    else if (localName.equalsIgnoreCase("nice_name"))
    {
        result.license_full_name = buffer.toString ();
        Log.v("License Full Name: ", result.license_full_name);
    }

} // end of endElement ()

Sample XML File:

<result>
<project>
<id>6050</id>
<name>FirePHP</name>
<created_at>2007-06-16T04:03:13Z</created_at>
<updated_at>2012-07-01T15:05:23Z</updated_at>
<description>
FirePHP 
<homepage_url>http://www.firephp.org/</homepage_url>
<download_url>http://www.firephp.org/</download_url>
<url_name>FirePHP</url_name>
<medium_logo_url>
https://s3.amazonaws.com/cloud.ohloh.net/attachments/6638/FirePHP_Large_White_med.png
</medium_logo_url>
<small_logo_url>
https://s3.amazonaws.com/cloud.ohloh.net/attachments/6638/FirePHP_Large_White_small.png
</small_logo_url>
<user_count>145</user_count>
<average_rating>4.11765</average_rating>
<rating_count>34</rating_count>
<analysis_id>8910317</analysis_id>
<licenses>
<license>
<name>bsd</name>
<nice_name>BSD Copyright</nice_name>
</license>
</licenses>
</project> 
  • 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-07T12:43:27+00:00Added an answer on June 7, 2026 at 12:43 pm

    You can resolve your issue in a simple way.

    1. Create some flags into your class handler.

      private boolean inProject = false;
      private boolean inLicense = false;
      
    2. Control these flags like I show you below.

         @Override
         public void startElement (String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException 
         {
            if (localName.equalsIgnoreCase("project")) {
                 this.inProject = true;
            }
            else if (localName.equalsIgnoreCase("license")) {
                 this.inLicense = true;
            }
         }
      
         @Override
         public void endElement (String namespaceURI, String localName, String qName) throws SAXException
         {       
             if (localName.equalsIgnoreCase("name") {
                 if(inProject) { 
                    //Set your project name here.
                    this.inProject = false;
                 }
                 else if (inLicense) {
                    //Set your lencense name here.
                    this.inLicense = false;
                 }
             }
          }
      

    Let me know if it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to parse this ( http://app.calvaryccm.com/mobile/android/v1/devos ) URL using a SAX
I am building an Android app that parses an RSS feed using SAX parser.
I trying to parse xml from an inputstream using the sax parser. The inputstream
I am begginer to android development. I am using SAX parser for xml parser.
i try to parse an rdf file using android.sax and android.utils.Xml methods. My parser
I'm trying to parse a file from the web on Android using the DOM
I am trying to parse XML in Perl using XML::SAX parser . My query
I am using SAX Parser to parse XML data from a http url. I
I'm using SAX parser in my Android application to read a few feeds a
I want to extract attributes from an xml file using Sax Parser I am

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.