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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:56:03+00:00 2026-05-20T00:56:03+00:00

I parse XML data and put it into an object. This takes fairly long

  • 0

I parse XML data and put it into an object. This takes fairly long and I have decided to run it in the background using AsyncTask. My code is almost exactly like this example:
How to get XML using AsyncTask and Timer?

The difference being that I want to PublishProgress as I go long. The relevant part of the code where I want to publish progress:

@Override   
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {       
        if (localName.equalsIgnoreCase("client")) {         
            clients.addClient(mClient);
            // Publish Progress
            RotationAwareTask.publishProgress();
            mClient = null;
        }       
    }

By now you would have deduced that I am a novice. The closest research that matches what I want to do states:

http://www.mail-archive.com/android-developers@googlegroups.com/msg79275.html

Yes, that is a bit more complex… Two
approaches:

1) Make AsyncTask implement
org.sax.ContentHandler. That way the
SAX callbacks have direct access to
AsyncTask.publishProgress().

2) Create a delegate so that the
parser has a handle back to AsyncTask
for posting progress updates.

When I try the above I get:

The method
publishProgress(Progress…) from the
type AsyncTask is
not visible

Alas, how can I call publicProgress from endElement? Or could someone give me some how to do this properly? To recap:

I have XML data.
Reading the data is a long operation.
I use the SAXParser to get the data.
On the endElement method the data is added to an object which will eventually be used elsewhere.
Most research indicates I have to use AsyncTask and I am using that now because I have a good example from Commonsware for screen rotation.
The question is how to update progress as I go along.

Edit:
@Cristian here is the async task:

static class RotationAwareTask extends AsyncTask<Void, Void, Void> {        
        RotationAsync activity = null;      
        int progress = 0;       

        private SaxClientsHandler saxClientsHandler;

        RotationAwareTask(RotationAsync activity) {
            attach(activity);
        }

            @Override
        protected Void doInBackground(Void... unused) {         
            try {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();
                saxClientsHandler = new SaxClientsHandler();
                xr.setContentHandler(saxClientsHandler);
                InputSource mSource = new InputSource( new StringReader( Whmcs.getClientsXml() ) );
                xr.parse(mSource);          
            } catch (Exception e) {
                Log.e(TAG, e.getMessage(), e);
            }           
            return(null);       
        }

        @Override
        protected void onProgressUpdate(Void... unused) {
            if (activity==null) {
                Log.w("RotationAsync", "onProgressUpdate() skipped – no activity");
            }
            else {
                progress += 5;
                activity.updateProgress(progress);
            }
        }

        @Override
        protected void onPostExecute(Void unused) {
            if (activity == null) {
                Log.w("RotationAsync", "onPostExecute() skipped – no activity");
            }
            else {
                activity.markAsDone();
            }
        }

        void detach() {
            activity = null;
        }

        void attach(RotationAsync activity) {
            this.activity = activity;
        }

        int getProgress() {         
            return(progress);
        }

    }

This is almost an exact duplicate of this Commonsware example:
https://github.com/commonsguy/cw-android/blob/master/Rotation/RotationAsync/src/com/commonsware/android/rotation/async/RotationAsync.java

As you can see:

saxClientsHandler = new
SaxClientsHandler();

calls the SaxClientHandler() where the endElement method exists. I am trying to publish the progress from there.

@Mayra, are you suggesting that I migrate all the saxClientHandler code into the AsyncTask?

  • 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-20T00:56:03+00:00Added an answer on May 20, 2026 at 12:56 am

    You are doing RotationAwareTask.publishProgress(); publishProgress is not a static method, you need to call it on the instance of RotationAwareTask.

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

Sidebar

Related Questions

I'm using TinyXML to parse/build XML files. Now, according to the documentation this library
I am trying to unmarshall data from an XML object in Java using SimpleXML.
I have to parse a XML structure in JAVA using the SAX parser. The
I'm using the SAX xml parser to parse some xml data which contains newlines.
When I parse my xml file (variable f) in this method, I get an
I'm using XPath in .NET to parse an XML document, along the lines of:
I am using XmlReader in .NET to parse an XML file using a loop:
I am using JAXP to generate and parse an XML document from which some
I'm looking for the best method to parse various XML documents using a Java
Lately I've been using XPathDocument and XNavigator to parse an XML file for a

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.