Dom4j and JAXP parsing tools

Source: Internet
Author: User
Several objects in dom4j Parsing

Node

-- Branch

-- Document

-- Element

-- Commment

-- Attribute

-- Text

Branch

-- Document

-- Element

Several objects in JAXP Parsing

Node

-- Document

-- Element

-- Commment

-- ATTR

-- Text


Dom4j Parsing

All objects in are the child nodes of the Node object. That is to say, it separates all objects from each other as an object, while branch is an encapsulation and Association of common nodes, for example, the element object contains attribute objects and text objects, and the Document Object encapsulates all node objects.

JAXP Dom Parsing

The JAXP Dom parsing method does not have branch nodes and does not encapsulate each node. All operations are node nodes;

In addition, because there is no association attribute between nodes, You need to associate the nodes after creating them. You need to find the parent node When deleting the nodes.

Details: node nodes do not have the method to get attribute. Only element has the method to get attribute.

Dom4j parsing: common points of JAXP Dom Parsing

1. The results obtained by the conditional query are all a list set.

2. You can use node or element to Modify text or textcontent.


XML file parsing methods include Dom and sax. Common development tools include JAXP and dom4j.

JAXP: The two parsing methods are separated. Dom parsing and sax parsing are not supported.

Dom4j: combines the two parsing methods. It uses the sax Method for file retrieval and Dom parsing for file writing. It inherits the advantages of the two parsing methods.


About sax parsing:

In fact, Sax parsing loads documents into the memory, but the cache area is only about 3 m (you can use a large file and then print the start value in the characters method to observe ), if the file size is small, all files are loaded into the memory. If the file size is large, the cache area is automatically cleared after the cache area is slow and subsequent data is loaded. The cache array is characters () ch in the method parameter list.

That is to say, if you want to read a small document, you only need to rewrite this method, and then convert the character array into a string for printing, or obtain the response data based on the badge.

Public void characters (char [] CH, int start, int length ){

System. Out. println (new string (CH, 10, 2 ));

}

Then the reading of the document is actually equivalent to moving the pointer in the IO stream.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.