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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:26:17+00:00 2026-05-22T17:26:17+00:00

i need to get information from xml file. my problem is i cant get

  • 0

i need to get information from xml file.
my problem is i cant get proper response from xml file

package com.xmlparser;

import java.net.URL;
import java.util.ArrayList;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class xmlparser extends Activity {
    /** Called when the activity is first created. */
     detaset dt=null;
     detaset  Date;
     ArrayList<String>  Score;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       try
       {
        URL url = new URL("C://Users//nik//Desktop//a.xml");
        System.out.println(url);
        TextView tv = new TextView(this);
        /* Get a SAXParser from the SAXPArserFactory. */
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();

        /* Get the XMLReader of the SAXParser we created. */
        XMLReader xr = sp.getXMLReader();
        /* Create a new ContentHandler and apply it to the XML-Reader*/
        Handler myExampleHandler = new Handler();
        xr.setContentHandler(myExampleHandler);

        /* Parse the xml-data from our URL. */
        xr.parse(new InputSource(url.openStream()));
        /* Parsing has finished. */

        /* Our ExampleHandler now provides the parsed data to us. */
        detaset parsedExampleDataSet = myExampleHandler.getParsedData();

        /* Set the result to be displayed in our GUI. */
        System.out.println(parsedExampleDataSet.toString());

       // Date  = myExampleHandler.getParsedData();


        //System.out.println(Date);
        this.setContentView(tv);


       }catch (Exception e) {
        e.printStackTrace();
    }
       }
    // TODO: handle exception

/* Display the TextView. */


    }

package com.xmlparser;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


public class Handler extends DefaultHandler{

        // ===========================================================
        // Fields
        // ===========================================================

        private boolean NewDataSet  = false;
        private boolean Table = false;
        private boolean Date = false;
        private boolean Score = false;

        private detaset myParsedExampleDataSet = new detaset();

        // ===========================================================
        // Getter & Setter
        // ===========================================================

        public detaset getParsedData() {
                return this.myParsedExampleDataSet;
        }

        // ===========================================================
        // Methods
        // ===========================================================
        @Override
        public void startDocument() throws SAXException {
                this.myParsedExampleDataSet = new detaset();
        }

        @Override
        public void endDocument() throws SAXException {
                // Nothing to do
        }

        /** Gets be called on opening tags like:
         * <tag>
         * Can provide attribute(s), when xml was like:
         * <tag attribute="attributeValue">*/
        @Override
        public void startElement(String namespaceURI, String localName,
                        String qName, Attributes atts) throws SAXException {
                if (localName.equals("NewDataSet")) {
                        this.NewDataSet = true;
                }else if (localName.equals("Table")) {
                        this.Table = true;
                }else if (localName.equals("Date")) {
                        this.Date = true;
                }else if (localName.equals("Score")) {
                        // Extract an Attribute
                       this.Score = true;
                                        }
        }

        /** Gets be called on closing tags like:
         * </tag> */
        @Override
        public void endElement(String namespaceURI, String localName, String qName)
                        throws SAXException {
                if (localName.equals("NewDataSet")) {
                        this.NewDataSet = false;
                        System.out.println("Newdataset"+NewDataSet);
                }else if (localName.equals("Table")) {
                        this.Table = false;
                        System.out.println("Table"+Table);
                }else if (localName.equals("Date")) {
                        this.Date = false;
                }else if (localName.equals("Score")) {
                        // Nothing to do here
                    this.Score = false;
                    System.out.println("Score"+Score);
                }
        }

        /** Gets be called on the following structure:
         * <tag>characters</tag> */
        @Override
    public void characters(char ch[], int start, int length) {
                if(this.Date){
                myParsedExampleDataSet.setDate(new String(ch, start, length));
                }
                if(this.Score){
                    myParsedExampleDataSet.setScore(new String(ch, start, length));
                    }

        }





    }

package com.xmlparser;
public class detaset {
    private String Date =  null;
    private String Score = null;




     public void setDate(String Date) {
            this.Date = Date;
        }
        public String getDate()
        {
            return Date;
        }


        public void setScore(String Score) {
            this.Score = Score;
        }
        public String getScore()
        {
            return Score;
        }








}




<?xml version="1.0" encoding="utf-8" ?> 
- <DataSet xmlns="http://tempuri.org/">
- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="Table">
- <xs:complexType>
- <xs:sequence>
  <xs:element name="Date" type="xs:string" minOccurs="0" /> 
  <xs:element name="Score" type="xs:string" minOccurs="0" /> 
  </xs:sequence>
  </xs:complexType>
  </xs:element>
  </xs:choice>
  </xs:complexType>
  </xs:element>
  </xs:schema>
- <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
- <NewDataSet xmlns="">
- <Table diffgr:id="Table1" msdata:rowOrder="0">
  <Date>12/5/2011</Date> 
  <Score>5</Score> 
  </Table>
- <Table diffgr:id="Table2" msdata:rowOrder="1">
  <Date>45/5/2011</Date> 
  <Score>54</Score> 
  </Table>
  </NewDataSet>
  </diffgr:diffgram>
  </DataSet>
  • 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-22T17:26:18+00:00Added an answer on May 22, 2026 at 5:26 pm

    I think the mistake is in the line URL url = new URL("C://Users//nik//Desktop//a.xml");

    You will run the program in emulator or in device there is no such path in either device or emulator. You can put the xml file in assets and read the file from there.

    Donot forget to vote if my response is helpful for you.

    Thanks

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

Sidebar

Related Questions

I need to get the File version information from an exe file originally written
I was wondering if anyone knows how to get information from an XML file
I need to extract information from iTunes Music Library.xml file. Since the xml is
I desperately need to be able to get some information from the request array
I need to get the version information of a DLL file I created in
Below is the information I receive from DB. It's originally from an XML file,
How could I GET the information in an XML file and read it into
Greetings I'm trying to get an xml file from a website which requires me
I need to get information about applied CSS styles in HTML page. I used
I need to get some information that is contained in the MFT on 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.