Easily integrate Java and XML with JDOM (1)
Overview:
Jdom is a new API function read by reading, writing, and operating XML in Java language. Jason Hunter and Brett McLauhlin disclose its test version. These API functions are maximized optimized in the premise of intuition, simple and efficient. In the next parameters, Hunter and McLaughlin introduces how to read a already existing XML document with Jdom.
JDOM is an open source API that describes the contents of XML documents and documents to Java programmers in a direct easy-to understand. As the name is revealed, JDOM is optimized for Java. Provide a low consumption method for using an XML document. JDOM users can do the desired operations without having to master too much XML knowledge.
JDOM can cooperate with existing XML technology such as Simple API for XML (SAX) and Document Object Model (DOM). However, it is not simple from these APIs. JDom has absorbed good aspects from these existing technologies, and has established a new set of new classes and interfaces. It is: "These interfaces are what I read from the beginning Org.W3c.dom look forward to ""; JDOM can read the SAX or the DOM content, or output SAX or DOM can receive the format. This capability can make JDOM good and existing systems established with SAX or DOM.
JDM principle
The first one is the most important one is that the JDOM's API function is designed to be easy to understand. Other XML parses functions are designed to be universal (support the same API function in Java, C , and even in JavaScript). JDOM uses Java's excellent features such as method overload, recycling mechanism, and background processing.
In order to be easily easy, these functions have to depict the XML document in the form of programmers like. For example: What is the text content of a programmer's text?
In some APIs, the text content of the element is only used as a child node of an element. From a technical point of view, this design requires the following code to access the element:
String content = element.getfirstchild (). GetValue ();
JDOM uses a simpler and easy way to get the content of the element:
String text = element.getText ();
JDM reduces the workload of programmers as much as possible. According to the thumb rules, JDOM should use 20% or less efforts to complete 80% or more Java / XML issues. This is not to say that JDOM just supports 80% XML specification (in fact we want JDOM100% support XML specification). This thumb rule is that some things can be added, but there is no need. These API functions should be concise.
The second principle of JDOM is that JDOM should be fast and lightweight. The transfer and execution documents should be fast, and the memory consumption should be as small as possible. JDOM design is obvious to follow this principle. For example, even if it starts, the operation of less coordinated operation is fast than DOM, but is rough than SAX. Despite this, JDOM still has many SAX nothing.
Do you need jdom?
So, do you need JDOM? This is really a good problem. Already have a standard, why is it going to invent a new one? The answer is that JDOM solves the problem of existing standards.
The DOM is fully described in memory. It is a big API that is designed to operate almost all possible XML tasks. It must also have the same API to support different languages. Because of these restrictions, it is very uncomfortable for those habitual use of Java, such as method overload, simple set, GET method's Java programmer. DOM also requires a lot of memory and higher frequency, which makes it difficult to work with many lightweight web applications. SAX did not build an element tree in memory, which is described in the way of developing. For example: it reports each read start tag and end tag. This processing method makes it a lightweight quick read API. However, this event handling method is not intuitive for the server-side Java programmers. SAX also does not support modifying XML documents and random read.
Jdom attempts to combine the advantages of DOM and SAX. It is designed to quickly perform a lightweight API in small memory. JDOM also supports random reading of the entire document, but amazing is that it does not need to read the entire document in memory. This API supports the secondary lightweight operation of the information when needed. Also, JDOM supports the modification of XML documents through standard constructors and SET methods.
Resources:
Read Part 2 of "Easy Java / XML Integration with Jdom," Jason Hunter and Brett Mclaughlin (Jason Hunter and Brett McLaughlin (July, 2000) To learn how to use jdom to create and mutate xml: http://www.javaworld.com/javaworld/jw- 07-2000 / JW-0728-jdom2.html
The home of jdom: http://jdom.org/
Mailing List Sign-Up for Jdom-Interest And Jdom-Announce, AS Well As List Archives: http://jdom.org/incolved/lists.html
THE JDOM Announcement Press Release: http://www.oreillynet.com/pub/a/mediakit/pressRelease/20000427.html
More Information on Dom: http://www.w3.org/dom/
More information on sax: http://www.meginson.com/sax/
More information on jaxp: http://java.sun.com/xml/