Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/03/2013, 18:09
Avatar de Hateoner
Hateoner
 
Fecha de Ingreso: octubre-2012
Ubicación: Madrid, Spain
Mensajes: 7
Antigüedad: 11 años, 6 meses
Puntos: 1
Sax parser finaliza antes de tiempo

Hola, buenas estoy progrmando una app que muestra en un ListView datos de un RSS y al parsear el xml antes del primer <item> hay un <![CDATA[ y cuando lo tiene que parsear, sigue con el resto de la app como si el xml hubiese acabado, os dejo el codigo del Handler que se encarga de decidir que hacer con cada tag del xml y el xml del rss es este
http://blog.exitae.es/rss

Código:
package es.brianapp.blogexitae.parser;

import java.util.Date;

import org.apache.http.impl.cookie.DateParseException;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;

import es.brianapp.blogexitae.db.DatabaseMap;
import es.brianapp.blogexitae.db.Provider;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.util.Log;

public class RssHandler extends DefaultHandler implements LexicalHandler{

	private boolean in_item = false;
	private boolean in_title = false;
	private boolean in_pubdate = false;
	private boolean in_link = false;
	private boolean in_comments = false;
	private boolean in_dccreator = false;
	private boolean in_description = false;
	private boolean in_CDATA = false;
	
	private ContentResolver resolver;
	private ContentValues values;
	private Uri provider_uri = Provider.CONTENT_URI;
	
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		
		values = new ContentValues();
		
		if (localName.equalsIgnoreCase("item")) {
			in_item = true;
			Log.d("Handler START TAG", localName);
		}else if (localName.equalsIgnoreCase("title")){
			in_title = true;
		}else if (localName.equalsIgnoreCase("pubdate")){
			in_pubdate = true;
		}else if (localName.equalsIgnoreCase("dc:creator")){
			in_dccreator = true;
		}else if (localName.equalsIgnoreCase("link")){
			in_link = true;
		}else if (localName.equalsIgnoreCase("description")){
			in_description = true;
		}else if (localName.equalsIgnoreCase("comments")){
			in_comments = true;			
		}
		super.startElement(uri, localName, qName, attributes);
	}
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		
		if (localName.equalsIgnoreCase("item")) {
			resolver.insert(provider_uri, values);
			Log.d("Handler END TAG", localName);
			in_item = false;
		}else if (localName.equalsIgnoreCase("title")){
			in_title = false;
		}else if (localName.equalsIgnoreCase("pubdate")){
			in_pubdate = false;
		}else if (localName.equalsIgnoreCase("dc:creator")){
			in_dccreator = false;
		}else if (localName.equalsIgnoreCase("link")){
			in_link = false;
		}else if (localName.equalsIgnoreCase("description")){
			in_description = false;
		}else if (localName.equalsIgnoreCase("comments")){
			in_comments = false;	
		}
		super.endElement(uri, localName, qName);
	}
	@Override
	public void characters(char[] ch, int start, int lenght)
			throws SAXException {
		if(in_item){
			if (in_title) {
				values.put(DatabaseMap.Posts.TITULO, new String(ch,start,lenght));
			}else if (in_link){
				values.put(DatabaseMap.Posts.LINK, new String(ch,start,lenght));
			}else if (in_description){
				values.put(DatabaseMap.Posts.DESCRIPCION, new String(ch,start,lenght));
			}else if (in_pubdate){
				String StringDate = new String(ch,start,lenght);
				try{ 
					long date = Date.parse(StringDate);
					values.put(DatabaseMap.Posts.FECHA,	date);
				}catch(Exception e){
					//
				}
				
			}
		}
		super.characters(ch, start, lenght);
	}
	@Override
	public void comment(char[] ch, int start, int length) throws SAXException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void endCDATA() throws SAXException {
		in_CDATA = false;
	}

	@Override
	public void startCDATA() throws SAXException {
		in_CDATA = true;
	}

	@Override
	public void startDTD(String name, String publicId, String systemId)
			throws SAXException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void endDTD() throws SAXException {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void startEntity(String name) throws SAXException {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void endEntity(String name) throws SAXException {
		// TODO Auto-generated method stub
		
	}

}
Sabéis algo que me pueda ayudar ? Gracias :D