Xml parsing technologies include DOM, SAX, and STAX. The difference is that DOM's performance drops significantly when processing large files. SAX is an event-driven XML parsing method. It reads XML files sequentially and does not require Load the entire file all at once.
1.DOM generates and parses XML documents
Defines a set of interfaces for the parsed version of the XML document. The parser reads in the entire document and then builds a memory-resident tree structure, and then the code can use the DOM
interface to manipulate the tree structure. Advantages: The entire document tree is in memory, easy to operate; supports multiple functions such as deletion, modification, and rearrangement; Disadvantages: Transferring the entire document into memory (including useless nodes) wastes time and space; Usage occasions: Once parsed Documents also need to access this data multiple times; hardware resources are sufficient (memory, CPU).
2.SAX generates and parses XML documents
To solve the problem of DOM, SAX appeared. SAX, event driven. When the parser finds the beginning of an element, the end of an element, the beginning or end of text, a document, etc., it sends events, and programmers write code that responds to these events and saves the data. Advantages: There is no need to load the entire document in advance, and it takes up less resources; the SAX parser code is smaller than the DOM parser code, and is suitable for Applet and download. Disadvantages: not persistent; after the event, if the data is not saved, the data is lost; stateless; only text can be obtained from the event, but it is not known which element the text belongs to; Usage occasions: Applet; only XML document A small amount of content, rarely revisited; less machine memory;
3.DOM4J generates and parses XML documents
DOM4J is a very, very excellent Java XML
API with excellent performance, powerful functions and extreme ease of use features, and it is also an open source software. Nowadays, you can see that more and more Java software is using DOM4J to read and write XML. It is particularly worth mentioning that even Sun's JAXM is also using DOM4J.
4.JDOM generates and parses XML
In order to reduce the amount of coding of DOM and SAX, JDOM appeared; advantages: 20-80 principle, greatly reducing the amount of code. Usage occasions: The functions to be implemented are simple, such as parsing, creation, etc., but at the bottom level, JDOM still uses SAX (most commonly used), DOM,
Xanan documents.
How many forms are there in XML document definition? What are the essential differences between them? What are the ways to parse XML documents?
Answer: a: two forms of dtd schema, b: essential difference: the schema itself is xml and can be parsed by an XML parser (this is also the fundamental purpose of developing schema from DTD), c: there are DOM, SAX, STAX etc.
DOM: Its performance drops significantly when processing large files. This problem is caused by the tree structure of the DOM. This structure takes up a lot of memory, and the DOM must load the entire document into the memory before parsing the file. It is suitable for
random access to XML
SAX: No Now in DOM, SAX is an event-driven XML parsing method. It reads XML files sequentially without loading the entire file all at once. When encountering an event like the beginning of the file, the end of the document, or the beginning and end of a tag, it will trigger an
event. The user can process the XML file by writing processing code in its callback event, which is suitable for sequential access to XML
The above is the detailed content of What are the differences between xml parsing technologies?. For more information, please follow other related articles on the PHP Chinese website!