Java se xml< two >xml dom and sax parsing

Source: Internet
Author: User

[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

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.