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
|
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import org.kxml2.io.*;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class AccessUrlKXML extends MIDlet{
private Display display;
static final String url = "http://127.0.0.1/testurljava/Livres.xml";
public AccessUrlKXML(){
display = Display.getDisplay(this);
}
public void startApp(){
try{
connection(url);
} catch (IOException ioe) {
System.out.println("IOException " + ioe);
ioe.printStackTrace();
} catch (XmlPullParserException xppe) {
System.out.println("XmlPullParserException : " + xppe);
xppe.printStackTrace();
}
}
public void pauseApp() {}
public void destroyApp(boolean unconditional){}
void connection(String url) throws IOException, XmlPullParserException {
StreamConnection sc = null;
InputStream is = null;
TextBox access;
try {
KXmlParser parseur = new KXmlParser();
parseur.setInput(new InputStreamReader(is));
parseur.nextTag();
parseur.require(XmlPullParser.START_TAG, null, "catalog");
while (parseur.next() != XmlPullParser.END_DOCUMENT) {
parseur.require(XmlPullParser.END_TAG, null, "catalog");
parseur.next();
parseur.require(XmlPullParser.END_DOCUMENT, null, null);
if (parseur.getEventType() == XmlPullParser.START_TAG) {
System.out.println("Start Tag : " + parseur.getName() + " Att Count : " + parseur.getAttributeCount() + parseur.nextText());
if (parseur.getAttributeCount() > 0) {
System.out.println("Attr name :" + parseur.getAttributeName(0) + " - Value : " + parseur.getAttributeValue(0));
}
}
}
}
catch(IOException ex) {
ex.printStackTrace();
} finally {
if (is != null){
is.close();
}
if(sc != null){
sc.close();
}
}
access = new TextBox("Test ...", "------", 1024, 0);
display.setCurrent(access);
}
} |
Partager