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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:49:54+00:00 2026-05-26T15:49:54+00:00

1st activity package com.example.parserss; import java.net.URL; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.InputSource; import org.xml.sax.XMLReader;

  • 0

1st activity

package com.example.parserss;

import java.net.URL;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;


public class Parserss extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);

        try {
            URL url = new URL("http://www.w3schools.com/xml/note.xml");
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            xr.parse(new InputSource(url.openStream()));
            MHandler mhandler = new MHandler();
            xr.setContentHandler(mhandler);
            getValue getV = mhandler.getData();
            tv.setText(getV.toString());
        }
        catch(Exception e) {
            System.out.println("Exception Occured :" + e );
        }

       this.setContentView(tv);


    }
}

2nd activity

package com.example.parserss;


import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class MHandler extends DefaultHandler {
    Boolean outerElement = false;
    Boolean innerElement = false;

    private getValue getvalue = new getValue();

    public getValue getData() {
        return getvalue;
    }

     public void startDocument() throws SAXException {
         getvalue = new getValue();
 }

 @Override
 public void endDocument() throws SAXException {
         // Nothing to do
 }




   public void startElement(String uri , String localName , String qName, Attributes attr) throws SAXException {


       if(localName.equals("note")) {
           outerElement = true;

       }
       else if(localName.equals("to")) {
           innerElement = true;

       }
   }
   public void endElement(String uri, String localName, String qnqme) throws SAXException {

       if(localName.equalsIgnoreCase("note")) {
           outerElement = false;
          }
       else if (localName.equals("body")) {
           innerElement = false;
       }



   }
   public void characters(char[] ch , int start, int length) throws SAXException {
       if(innerElement){
           getvalue.setStringss(new String(ch, start, length));


       }

   }
}

3rd activity

package com.example.parserss;

public class getValue {
    private String exData = null;
    public String getStringss() {
        return  exData;
    }
    public void setStringss(String exData) {
        this.exData = exData;

    }
    public String toString() {
        return "data = " + exData;
    }
}
  • 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-26T15:49:55+00:00Added an answer on May 26, 2026 at 3:49 pm

    I got the solution. Actually I was parsing the stream first and then creating the object of handler class which was wrong. First we have to create the object of handler class and then parse the stream and it worked.

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

Sidebar

Related Questions

For the 1st example given on site: View-Site , my understanding is that normal
I am having 2 activities: 1st Activity contains 2 arrays which are filled up
I have 3 activities. 1st activity has a 'go right' image button. (to move
I am trying to send the events from one Java class to Activity. Scenario
1st phase I have a problem shutting down my running JBoss instance under Eclipse
1st post on stackoverflow, hope to have great feedback :) I'm currently trying to
1st disclaimers: I'm not a programmer, never was had never been taught higher math
1st I have to say I know nothing bout php. I was actually doing
Ok thanks for the 1st guy I found the code. Machine.Migrations: I mean, the
I have 2 tables: 1st holds employees (of ones in any position) and the

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.