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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:54:44+00:00 2026-06-13T05:54:44+00:00

I am new to this parse using SAX. Ive manage to use this code

  • 0

I am new to this parse using SAX. Ive manage to use this code to get the returned xml and bind it on my getter setter.

My Code:

try {

        /**
         * Create a new instance of the SAX parser
         **/
        SAXParserFactory saxPF = SAXParserFactory.newInstance();
        SAXParser saxP = saxPF.newSAXParser();
        XMLReader xmlR = saxP.getXMLReader();


        URL url = new URL(""); // URL of the XML

        /** 
         * Create the Handler to handle each of the XML tags. 
         **/
        XMLHandler myXMLHandler = new XMLHandler();
        xmlR.setContentHandler(myXMLHandler);
        xmlR.parse(new InputSource(url.openStream()));

    } catch (Exception e) {
        System.out.println(e);
    }

    data = XMLHandler.data;

Now my question is, how can I pass parameters on my php url. Cause on my PHP file I needed some data so that I could validate if it is valid or not.

Let say I need the Username of the person logged on the phone?

On DOM approach I could do something like this

XMLParser parser2 = new XMLParser(); 
    parser2.getXmlFromUrl(URL_FBFRIEND); 

      //HTTP POST
      String url_Getmembermob= URL_FBFRIEND ;
      //String xml_getMembermob=null;
      try {
      HttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost(url_Getmembermob);

      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4); 
      nameValuePairs.add(new BasicNameValuePair("blah", "blah"));
      nameValuePairs.add(new BasicNameValuePair("blah", "blah"));
      nameValuePairs.add(new BasicNameValuePair("blah", "blah"));
      nameValuePairs.add(new BasicNameValuePair("blah", "blah"));

      //Log.i("nameValuePairs", "nameValuePairs=" + nameValuePairs);

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse httpResponse = httpclient.execute(httppost);

        HttpEntity httpEntity = httpResponse.getEntity();

        FBFRIENDS = EntityUtils.toString(httpEntity);
  • 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-13T05:54:44+00:00Added an answer on June 13, 2026 at 5:54 am

    SAX is a push parser. This means that it goes through an XML document, generates events based on it and pushes them forward for you to handle. It does not create an object tree like DOM. But it can help you create a custom object or an object hierarchy of your choice with much less of a memory footprint.

    Generated SAX events could be like “uh! oh! I’ve just hit an element openening tag”, “alrighty! I’ve hit an attribute” or “characters! dear god, I’ve located a text value”. An event is usually generated for each XML construct found in the XML document being parsed but not all of them need to be handled. What gets handled is specified by an implementation of a handler (it’s set using setContentHandler(myXMLHandler) in your example).

    In order to get specific XML content you need to implement or use an implementation of a specific handler. Your example uses an implementation called XMLHandler. I don’t know if you yourself implemented it or it’s just some default implementation. From the looks of it it just copies entire content of an XML document into a String member which is not really what you want to do with SAX (DOM will do that better for you).

    What you need to do now is to create an object with the data you require by implementing a handler. Here’s an example (instead of just printing stuff, you should build objects the way you see fit):

    public class DummyHandler extends DefaultHandler{
        @Override
        public void characters(char[] ch, int start, int length)
                throws SAXException {
            super.characters(ch, start, length);
            System.out.println("characters! dear god, I've located a text value");
        }
    
        @Override
        public void endElement(String uri, String localName, String name)
                throws SAXException {
            super.endElement(uri, localName, name);
            System.out.println("an element was ended. may it R.I.P. o7");
        }
    
        @Override
        public void startElement(String uri, String localName, String name,
                Attributes attributes) throws SAXException {
            super.startElement(uri, localName, name, attributes);
            System.out.println("uh! oh! I've just hit an element openening tag");
        }
    }
    

    See here for more details.

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

Sidebar

Related Questions

I am using this code to parse this date. It must show new date
I have this code snippet: DateFormat formatter1; formatter1 = new SimpleDateFormat(mm/DD/yyyy); System.out.println((Date)formatter1.parse(08/16/2011)); When I
I am trying to parse an XML file using the SAX interface of libxml2
I am using SAX to parse an XML file I'm pulling from the web.
I've got an XML::SAX::Base-based parser that looks something like this: package MyParser; use base
I'm parsing an RSS feed using SAX messages = parser.parse(); List<String> titles = new
I am using SAX to parse XML files. Let's suppose that I want my
I am using a SAX XML Parser to get values out of a XML
I'm trying to learn how to parse an xml file using SAX parser in
I am trying to parse an xml file using SAX with Android 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.