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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:04:31+00:00 2026-06-08T06:04:31+00:00

this code parses a locally stored xml file and then creates a dynamic UI

  • 0

this code parses a locally stored xml file and then creates a dynamic UI from the parsed data, though i haven’t completed the UI part. It was working fine till yesterday and now suddenly it is not responding.

public class XML_PARSER extends Activity {

String TAG= "XML_PARSER";
List optionList = new ArrayList(); ;
Document dom;
Document doc;
Menu mymenu=null;

String msg=null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.parser);
    new ParseXML().execute();
   }

private class ParseXML extends AsyncTask<Integer, Integer, Document>{
    @Override
protected Document doInBackground(Integer... params) {

     DocumentBuilderFactory dbf= DocumentBuilderFactory.newInstance();
    Document dom1=null;
    try {
        //Uri uri = Uri.parse("android.resource://com.example.xml_parser/raw/options");
        InputStream is=getResources().openRawResource(R.raw.options);

        DocumentBuilder db = dbf.newDocumentBuilder();
        dom1=db.parse(is);
        Log.i(TAG,"parsing done");

    }

    catch(ParserConfigurationException pce){
        pce.printStackTrace();
    }
    catch(SAXException se){
        se.printStackTrace();
    }
    catch(IOException ioe){
        ioe.printStackTrace();
    }
    return dom1;

}
    @Override
    public void onPostExecute(Document d) {
        ParseDocument(d); 
        //onCreateOptionsMenu(mymenu);
        text();
        }



}
@SuppressWarnings("unchecked")
public void ParseDocument(Document dom){
    Element docEle = dom.getDocumentElement();
    Node node;

    NodeList n1= docEle.getElementsByTagName("Option");
    if(n1!=null && n1.getLength()>0){

        for(int i=0;i<n1.getLength();i++){

            node=n1.item(i);

            Element e1=(Element)n1.item(i);

it is somehow getting stuck at this getOption() as the log is not getting printed if written below while it is getting printed if written above it.

            Option e = getOption(e1,node);
            Log.i(TAG,"Parse Document reached");

            optionList.add(e);



            }

        }

    }

private Option getOption(Element el,Node parent){

    String name= getTextValue(el,"Name");
    String type = el.getAttribute("type");


    Option op = new Option(name,type);
    fillSubOptions(op, el, parent);

    return op;


}

private String getTextValue(Element ele, String tagName){
    String textVal=null;
    NodeList n1 = ele.getElementsByTagName(tagName);

    if(n1!=null && n1.getLength()>0){
        Element el= (Element)n1.item(0);
        textVal =el.getFirstChild().getNodeValue();

    }
    return textVal;
}


private void fillSubOptions(Option op, Element el, Node parent){
    Element ele;
    Node node;
    String name = null;
    NodeList n1 = el.getElementsByTagName("Option");
    int count =0;
    if(n1!=null && n1.getLength()>0){
        for(int i=0;i<n1.getLength();i++){
            ele = (Element)n1.item(i);
            node= n1.item(i);
            if((node.getParentNode()).equals(parent)){
                name= getTextValue(ele, "Name");
                count= op.printSubOptions(count);
                op.setSubOptions(name);
            }
        }
    }

}




@SuppressWarnings("unchecked")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    this.mymenu=menu;
    Iterator<Option> it= optionList.iterator();
    int count=0;
    while(it.hasNext()){
        Option e= (Option)it.next();
        if(e.getType().equals("menu")){
            count++;
            menu.add(0,count,0,e.getName());
        }
    }


    getMenuInflater().inflate(R.menu.parser, menu);
    return true;
}




public class Option {


    String name;
    String type;
    String parent;
    int count;
    ArrayList<String> subOptions;
    Option(String name,String type)
    {
        setName(name);
        setType(type);

        subOptions = new ArrayList<String>();
        parent = null;
    }
    public void setName(String name) {
        this.name = name;
    }

    public void setType(String type) {
        this.type = type;
    }
    public void setSubOptions(String subOption) {
        (this.subOptions).add(subOption);

    }

    public String getName() {
        return name;
    }
    public int printSubOptions(int count) {
        Iterator<String> it = (this.subOptions).iterator();
        if(it.hasNext()){

            while(it.hasNext()){

                count++;
            }
        }
        return count;


    }
    public String getType() {
        return type;

}


}
  • 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-08T06:04:32+00:00Added an answer on June 8, 2026 at 6:04 am

    As the methods called in the onPostExecuted gets the control of the UI thread,I hope that may be the cause as the parsing that you are doing is still done on the UI thread and so your application stops responding as it would be parsing the data.

    Use onPreExecute() to start the ProgressDialog like this way.Declare the ProgressDialog Globally at the Top.

    ProgressDialog pd;
    

    Start it in the onPreExecute Method.

     @Override
        public void onPreExecute() {
              pd=ProgressDialog.show(myActivity.this,"","Please Wait");
            }
    

    Call these both methods in doInBackground Itself at the Bottom.Don’t call it in the PostExecute Method so that it gets executed in the BackGround

    ParseDocument(d); 
    text();
    

    Now, in the PostExecute method,dismiss the progressDialog.

    @Override
        public void onPostExecute(Document d) {
              pd.dismiss();  //Dismiss the Progress Dialog 
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This snippet of code always parses the date into the current timezone, and not
This line of code: DateTime dt = DateTime.ParseExact(time, hh:mm, CultureInfo.InvariantCulture); parses a time value
Hi I have this code to parse JSON on JQUERY var json_text2 = $.parseJSON('{data:[[1340650436,2.00000],[1340736844,4.00000]],label:Waist
i am going through the code for xml parser, and i found this code,
I get a parse error from Safari with this code: for (var i=0; i<parent.frames.length;
I'm using a webservice to get a certain xml file from it. It works
This is the code that works, locally. $str = <<<SSS <H1 class=prodname>Alison Raffaele Reality
This code opens a directory, and for every file in the directory it loops
I am using this code to parse this date. It must show new date
I've got this code: def __parse(self): for line in self.lines: r = Record(line) self.records[len(self.records):]

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.