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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:48:10+00:00 2026-05-21T18:48:10+00:00

What got me to this point: I wrote an XML web service that provides

  • 0

What got me to this point:

I wrote an XML web service that provides data from a CRM that is stored in a database. The purpose of the XML web service is so I can provide a limited set of data read-only to the outside world in a format that is easy for other applications to connect to and read from. (or so I thought).

My Specific Question:

I need to write an application in Android that can parse XML from this web service and present it to my user in a native application. What is the recommended way to connect to a web-site and pull it’s XML down and parse it into an object?

Notes:

I cannot show you an example of the XML because the test server currently is not Internet facing (it will be soon enough). I am also not worried about the GUI development. I will tackle that after I get the data to the handset =).

  • 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-21T18:48:11+00:00Added an answer on May 21, 2026 at 6:48 pm

    Here is some SAX code from one of our Android apps.

    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    //. . .
    public class MyXmlHandler extends DefaultHandler
    {
        @Override
        public void startDocument()
        {
            Log.i(TAG,"Starting to parse document.");
        }
        @Override
        public void endDocument()
        {
                Log.i(TAG,"End of document.");
        }
        @Override
        public void startElement(String uri,String localName,String qName,Attributes attributes)
        {
            if(localName.equals("myxmltag"))
            {
                     //do something with myxmltag and attributes.
            }
        }    
    }    
    public void parseDocument()
    {
        try {
             URL myxmlUri = new URL("file:///sdcard/appfolder/myxmldoc.xml");
             SAXParserFactory spf = SAXParserFactory.newInstance();
             SAXParser sp = spf.newSAXParser();
             XMLReader xr = sp.getXMLReader();
             MyXmlHandler myxmlhandler = new MyXmlHandler();
             xr.setContentHandler(myxmlhandler);
             InputSource inputs = new InputSource(myxmlUri.openStream());
             xr.parse(inputs);
             // . . . 
    

    And the download code it has

    private void downloadFile(String url, String destination) throws ParserConfigurationException, FileNotFoundException, SAXException, UnsupportedEncodingException, ClientProtocolException, IllegalStateException, IOException {
        if(isNetworkAvailable(this)){
            HttpClient client = new DefaultHttpClient();
            HttpGet get = new HttpGet(url);
            MultipartEntity reqEntity = new  MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            get.setHeader("user_id", user_id);
            reqEntity.addPart("user_id", new StringBody(user_id));
            HttpResponse response = client.execute(get);  
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
                String serverResponse = EntityUtils.toString(resEntity);
                BufferedWriter out = new BufferedWriter(new FileWriter(destination));
                out.write(serverResponse);
                out.close();
            }
        }
    }
    

    And isNetworkAvailable

    public static boolean isNetworkAvailable(Context context)
    {
        ConnectivityManager connectivity = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity == null) {
            Log.w("tag", "Connectivity Manager failed to retrieve.");
        } else {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null) {
                for (int i = 0; i < info.length; i++) {
                    if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    

    You probably want to edit downloadFile so there is some consequence if isNetworkAvailable returns false.

    EDIT: I removed some code that may have been in your way. I gave everything a generic name that starts with “my” instead of what was in my code.

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

Sidebar

Related Questions

Here's what I got so far (that doesn't work). At this point I thought
I'm not sure I wrote the headline right, but I've got a service that
ive got an object that looks like this with print_r(): SimpleDOM Object ( [0]
Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;
I've got a project that I'd like to move the testing from rhino to
I call a .Net web service from my Blackberry app. After having nothing but
I want to write a function that parses a (theoretically) unknown XML data structure
I've got some code that needs to scan through a hierarchical database schema, looking
I've got some code (that someone else wrote): def render(self, name, value, attrs=None): if
I've got this little class I wrote to try playing with custom __getattr__ methods,

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.