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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
| package readXML;
import java.util.ArrayList;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import android.util.Log;
public class ParserXMLHandler extends DefaultHandler {
private final String MOT_FRANCAIS = "motFrancais";
private final String MOT_ANGLAIS = "motAnglais";
private final String DEF_FRANCAIS = "definitionFrancais";
private final String DEF_ANGLAIS = "definitionAnglais";
private final String TEST1 = "test1";
private final String TEST2 = "test2";
private final String TEST3 = "test3";
private final String TEST4 = "test4";
private final String TEST5 = "test5";
private final String ENTRY = "entry";
private boolean inEntry;
private boolean inTest1;
private boolean inTest2;
private boolean inTest3;
private boolean inTest4;
private boolean inTest5;
private static final String TAG = "ParserXMLHandler";
private ArrayList<Entry> entries;
private Entry currentFeed;
private StringBuffer buffer;
public ParserXMLHandler(){
super();
Log.i(TAG, "super();");
this.inTest1 = false;
this.inTest2 = false;
this.inTest3 = false;
this.inTest4 = false;
this.inTest5 = false;
this.inEntry = false;
}
@Override
public void processingInstruction(String target, String data) throws SAXException
{
try
{
Log.i(TAG, "super.processingInstruction(target, data);");
super.processingInstruction(target, data);
}
catch (SAXException e) {Log.e(TAG, "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE" + e.getMessage());}
}
@Override
public void startDocument() throws SAXException
{
try
{
Log.i(TAG, "super.startDocument();");
super.startDocument();
} catch (SAXException e) {Log.e(TAG, "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD" + e.getMessage());}
Log.i(TAG, "this.entries = new ArrayList<Entry>();");
this.entries = new ArrayList<Entry>();
}
@Override
public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException
{
Log.i(TAG, "STARTELEMENT");
buffer = new StringBuffer();
if(localName.equalsIgnoreCase(TEST1))
{
Log.i(TAG, "TEST1");
this.inTest1 = true;
}
if(localName.equalsIgnoreCase(TEST2))
{
Log.i(TAG, "TEST2");
this.inTest1 = false;
this.inTest2 = true;
}
if(localName.equalsIgnoreCase(TEST3))
{
Log.i(TAG, "TEST3");
this.inTest2 = false;
this.inTest3 = true;
}
if(localName.equalsIgnoreCase(TEST4))
{
Log.i(TAG, "TEST4");
this.inTest3 = false;
this.inTest4 = true;
}
if(localName.equalsIgnoreCase(TEST5))
{
Log.i(TAG, "TEST5");
this.inTest4 = false;
this.inTest5 = true;
}
if(localName.equalsIgnoreCase(ENTRY))
{
Log.i(TAG, "ENTRYYYYYYYYY");
this.inEntry = true;
this.currentFeed = new Entry();
if(this.inTest1)
this.currentFeed.setTest("test1");
if(this.inTest2)
this.currentFeed.setTest("test2");
if(this.inTest3)
this.currentFeed.setTest("test3");
if(this.inTest4)
this.currentFeed.setTest("test4");
if(this.inTest5)
this.currentFeed.setTest("test5");
}
}
@Override
public void endElement(String uri, String localName, String name) throws SAXException
{
Log.i(TAG, "ENDELEMENT");
if(localName.equalsIgnoreCase(MOT_ANGLAIS))
{
if(this.inEntry)
{
Log.i(TAG, "SET MOT ANGLAIS : " + buffer.toString());
this.currentFeed.setMotAnglais(buffer.toString());
this.buffer = null;
}
}
if(localName.equalsIgnoreCase(MOT_FRANCAIS))
{
if(this.inEntry)
{
Log.i(TAG, "SET MOT FRANCAIS : " + buffer.toString());
this.currentFeed.setMotFrancais(buffer.toString());
this.buffer = null;
}
}
if(localName.equalsIgnoreCase(DEF_ANGLAIS))
{
if(this.inEntry)
{
Log.i(TAG, "SET DEF ANGLAIS : " + buffer.toString());
this.currentFeed.setDefAnglais(buffer.toString());
this.buffer = null;
}
}
if(localName.equalsIgnoreCase(DEF_FRANCAIS))
{
if(this.inEntry)
{
Log.i(TAG, "SET DEF FRANCAIS : " + buffer.toString());
this.currentFeed.setDefFrancais(buffer.toString());
this.buffer = null;
}
}
if(localName.equalsIgnoreCase(ENTRY))
{
this.entries.add(currentFeed);
this.inEntry = false;
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException
{
String lecture = new String(ch, start, length);
if(buffer != null)
{
Log.i(TAG, "buffer PAAAS null !!!!!!" + lecture);
this.buffer.append(lecture);
}
else
{
Log.i(TAG, "buffer null !!!!!!");
}
}
public ArrayList<Entry> getData()
{
Log.i(TAG, "getData()");
return this.entries;
}
} |
Partager