Differences in how DOM and sax read XML

Source: Internet
Author: User

There are two main methods of manipulating XML: Dom and sax. Dom will read the entire XML into memory, parse into a tree, so take up memory, parsing slow, the advantage is that you can arbitrarily traverse the tree node. Sax is a stream pattern, side-reading side parsing, memory-intensive, parsing fast, the disadvantage is that we need to handle the event ourselves.

1. The DOM is memory-based and, regardless of the size of the file, pre-loads all the content into memory. Thus consuming a lot of memory space. and Sax is event-based. When an event is triggered, a portion of the corresponding XML data is obtained, regardless of the size of the XML file, which consumes only a small amount of memory space.

2. The DOM can read XML or insert data into an XML file, while Sax can read only the XML and not insert data into the file. This is also a disadvantage of sax.

3. Another disadvantage of Sax: Dom We can specify the elements to be accessed for random access, while sax is not. Sax is traversed from the beginning of the document. And can only be traversed once. This means that we cannot access the XML file at random, and we can only traverse the XML file once from beginning to end (or, of course, truncate the traversal).

Differences in how DOM and sax read XML

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.