local parser problem in android
<p>i am make a 3 file that parse "a.xml",problem is as a result i got last line not entire parsing.
so can you help me?</p>

<pre><code>package barc3.barc3;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

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.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class barc3 extends Activity {

    private TextView orgXmlTxt;
    private TextView parsedXmlTxt;
    private Button parseBtn,chartbtn;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        try {
            setContentView(R.layout.main);
            orgXmlTxt = (TextView) findViewById(R.id.orgXMLTxt);
            parsedXmlTxt = (TextView) findViewById(R.id.parsedXMLTxt);
            parseBtn = (Button) findViewById(R.id.parseBtn);
            chartbtn =(Button) findViewById(R.id.chartbtn);
            //orgXmlTxt.setText(getOriginalMyXML());
            parseBtn.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    try {
                        parsedXmlTxt.setText(getParsedMyXML());
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        orgXmlTxt.setText(e.getMessage());
                    }
                }
            });

            chartbtn.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {

                    startActivity(new Intent(barc3.this,XMLParsingDemo.class));
                }
            });

        } catch (Exception e) {
            orgXmlTxt.setText(e.getMessage());
        }
    }



/**
     * This method is called by OnCreate during startup to show the original XML file content
     * @return
     * @throws Exception
     */
    private String getOriginalMyXML() throws Exception {
      /* Load xml file being shown from raw resource folder */
    InputStream in = this.getResources().openRawResource(R.raw.a); 
        StringBuffer inLine = new StringBuffer();
        InputStreamReader isr = new InputStreamReader(in);
        BufferedReader inRd = new BufferedReader(isr);

        String text;
        while ((text = inRd.readLine()) != null) {
            inLine.append(text);
            inLine.append("\n");
        }
        in.close();
        return inLine.toString();
    }

    private String getParsedMyXML() throws Exception {
        StringBuffer inLine = new StringBuffer();
        /* 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 */
        XMLHandler myExampleHandler = new XMLHandler();
        xr.setContentHandler(myExampleHandler);
        /* Load xml file from raw folder*/
    InputStream in = this.getResources().openRawResource(R.raw.a); 
    /* Begin parsing */
        xr.parse(new InputSource(in));
        XMLDataSet parsedExampleDataSet = myExampleHandler.getParsedData();
        String s = parsedExampleDataSet.getDate();
        String s2 = parsedExampleDataSet.getScore();
        System.out.println("s is:::::: "+s);
        System.out.println("s2 is :::::"+s2);
        System.out.println(parsedExampleDataSet);
        inLine.append(parsedExampleDataSet.toString());
        in.close();
        return inLine.toString();
    }
}
</code></pre>

<hr>

<pre><code>package barc3.barc3;

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


public class XMLHandler extends DefaultHandler{

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

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

     private XMLDataSet myParsedExampleDataSet = new XMLDataSet();

     // ===========================================================
     // Getter &amp; Setter
     // ===========================================================

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

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

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

     /** Gets be called on opening tags like:
      * &lt;tag&gt;
      * Can provide attribute(s), when xml was like:
      * &lt;tag attribute="attributeValue"&gt;*/
     @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")) {
              this.Score = true;
          }
     }

     /** Gets be called on closing tags like:
      * &lt;/tag&gt; */
     @Override
     public void endElement(String namespaceURI, String localName, String qName)
               throws SAXException {
         if (localName.equals("NewDataSet")) {
             this.NewDataSet = false;
        }else if (localName.equals("Table")) {
             this.Table = false;
        }else if (localName.equals("Date")) {
             this.Date = false;
        }
        else if (localName.equals("Score")) {
            this.Score = false;
        }
     }

     /** Gets be called on the following structure:
      * &lt;tag&gt;characters&lt;/tag&gt; */
     @Override
    public void characters(char ch[], int start, int length) {
          if(this.Date)
          {
              myParsedExampleDataSet.setDate(new String(ch, start, length));
              System.out.println("Date"+Date);
          }
          if(this.Score)
          {
              myParsedExampleDataSet.setScore(new String(ch, start, length));
              System.out.println("Score"+Score);

          }

    }
}
</code></pre>

<hr>

<pre><code>package barc3.barc3;

public class XMLDataSet {
 String Date = null;
 String Score = null;

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

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

    public String toString(){
         return "Date is  = " + this.Date
                   + "\nScore is  = " + this.Score;

    }
}
</code></pre>

<hr>

<pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; 
&lt;DataSet xmlns="http://tempuri.org/"&gt;
&lt;xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"&gt;
 &lt;xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"&gt;
- &lt;xs:complexType&gt;
- &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt;
- &lt;xs:element name="Table"&gt;
- &lt;xs:complexType&gt;
- &lt;xs:sequence&gt;
  &lt;xs:element name="Date" type="xs:string" minOccurs="0" /&gt; 
  &lt;xs:element name="Score" type="xs:string" minOccurs="0" /&gt; 
  &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;/xs:choice&gt;
  &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
 &lt;diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"&gt;
 &lt;NewDataSet xmlns=""&gt;
 &lt;Table diffgr:id="Table1" msdata:rowOrder="0"&gt;
  &lt;Date&gt;12/5/2011&lt;/Date&gt; 
  &lt;Score&gt;5&lt;/Score&gt; 
  &lt;/Table&gt;
- &lt;Table diffgr:id="Table2" msdata:rowOrder="1"&gt;
  &lt;Date&gt;45/5/2011&lt;/Date&gt; 
  &lt;Score&gt;54&lt;/Score&gt; 
  &lt;/Table&gt;
- &lt;Table diffgr:id="Table3" msdata:rowOrder="2"&gt;
  &lt;Date&gt;12/5/2011&lt;/Date&gt; 
  &lt;Score&gt;12&lt;/Score&gt; 
  &lt;/Table&gt;
- &lt;Table diffgr:id="Table4" msdata:rowOrder="3"&gt;
  &lt;Date&gt;3/4/2011&lt;/Date&gt; 
  &lt;Score&gt;25&lt;/Score&gt; 
  &lt;/Table&gt;
- &lt;Table diffgr:id="Table5" msdata:rowOrder="4"&gt;
  &lt;Date&gt;6/8/2011&lt;/Date&gt; 
  &lt;Score&gt;45&lt;/Score&gt; 
  &lt;/Table&gt;
  &lt;/NewDataSet&gt;
  &lt;/diffgr:diffgram&gt;
  &lt;/DataSet&gt;
</code></pre>
