[Change] Comparison of the four operating mode XML

1. Introduction

1) DOM (JAXP Crimson parser)
DOM is platform-and language-independent manner, said the official W3C standard XML document. DOM is a hierarchical organization of nodes or pieces of information collection. This hierarchy allows the developer to find specific information in the tree. Analysis of the structure often requires loading and structural hierarchy of the entire document before doing any work. Because it is based on the information level, which is considered DOM tree-based or object-based. DOM and the broad tree-based processing has several advantages. First, because the tree in memory is durable, so you can modify it so that applications can be made on data and structural changes. It may at any time up and down navigation in the tree, rather than as a one-time processing SAX. DOM also much easier to use.

2) SAX

The advantages of SAX processing is very similar to the advantages of streaming media. Analysis can begin immediately rather than waiting for all data are processed. And, because the application reads the data only at the check data, so no data is stored in memory. This large document is a huge advantage. In fact, the application even without parsing the entire document; it can stop when a condition is met resolve. In general, SAX is also an alternative to DOM than its much faster.
Select or Select DOM SAX? The need to write your own code to handle XML document, developers, choose DOM or SAX parsing model is a very important design decisions. DOM tree structure used to establish access to XML documents, while the SAX event model used.

DOM parser, the XML document into a tree that contains the content, and can traverse the tree. DOM parsing model with the advantages of easy programming, developers need only call the achievements of the command, and then using the tree navigation APIs to access the node to complete the required tasks. Can easily add and modify elements of the tree. However, when the use of DOM parser to handle the entire XML document, so performance and memory requirements is relatively high, particularly at a time when much of the XML file. Because of its ability to traverse, DOM parser, XML documents commonly used in frequently changing needs of the services.

SAX parser using event-based model, which, when parsing XML documents can trigger a series of events, when discovered, when a given tag, which can activate a callback method, to tell the method to develop the label has been found. SAX on the memory requirements are usually lower, because it allows developers to decide which to deal with the tag. Especially when the developer need only deal with part of the document contained in the data, SAX is better scalability of this embodiment. But with the SAX parser when the coding would be more difficult, and it is very difficult to access the same document in multiple different data.

3) JDOM http://www.jdom.org/

JDOM is intended to be Java-specific document model, which simplifies the interaction with XML, and faster than using DOM. Because it is the first Java-specific models, JDOM has been vigorously promoted and promoted. Is considering "Java Specification Request JSR-102" will it eventually be used as "Java standard extension." From early 2000 had started JDOM development.

JDOM and DOM are mainly two different. First of all, JDOM uses concrete classes rather than just using the interface. This is in some ways simplifies the API, but also limits flexibility. Second, API extensive use of Collections class, simplifying those already familiar with these kind of Java developers use.

JDOM document to declare that their aim is to "use 20% (or less) 80% of the energy solution (or more) Java / XML problems" (according to the learning curve is assumed to be 20%). JDOM for the majority of Java / XML applications, of course, useful, and most developers find that API is much easier to understand than the DOM. JDOM also includes a wide range of program behavior in check to prevent users from doing anything in XML in insignificant things. However, it still requires that you fully understand the XML to do some work beyond the basic (or even understand some cases, the error). This may be better than learning the DOM or JDOM interfaces are more meaningful work.

JDOM itself does not contain a parser. It usually uses SAX2 parser to parse and validate input XML document (although it can be said before the DOM structures as input). It contains the JDOM said converter to output a SAX2 event streams, DOM model or XML text document. JDOM is a variant of the Apache License released under open source.

4) DOM4J http://dom4j.sourceforge.net/

Although DOM4J represents the results of completely independent development, but initially, it is an intelligence branch of JDOM. It incorporates many of the basic XML document that go beyond the features, including integrated support for XPath, XML Schema support, and for large documents or stream of event-based document processing. It also provides the option of constructing the document indicated that it passed DOM4J API and standard DOM interfaces with parallel access. From the second half of 2000, it has been under development.

To support all these features, DOM4J use interfaces and abstract base class methods. DOM4J extensive use of the API in the Collections class, but in many cases, it also provides some alternative ways to allow for better performance or a more direct encoding method. Direct benefit, although DOM4J more complex API to pay the price, but it offers much greater flexibility than JDOM.

Adding flexibility, XPath integration and processing of large documents objectives, DOM4J goals and JDOM is the same: for the Java Developer's ease of use and intuitive operation. It also aims to be more complete than JDOM solution to achieve, in essence, to deal with all Java / XML, the objective. Upon completion of the target, less stressed than JDOM prevent incorrect application behavior.

DOM4J is a very, very good Java XML API, high-performance, powerful and extremely easy to use features, while it is an open source software. Now you can see more and more Java software are in use DOM4J to read and write XML, is particularly worth mentioning is that even the Sun's JAXM also use DOM4J.

Comparison of 2 ..

1) DOM4J best performance, even the Sun's JAXM also use DOM4J. At present, many open source projects are widely used DOM4J, such as the famous Hibernate also used DOM4J to read XML configuration files. If you do not consider the portability, then use DOM4J.

2) JDOM and DOM in the performance of the test performed poorly in tests of memory 10M document. In the small document cases, is worth considering the use DOM and JDOM. While JDOM developers have shown they expect to focus on performance before the official release issue, but from a performance point of view, it does not recommend it. In addition, DOM is still a very good option. DOM implementation used in a variety of programming languages. It is a number of other standards and XML-related basis, because it formally W3C Recommendation (based on non-standard Java model over), so certain types of projects may also need it (such as the use of the JavaScript DOM).

3) SAX performance is better, that depends on its specific analytical method - event-driven. Detection of a SAX XML stream coming, but not loaded into memory (of course, when the XML stream is read, some of the documents being hidden in the memory).

3. Xml mode of operation of four basic use

xml file:

<? Xml version = "1.0" encoding = "utf-8"?>
<Result>
<VALUE>
<NO DATE="2005"> A1 </ NO>
<ADDR> GZ </ ADDR>
</ VALUE>
<VALUE>
<NO DATE="2004"> A2 </ NO>
<ADDR> XG </ ADDR>
</ VALUE>
</ Result>

1) DOM

import java.io. *;
import java.util .*;
import org.w3c.dom .*;
import javax.xml.parsers .*;

public class MyXMLReader (
public static void main (String arge []) (

long lasting = System.currentTimeMillis ();
try (
File f = new File ("data_10k.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance ();
DocumentBuilder builder = factory.newDocumentBuilder ();
Document doc = builder.parse (f);
NodeList nl = doc.getElementsByTagName ("VALUE");
for (int i = 0; i <nl.getLength (); i + +) (
System.out.print ("license plate number:" + doc.getElementsByTagName ("NO"). Item (i). GetFirstChild (). GetNodeValue ());
System.out.println ("owner address:" + doc.getElementsByTagName ("ADDR"). Item (i). GetFirstChild (). GetNodeValue ());
)
) Catch (Exception e) (
e.printStackTrace ();
)

2) SAX

import org.xml.sax .*;
import org.xml.sax.helpers .*;
import javax.xml.parsers .*;

public class MyXMLReader extends DefaultHandler (

java.util.Stack tags = new java.util.Stack ();
public MyXMLReader () (
super ();
)

public static void main (String args []) (
long lasting = System.currentTimeMillis ();
try (
SAXParserFactory sf = SAXParserFactory.newInstance ();
SAXParser sp = sf.newSAXParser ();
MyXMLReader reader = new MyXMLReader ();
sp.parse (new InputSource ("data_10k.xml"), reader);
) Catch (Exception e) (
e.printStackTrace ();
)

System.out.println ("running time:" + (System.currentTimeMillis () - lasting) + "ms");)
public void characters (char ch [], int start, int length) throws SAXException (
String tag = (String) tags.peek ();
if (tag.equals ("NO")) (
System.out.print ("license plate number:" + new String (ch, start, length));
)
if (tag.equals ("ADDR")) (
System.out.println ("Address:" + new String (ch, start, length));
)
)

public void startElement (String uri, String localName, String qName, Attributes attrs) (
tags.push (qName);)
)

3) JDOM

import java.io. *;
import java.util .*;
import org.jdom .*;
import org.jdom.input .*;

public class MyXMLReader (

public static void main (String arge []) (
long lasting = System.currentTimeMillis ();
try (
SAXBuilder builder = new SAXBuilder ();
Document doc = builder.build (new File ("data_10k.xml"));
Element foo = doc.getRootElement ();
List allChildren = foo.getChildren ();
for (int i = 0; i <allChildren.size (); i + +) (
System.out.print ("license plate number:" + ((Element) allChildren.get (i)). GetChild ("NO"). GetText ());
System.out.println ("owner address:" + ((Element) allChildren.get (i)). GetChild ("ADDR"). GetText ());
)
) Catch (Exception e) (
e.printStackTrace ();
)

)

4) DOM4J

import java.io. *;
import java.util .*;
import org.dom4j .*;
import org.dom4j.io .*;

public class MyXMLReader (

public static void main (String arge []) (
long lasting = System.currentTimeMillis ();
try (
File f = new File ("data_10k.xml");
SAXReader reader = new SAXReader ();
Document doc = reader.read (f);
Element root = doc.getRootElement ();
Element foo;
for (Iterator i = root.elementIterator ("VALUE"); i.hasNext ();) (
foo = (Element) i.next ();
System.out.print ("license plate number:" + foo.elementText ("NO"));
System.out.println ("owner address:" + foo.elementText ("ADDR"));
)
) Catch (Exception e) (
e.printStackTrace ();
)
)
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb
Tags:

Related Posts of [Change] Comparison of the four operating mode XML

  • The use of VI commands

    Basically, vi can be divided into three operating states, namely, the command mode (Command mode), insert mode (Insert mode) and bottom-line command mode (Last line mode), the mode functions classified as follows: 1. Comand mode: control the screen cursor

  • java in the comparison of four operating modes xml

    java in the comparison of four operating modes xml 1. Introduction 1) DOM (JAXP Crimson parser) DOM is platform and language independent way, said an official W3C standard XML documents. DOM is a hierarchical organization of nodes or a collection of piece

  • Several Android phone operating mode analysis system

    Android system, with six models, namely, general startup mode (normal mode), safe mode (safe mode), recovery mode (recovery mode), boot mode (bootloader mode), fastboot mode and diagnostic mode (diagnostic mode). Normal startup mode (normal mode) act

  • Dual-drive double into the operating system than Ubuntu Desktop mode

    Operating system installed in the ubuntu one editor, do not get to know ye the dead. Then select the recover mode on reboot or useless. Can only enter command mode. Is prompted to mount of filesystem failed A MAITENANCE SHELL WILL NOW BE STARTED CONT ...

  • linux vi command of the details

    The basic concept is basically vi vi can be divided into three operating states, namely, command mode (Command mode), insert mode (Insert mode) and bottom-line command mode (Last line mode), the functions of the model classified as follows: Comand mode: c

  • derby: operating mode

    derby at the two operating modes: embedded mode and network mode (I think that is the "Client - Server (CS)"). In embedded mode, the database and application sharing a JVM, the application Fuze generally start He stop database, Qita applica

  • Linux environment, the vi text editor under common operating

    vi editor has three kinds of modes: command mode, input mode, the last line mode. Grasp the importance of three modes: Command mode: vi starts to enter the command mode by default, use the command from this mode can switch to the other two models, wh

  • Comparison of mode perfork.worker apahce

    prefork and worker model comparison: prefork mode uses multiple child processes, each child process only one thread. Each process in a certain time only to maintain a connection. In most platforms, Prefork MPM in the efficiency is higher than the Wor

  • Operating instructions used vi

    First, the mode: 1. Open for the normal mode, waiting for command input. 2. When the input i, is the insert mode, you can edit, when if Esc to return to normal mode. 3. Command line mode: normal mode, type ":" No you can enter command mode.

  • Assessed using SpecJbb2005

    Scope: 1. Different jvm versions 2. Comparison of several existing machine 3. Virtualization comparison 4. Numa architecture comparison 5. 32/64 comparison 6. Os kernel comparison The duration of this test a bit longer, I shall report my understandin ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries