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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:46:31+00:00 2026-06-11T08:46:31+00:00

I am using a SAX XML Parser to get values out of a XML

  • 0

I am using a SAX XML Parser to get values out of a XML file that works fine. This is the method in my main activity:

public void parseXML() {

    String parsedData = "";

    try {

        Log.w("AndroidParseXMLActivity", "Start");
        /** Handling XML */
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();

        XMLContentHandler myXMLHandler = new XMLContentHandler();
        xr.setContentHandler(myXMLHandler);

        AssetManager assetManager = getAssets();
        InputStream inputStream = null;
        try {
            inputStream = assetManager.open("calimero.xml");
        } catch (IOException e) {
            Log.e("tag", e.getMessage());
        }
        xr.parse(new InputSource(inputStream)); 

        ArrayList<Datapoint> itemsList = myXMLHandler.getItemsList();
        int datapoint_size = itemsList.size();
        String xml_names[]  = new String [datapoint_size];
        String xml_states[]  = new String [datapoint_size];
        String xml_dptIDs[] = new String [datapoint_size];
        String xml_groupadresses[]  = new String [datapoint_size];
        String xml_mainNumbers[]  = new String [datapoint_size];

        for(int i=0;i<itemsList.size();i++){
            Datapoint item = itemsList.get(i);
            parsedData = parsedData + "----->\n";
            parsedData = parsedData + "Name: " + item.getName() + "\n";
            xml_names[i] = item.getName();
            parsedData = parsedData + "stateBased: " + item.getStateBased() + "\n";
            xml_states[i] = item.getStateBased();
            parsedData = parsedData + "mainNumber: " + item.getMainNumber() + "\n";
            xml_mainNumbers[i] = item.getMainNumber();
            parsedData = parsedData + "dptID: "+ item.getDptID() + "\n";
            xml_dptIDs[i] = item.getDptID();
            parsedData = parsedData + "Groupadress: "+ item.getGroupadress() + "\n";
            xml_groupadresses[i] = item.getGroupadress();
        }
        Log.w("AndroidParseXMLActivity", "Done");
    }
    catch (Exception e) {
        Log.w("AndroidParseXMLActivity",e );
    }
    Log.w("AndroidParseXMLActivity", names[0]);
    Log.w("AndroidParseXMLActivity", mainNumbers[2]);
    Log.w("AndroidParseXMLActivity", dptIDs[3]);
    //xmlOutput.setText(parsedData);
}

I want to use the values like name, mainNumber and so on outside my method. But I don’t get it… I know this are java basic….
Please help me, thanks!

  • 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-11T08:46:32+00:00Added an answer on June 11, 2026 at 8:46 am

    If you want to use your String array in the whole class you have to define it in the class. Then the variable are avaliable for all functions in your class.

        public class Test {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            StringArray testString = new StringArray();
            testString.setArray();
            testString.printArray();
        }
    
        static private class StringArray{
            String test[];
    
            public void setArray(){
                test = new String[5];
                for (int i = 0 ; i < test.length; i++){
                    test[i] = "test";
                }
            }
    
            public void printArray(){
                for (int i = 0 ; i < test.length; i++){
                    System.out.println(test[i]);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have student.xml file and am parsing this file using SAX Parser and now
I have a problem with using the SAX parser to parse a XML file.
i parsed my xml file successfully using sax parser.my doubt is how to convert
I'm writing out some xml from C# using the .net framework's XmlTextWriter. This works
I download an XML-file, I generate using PHP, that looks similar to this <?xml
I want to extract attributes from an xml file using Sax Parser I am
hi friends i'm using Sax parser for parsing my xml file which i recieve
I'm using sax parser to get xml data, the below code is causing my
I am begginer to android development. I am using SAX parser for xml parser.
In my application, I am parsing XML data using SAX Parser. But, I want

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.