1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| package com.example.fadda;
import java.util.ArrayList;
import java.util.List;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import android.util.Log;
public class XMLhandler extends DefaultHandler {
//private ChannelList channelList = new ChannelList();
private StringBuilder builder;
private List<ItemStructure> channelList;
private ItemStructure chList;
// private RoomRate currentMessage=new RoomRate();
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub
super.characters(ch, start, length);
String string = new String(ch, start, length).replaceAll("[\r\t\n]", "");
builder.append(string);
}
/*
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub
super.characters(ch, start, length);
builder.append(ch, start, length);
}
*/
@Override
public void endElement(String uri, String localName, String title)
throws SAXException {
// TODO Auto-generated method stub
super.endElement(uri, localName, title);
if (chList != null){
if (localName.equalsIgnoreCase("title"))
{
chList.setTitle(builder.toString());
Log.i("111CITYYYYYYY", "++++++++"+chList.getTitle());
}
else if (localName.equalsIgnoreCase("teaser")){
chList.setTeaser(builder.toString());
}
else if (localName.equalsIgnoreCase("photo")){
chList.setPhoto(builder.toString());
}
else if (localName.equalsIgnoreCase("date")){
chList.setDate(builder.toString());
}
else if (localName.equalsIgnoreCase("article")){
channelList.add(chList);
}
builder.setLength(0);
}
}
@Override
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
super.startDocument();
channelList = new ArrayList<ItemStructure>();
builder = new StringBuilder();
}
@Override
public void startElement(String uri, String localName, String title,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
super.startElement(uri, localName, title, attributes);
if (localName.equalsIgnoreCase("article")){
this.chList = new ItemStructure();
builder.setLength(0);
}
}
public List<ItemStructure> getChannelList() {
return channelList;
}
public void setChannelList(List<ItemStructure> channelList) {
this.channelList = channelList;
}
} |
Partager