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.