[Document Collation Series] Java se xml< two >xml dom and sax parsing
XML programming: CRUD (Create Read Update Delete)
Two common ways to parse xml:
DOM (Document Object Model):
Features: Tree-like parsing
Pros: "Better for (CRUD) operations on XML documents." "Easy and flexible for adding and deleting XML documents
Cons: Memory consumption is very large, not suitable for large data volumes, many nodes of XML documents.
SAX (Simple API for XML):
Features: From the top down to the order of analysis
Advantage: "Small footprint, fast resolution, only suitable for reading data." 】
Disadvantage: "CRUD operations on XML documents are not appropriate." "It is very inconvenient to change and delete XML documents."
Common analytic Development Package: JAXP (Sun), jdom,dom4j
======================================================================
Because of the differences in memory requirements for the parsing of the last two XML documents:
Need to----tuning JVM memory
=============================================
DOM parsing programming
Traverse all nodes
Find a Node
Delete a node
Update node
Adding nodes
==============================================
Updating an XML document
The transformer class in the Javax.xml.transform package is used to output the Document object that represents the XML file into a format, such as converting an XML document into an HTML document after applying a stylesheet table. This object, of course, can also be updated to write the document object to an XML file.
The transformer class completes the conversion operation through the transform method, which receives a source and a destination. We can do this by:
1.javax.xml.transform.dom.domsource class to associate the Document object to be converted
2. Destination of data using Javax.xml.transform.stream.StreamResult object
Transformer object obtained by transformerfactory
Document (node)--->domsource (Source)--->streamresult (Result)--->outstream
Transform (Domsource,filestream)
Domsource Transform
Transformfactory
Java se xml< two >xml dom and sax parsing