The source program is downloaded from the Internet, but the run is wrong, some categories are not included in J2ME, such as file read class FileReader, etc., change, can run. However, a bug has also left, that is, it will be wrong when the network. There has been no debugging success. In addition, DOS can be executed, but cannot be executed in the mobile emulator, saying that the lack of stack chart is coming. . . Calibration is not available. Source code pay / * - * - c-basic-offset: 4; indent-tabs-mode: nil; - * - // ------ 100-color - wide ------> | * /// for license please see acompanying license.txt file (Available Also At http://www.xmlpull.org/)
import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.io.DataInputStream; import java.io.IOException; import javax.microedition.io.HttpConnection; import javax.microedition.io.Connector; import javax.microedition .midlet.midlet; import javax.microedition.lcdui.form;
Import org.kxml2.io.kxmlparser; import org.xmlpull.v1.xmlpullParser; import org.xmlpull.v1.xmlpullParserException;
/ ** * an example xmlpull v1 api. * * @Author Aleksander Slominski * / public Class myxmlpullapp {
Public final static string Sample_Xml = " Xml version = /" 1.0 / "?> / n" "/ n" "
public static void main (String args []) throws XmlPullParserException, IOException {// XmlPullParserFactory factory = XmlPullParserFactory.newInstance (// System.getProperty (XmlPullParserFactory.PROPERTY_NAME), null); //factory.setNamespaceAware(true); // factory .setFeature (XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); KXmlParser xpp = new KXmlParser (); System.out.println ( "parser implementation class is" xpp.getClass ()); MyXmlPullApp app = new MyXmlPullApp ();
if (args.length == 0) {System.out.println ( "Parsing simple sample XML / n" SAMPLE_XML); xpp.setInput (new InputStreamReader (new ByteArrayInputStream (SAMPLE_XML.getBytes ()))); app.processDocument (xpp);} else {system.out.println ("Parsing file:" args [}); httpConnection hc = null; try {hc = (httpConnection) Connector.Open (args [0]);} catch Exception E) {E.PrintStackTrace ();
int resCode = 0; if (hc = null!) resCode = hc.getResponseCode (); byte [] data = null; if (resCode == HttpConnection.HTTP_OK) {DataInputStream dis = new DataInputStream (hc.openInputStream ()); INT size = disp.available (); data = new byte [size]; dis.readfully (DATA); dis.close ();} xpp.setInput (New INPUTSTREAMREADER (New ByteArrayInputStream (Data)); // XPP. setInput (new InputStreamReader (new FileInputStream (args [i]))); //xpp.setInput (new FileInputStream (args [i]), "UTF8"); app.processDocument (xpp);}} public void processDocument (KXmlParser XPP) THROWS XMLPULLPARSEREXCEPTION, IOEXCEPTION {INT EventType = Xpp.geteventType (); do {if (eventtype == xmlpullParser.Start_Document) {system.out.println ("Start Docume) nt ");} else if (eventType == XmlPullParser.END_DOCUMENT) {System.out.println (" End document ");} else if (eventType == XmlPullParser.START_TAG) {processStartElement (xpp);} else if (eventType == XmlPullParser.END_TAG) {processEndElement (xpp);} else if (eventType == XmlPullParser.TEXT) {processText (xpp);} eventType = xpp.next ();} while (eventType = XmlPullParser.END_DOCUMENT);!}
Public void processStartElement (kxmlparser xpp) {string name = xpp.getname (); string uri = xpp.getnamespace (); if ("" .Equals (uri)) {system.out.println ("Start Element:" Name );} Else {system.out.println ("start element: {" URI "}" name);}} public void processendelement (kxmlparser xpp) {string name = xpp.getname (); string uri = xppp .getnamespace (); if ("" .equals (uri)) System.out.Println ("End Element:" Name); Else System.out.println ("End Element: {" URI "}" Name);
INT HolderforstartandLength [] = new int [2];