parsing error

//ContentXml.java

package com.laabroo.android.ilivescore;

import java.net.URL;

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.LinearLayout;
import android.widget.TextView;

public class ContentXml extends Activity {
	RssItem rssItem=null;
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.news);
		
		LinearLayout layout=new LinearLayout(this);
		layout.setOrientation(1);
		
		TextView title[];
		TextView desc[];
		TextView date[];
		
		
		try{
			SAXParserFactory spf=SAXParserFactory.newInstance();
			SAXParser sp=spf.newSAXParser();
			XMLReader xr=sp.getXMLReader();
			
			URL url=new URL("http://www.goal.com/id-ID/feeds/news?fmt=atom");
			ParsingXml parsingXml=new ParsingXml();
			xr.setContentHandler(parsingXml);
			xr.parse(new InputSource(url.openStream()));
			
		}
		catch(Exception e){
			System.out.println("XML Parising Exception "+e);
		}
		
		rssItem=ParsingXml.rssItem;
		title=new TextView[rssItem.getTitle().size()];
		desc=new TextView[rssItem.getTitle().size()];
		date=new TextView[rssItem.getTitle().size()];
		
		
		for(int i=0;i<rssItem.getTitle().size();i++){
			title[i]=new TextView(this);
			title[i].setText(rssItem.getTitle().get(i));
			desc[i]=new TextView(this);
			desc[i].setText(rssItem.getDesc().get(i));
			date[i]=new TextView(this);
			date[i].setText(rssItem.getDate().get(i));
			
			layout.addView(title[i]);
			layout.addView(desc[i]);
			layout.addView(date[i]);
		}
		
		setContentView(layout);
	}

}



//ParsingXml.java

package com.laabroo.android.ilivescore;



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

public class ParsingXml extends DefaultHandler {

	Boolean curentElement = false;
	String curentValue = null;

	public static RssItem rssItem = null;

	public static RssItem getRssItem() {
		return rssItem;
	}

	public static void setRssItem(RssItem rssItem) {
		ParsingXml.rssItem = rssItem;
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attribute) throws SAXException {
		curentElement = true;
		if (localName.equals("entry")) {
			rssItem = new RssItem();
		}

		else if (localName.equals("title")) {
			String atr = attribute.getValue("type");
			rssItem.setTitle(atr);
		} else if (localName.equals("updated")) {
			rssItem.setDate(curentValue);

		}

		else if (localName.equals("summary")) {
			String atr2 = attribute.getValue("type");
			rssItem.setDesc(atr2);
		}
	}

	public void endElement (String uri, String localName, String qName,
			Attributes attribute) throws SAXException {
		curentElement = false;
		if (localName.equalsIgnoreCase("title")) {
			rssItem.setTitle(curentValue);

		} else if (localName.equalsIgnoreCase("updated")) {
			rssItem.setDate(curentValue);
		} else if (localName.equalsIgnoreCase("summary")) {
			rssItem.setDesc(curentValue);
		}
	}

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		if (curentElement) {
			curentValue = new String(ch, start, length);
			curentElement = false;
		}
	}
}




//RssItem.java

package com.laabroo.android.ilivescore;

import java.util.ArrayList;

public class RssItem {
private ArrayList<String> title=new ArrayList<String>();
private ArrayList<String> desc=new ArrayList<String>();
private ArrayList<String> date=new ArrayList<String>();

public ArrayList<String> getTitle(){
	return title;
}
  public void setTitle(String title){
	  this.title.add(title);
  }
  public ArrayList<String> getDesc(){
	  return desc;
  }
  public void setDesc(String desc){
	  this.desc.add(desc);
  }
  public ArrayList<String> getDate(){
	  return date;
  }
  public void setDate(String date){
	  this.date.add(date);
  }
}


please correct this code…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s