XML brief

xiaoxiao2021-03-06  105

XML brief

One. Wang Daohe

First, do DOM and JDOM comparisons, talking in "Simplifying XML Programming" with JDOM.

Limitations of W3C DOM Design:

Language is independent. This is not very obvious, and JDM also exists this problem.

Strict hierarchy. Using DOM programming very painfully, cumbersome explicit pull-up, what you have learned is often Node type, you must be able to change the type of mandatory conversion, especially the traversal of child nodes, the type of child node, Will spend a lot of spirit.

Interface driver. The things made by W3C are interfaces. When the actual program ran, the implementation class is obtained through the factory.

The method of finding the implementation of the DOM class is such

FactoryFinder.Find (

/ * The default property name accounting to the jaxp spec * /

"javax.xml.parsers.Documentbuilderfactory",

/ * The Fallback Implementation Class Name * /

"org.apache.crimson.jaxp.documentbuilderfactoryImpl");

The first step. First find the class name corresponding to the javax.xml.parsers.DocumentBuilderFactory from the system properties, and find the instantiation.

Step 2. From the $ java.home / lib / xml.properties, read the class name corresponding to the javax.xml.parsers.DocumentBuilderFactory, and find the instantiation.

The third step. None found on the Meta-Inf / Services / Directory in ClassPath, instantiation returned to the class name of the javax.xml.parsers.DocumentbuilderFactory file from the Meta-Inf / Services / Directory in ClassPath.

None, return Org.apache.crimson.jaxp.DocumentBuilderFactoryImpl instance.

With DOM, you don't have to implement the underlying implementation, with JDK to provide your interface and abstract class programming. If there is no DOM implementation in the package you introduced, JDK uses its own Org.Apache.crimson's stuff to implement the DOM.

The advantage of the DOM is that it is the standard of XML, the standard meaning is universal, he does not need you worry that the underlying implementation and environmental configuration does not need to introduce special packages, do not use a special configuration when making a system migration or environmental transplantation. But it is easy to say that the programming is easy to use, or use JDOM, Dom4j is much easier.

JDOM is dedicated to the Java platform. As long as it is possible, the API uses the built-in String support of the Java language, so the text value is also available for String. It also uses the Java 2 platform class, such as List and Iterator, providing programmers with a rich and similar environment with Java languages.

There is no hierarchy. In JDOM, the XML element is an instance of ELEMENT. The XML property is an instance of Attribute, and the XML document itself is the instance of Document. Since all of this represents different concepts in XML, they always be referenced as their own type, not as a vague "node."

Class driver. Because JDOM objects are direct instances such as Document, Element, and Attribute, create a new JDOM object as easy as the New operator is used in Java language. It also means that it is not necessary to make a factory interface configuration - JDOM is straightforward.

But JDOM has his advantages and his shortcomings. All your operations are based on classes. The portability is not as good as DOM. When the JDOM version is upgraded, or the system is transplanted, your code changes probably a big bit. two. XML operation library in JDK

JDK took yourself with corn and org.apache's Crimson. Crimson is an implementation version of the DOM, Xalan is an implementation of XSL Transformations (XSLT). Almost all of XML can be completed with these things.

Reference link:

What is the usage of XML in Java? Http://bbs.xml.org.cn/dispbbs.asp?boardid=41&id=8710

Simplify XML programming with JDOM

Http://www-900.ibm.com/developerWorks/cn/java/j-jdom/index.shtml

Treat XML document with JDOM

http://www.chinaunix.net/jh/26/15908.html

Tip: Conversion from JDOM

http://www-900.ibm.com/developerWorks/cn/xml/tips/x-tipcjdm/index.shtml

转载请注明原文地址:https://www.9cbs.com/read-123579.html

New Post(0)