Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between xml parsing techniques?

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

What are the differences between xml parsing techniques? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Xml parsing technology has DOM,SAX,STAX, the difference is that the performance of DOM is very degraded when dealing with large files. SAX is an event-driven XML parsing mode, which reads XML files sequentially and does not need to load the whole file at once.

1.DOM generates and parses XML documents

Defines a set of interfaces for parsed versions of XML documents. The parser reads the entire document, then builds a tree structure that resides in memory, and the code can then use DOM

Interface to manipulate the tree structure. Advantages: the entire document tree in memory, easy to operate; support for deletion, modification, rearrangement and other functions; disadvantages: the entire document into memory (including useless nodes), a waste of time and space; use: once the document parses the need to access these data multiple times; adequate hardware resources (memory, CPU).

2.SAX generates and parses XML documents

In order to solve the problem of DOM, SAX appeared. SAX, event driven. When the parser finds the start of the element, the end of the element, the text, the beginning or end of the document, etc., it sends events, and the programmer writes code to respond to these events, saving the data. Advantages: no need to call in the whole document beforehand, and take up money

Fewer sources; SAX parser code is smaller than DOM parser code, suitable for Applet, download. Disadvantages: not persistent; after the event, if the data is not saved, then the data is lost; stateless; can only get the text from the event, but do not know which element the text belongs to; usage: Applet; only needs a small amount of content of the XML document, rarely go back to visit; machine memory is low

3.DOM4J generates and parses XML documents

DOM4J is a very good Java XML.

API, with excellent performance, powerful and extremely easy to use, is also an open source software. Now you can see that more and more Java software are using DOM4J to read and write.

XML, it's worth mentioning that even Sun's JAXM is using DOM4J.

4.JDOM generates and parses XML

In order to reduce the coding amount of DOM and SAX, there are the advantages of JDOM;: 20-80 principle, which greatly reduces the amount of code. Usage: the functions to be implemented are simple, such as parsing, creating, etc., but at the bottom, JDOM still uses SAX (most commonly used), DOM,

Xanan document.

How many forms are there for XML document definitions? What is the essential difference between them? What are the ways to parse XML documents?

Answer: a: two forms of dtd schema,b: essential difference: schema itself is xml and can be parsed by XML parsers (this is also the fundamental purpose of developing schema from DTD), c: there are DOM,SAX,STAX, etc.

DOM: its performance degrades very badly when dealing with large files. This problem is caused by the tree structure of DOM, which takes up a lot of memory, and DOM must load the entire document into memory before parsing the file, which is suitable for XML

Random access

SAX: DOM,SAX is not an event-driven XML parsing method. It reads XML files sequentially and does not need to load the entire file at once. When it encounters something like the beginning of a file, the end of a document, or the beginning and end of a tag, it triggers a

Event, the user handles the XML file by writing processing code in its callback event, which is suitable for sequential access to XML

After reading the above, have you mastered the different methods of xml parsing technology? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report