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 subnodes 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 frequently used nodes, for example, the element object includes 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;
Because there are no association attributes 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. Commonly Used 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. When a file is retrieved, parse is used to parse the file. When writing the file, parse uses Dom to parse the file. It inherits the advantages of the two parsing methods.
About sax parsing:
In fact, the sax parsing also loads the file into the memory, but the cache area only has a size of about 3 m (you can use a large file and then print the start value in the characters method to observe ), assume that the file is very small and all files are loaded into the memory. If the file is very large, the cache area automatically clears the cache area and continues to load the expected data. The cache array is characters () method CH in the number of workers 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.