Analyze XML on an architecture based on CLDC
More and more applications use XML exchange messages. For example, a CLDC-based application requires processing XML files, and even HTML web pages will also be able to convert into a XML-based format. This means that the information will be analyzed from a web server to take the information from a web server. Installing Software J2ME Wireless Toolkit 1.0.4 and Chinese Version Apache Tomcat XML is "Extensible Markup Language", is a lightweight, text-based approach to present structured materials. More and more applications use XML exchange messages, and in some cases, you are based on CLDC (these refer to the SMEs based on CLDC-based architectures, like tiny mobile devices Class) needs to process the XML file. After that, even HTML web pages will also be able to convert to an XML-based format called XHTML. This means that the information will be analyzed from a web server to take out the information will need to analyze XML technology.
A Multi-Tier Architecture with XML Find a Java-based XML analyzer is not difficult, especially since there are several XML-based advocates that are defined as part of the Java handler. However, most of the XML analyzers are not supported in a limited resource environment provided by CLDC. These analyzers are not using too much memory is the J2SE category that cannot work in CLDC. However, there are two open original code XML analyzers that can operate in a CLDC environment - kxml and nanoxml. The lengths of both are some - this article will discuss them and provide you decide which one is best for your program. However, you should also consider whether to select XML because the XML file is very lengthy. This is quite easy to communicate with a Java-based client with a Java-based servo. In this example, use the DataInputStream and the DataOutputStream category to read the information in a lightweight method.
Basic XML analyzer type
Basic XML analyzer has two types: confirmation and non-confirmatory. A confirmative analyzer confirms a XML file through a file type, definition or summary (Schema) to ensure that the content of this file is expected. This requirement will reduce the speed of processing. A non-specific analyzer skip this step, only guarantees that the XML file is a fundamental format, in turn, it complies with the rules that the general XML file must be observed. Both KXML and Nanoxml are unconfirmed analyzers. Non-confirming analyzer XML analyzers can also distinguish between how they handle and present an XML file. 1.Modelparser: Read the entire file into the memory. Model Parsers will need more memory (DOM API) 2.pushparser than other Parser: Read the entire file, perform processing when you encounter a special label (SAX API) 3.PullParser: One read part file is parsed. This is a single-step (SINGLE-STEP) analyzer. A file is given, and NanoXML analyzes it with a single operation and transmits the file in a tree structure. KXML belongs to a PULL type, a multi-step analyzer - an area of an analysis file. These two methods have their own advantageous and disadvantages. If you are processing a large file, a single step method uses more memory, as all of the files are stored in the memory. If you need to cross this file, how many times, a single step will be more efficient. Multi-step approaches can easily handle large files, but you have to do more bookkeeping to track which place you are in the file. ■ How to use KXML? Download the KXML original code from http://www.kxml.org/ and contain the KXML category to enter your app. Not all categories are needed, so just download the ZIP file containing the minimum KXML. Place the zip or JAR gear in the LIB directory of J2Mewtk Project, after installing this file, add the following introduction to your program.
Package XML; import java.io. *; import java.util.vector; import org.kxml2.io. *; import org.xmlpull.v1. *; import javax.microedition.midlet. *; import javax.microedition.lcdui *; / ** * J2ME: Read http://www.newsforge.com/newsforge.xml News list * / public class newsreader extends MIDlet imports commandlistener {static final string URL = "http://www.newsforge.com/newsforge.xml"; static final string title = "newsforge"; vector descriptions = new vector (); list newslist = new list (title, choice.implicit); TextBox textbox = New TextBox ("", ",", 256, textfield.any); Display Display; command backcmd = new command ("back", command.back, 0); / ** * Start reading thread * / Class Readthread Extends thread {PUBLIC VOID RUN () {Try {httpconnection httpConnection = (httpConnection) Connector.Open (URL); KXmlParser parser = new KXmlParser (); parser.setInput (new InputStreamReader (httpConnection.openInputStream ())); // parser.relaxed = true; parser.nextTag (); parser.require (XmlPullParser.START_TAG, null, "backslash" ); While (Parser.NextTag ()! = Xmlpullparser.end_tag) ReadStory (Parser); Parser.Require (XmlpullParser.end_tag, null, "backslash"); parser.next ();
Parser.Require (XmlpullParser.end_Document, null, null);} catch (exception e) {E.PrintStackTrace (); descriptions.addelement (E.TOSTRING ()); newslist.append ("error", null);}} / ** * reads the story and added to the list * @param parser kxml parser * / void readStory (KXmlParser parser) throws IOException, XmlPullParserException {parser.require (XmlPullParser.START_TAG, null, "story"); String title = null; String description = null; while (parser.nextTag () = XmlPullParser.END_TAG!) {parser.require (XmlPullParser.START_TAG, null, null); String name = parser.getName (); String text = parser. NextText (); System.out.println ("<" Name " Text); if (Name.Equals (" Title ")) Title = Text; Else IF (Name.Equals (" Description ")) Description = Text; Parser .Require (XmlpullParser.end_tag, null, name);} Parser.Require (XmlpullParser.end_tag, null, "story"); if (title! = null) {descriptions.addelement (" description);
newsList.append (title, null);}}} public void startApp () {display = Display.getDisplay (this); display.setCurrent (newsList); newsList.setCommandListener (this); textBox.setCommandListener (this); textBox. addCommand (backCmd); new ReadThread () start ();.} public void pauseApp () {} public void commandAction (Command c, Displayable d) {if (c == List.SELECT_COMMAND) {String text = (String) descriptions .elementAt (newsList.getSelectedIndex ()); if (textBox.getMaxSize ()