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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:19:19+00:00 2026-05-24T20:19:19+00:00

First off all I didn’t find better title for my question, so please update

  • 0

First off all I didn’t find better title for my question, so please update if you have some words.

What I am doing :

In current I am sending two request for this purpose(One for user validation, another for data, if user is authorised). But I want to use single request.

What I want :

I will send a request as POST method to server where server will send a XML as response depends on my request.

For example :

  • I am sending user and password to server.
  • Server authenticate that user.
  • If user authorised, server sends response xml as

    enter image description here

  • If authentication failed, server sends response as

enter image description here

Problem I faced :

I am not able to handle XML data, actually not identify the xml data.

I am using android.sax parser and I created two parser classes for both type of xml response, But how can I identify which parser class should I use depends on response?

Update :

Here is my actual xml

enter image description hereenter image description here

So how can I parse it, using single parser?

  • 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-24T20:19:20+00:00Added an answer on May 24, 2026 at 8:19 pm

    I would use a data structure which allows for the parser to see if it has failed or not.
    Example:

    public class XMLResponse {
     private boolean hasFailed;
     private Employee employee;
     public void setFailure(boolean in) {
        this.hasFailed=in;
     }
     public void setEmployee(Employee in) {
        this.employee=in;
     }
    }
    

    And in your parser, see if the response is false or not. This is based on the fact that your response from the webservice does not contain the response tag if its successful.

    Here is an example of a parser, might need some tweaks before it can be used. It is only useful if you only get 1 employee in your response, otherwise you need to use a list.

    public class XMLHandler extends DefaultHandler {
    private XMLResponse myResponse;
    private Employee employee;
    public XMLResponse getParsedData() { 
        return this.myResponse;
    }
    @Override
    public void startDocument() throws SAXException {
        myResponse = new XMLResponse();
        employee = new Employee();
    }
    
    @Override
    public void startElement(String namespaceURI, String localName,
    
            String qName, Attributes atts) throws SAXException {
        buffer = new StringBuffer();
        if(localName.equals("employee")) {
            employee.setId(atts.getValue("id"));
        }
    }
    @Override
    
    public void endElement(String namespaceURI, String localName, String qName)
    
    throws SAXException {
    
        if(localName.equals("response")) {
            if(buffer.toString().contains("failure")) {
                myResponse.setFailure(true);
            }
        }
        else if(localName.equals("info")) {
            /*
             * This is only an example, could bee employee or whatever. You should use the startElement to get the tag. 
             */
        }
        else if(localName.equals("name")) {
            employee.setName(buffer.toString());
        }
        else if(localName.equals("age")) {
            employee.setAge(buffer.toString());
        }
        else if(localName.equals("employee")) {
            myResponse.setEmployee(employee);
        }
    
    
    }
    
    /** Gets be called on the following structure:
    
     * <tag>characters</tag> */
    
    
    StringBuffer buffer;
    @Override
    public void characters(char ch[], int start, int length) {
    
        buffer.append(ch,start,length);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, please bear with the question as I am just starting out with
First off, I am using Windows XP. I have multiple hard drives and it
First off, I'm working on an app that's written such that some of your
First off, this question is ripped out from this question. I did it because
First off I am pretty new to C, so I probably just have a
Ok, let me get some things out of the way first. I have OWNERSHIP
first off what's the difference between javascript_include_tag :all and javascript_include_tag :defaults Lastly, I previously
First off, I read all of the suggested questions that sounded halfway relevant and
First off, the jQuery datepicker works fine with classes when doing a fresh page
First off, I apologize if I'm not using the right terms in my question

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.