Hi all,
XML has been widely used in the field of data exchange, xml is based on plain text, with excellent cross-platform features. I want how to parse XML in J2ME for data transmission. Please suggest. Thanks in advance.
Hi all,
XML has been widely used in the field of data exchange, xml is based on plain text, with excellent cross-platform features. I want how to parse XML in J2ME for data transmission. Please suggest. Thanks in advance.
Before the use of XML, you must consider the good and not have to use it to transmit data, because xml parsing is more resource-intensive, especially in the CPU and memory resources are precious conditions. If we can use DataInputStream and DataOutputStream, then transfer to try not to use XML. XML parser, there are two, one is sure of, he would have xml parsing of the document prior to the effectiveness of verification, to ensure that it is the application needed. Check and reply.
Written in XML is relatively simple and very easy to people to read. But it must be the client and server-side XML parser can have a normal communication, because of the initial mobile information device memory and processor on the lack of, so MIDP1.0 did not provide XML support.You can use kxml. To use the kxml, you must first get a XmlParser instance, it uses Reader as the constructor parameters. Check that and reply.
Code:try ( Reader r123 = .....; XmlParser parser = new XmlParser (r123); } catch (java.io.IOException e) ( / / Handle exception .... }
If you want to use nanoxml for parsing XML in J2ME, then you must first create an kXMLElement instance, and then call parseFromReader, parseString or parseCharArray. Because it is the first step parser, then it will parse the entire document exhausted generate an Object tree. Each node is a kXMLElement instance, by calling getChildren methods such as navigation in this tree.
Code:HttpConnection conn123 = ....; InputStreamReader doc123 = new InputStreamReader (conn.openInputStream ()); kXMLElement root123 = new kXMLElement (); try ( root.parseFromReader (doc123); } catch (kXMLParseException pe) ( } catch (IOException ie) ( }
With the improvement of memory and processors of XML support as possible. JSR182 is provided in the XML parser, but this is not the standard MIDP in the API require a specific implementation can support. Fortunately, there is a third-party API provides support for parsing xml to compare well-known is the kxml and nanoxml. You can download this parser from website. Best of luck.
The other parser is non-confirmation in nature, They does not do validation work directly parsing, no doubt such a speed would be faster. kxml and parser nanoxml are like this. They are also differences, kxml incremental parser that he will bit by bit resolution, so that when parsing large documents will be more efficient. nanoxml parser is the first step, once put the document parsing finished, if the document is very large, it will undoubtedly cost a great memory. Check and reply.
Bookmarks