In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Today's goal: DOM, SAX, STAX, XML parsing API
Highlights of the day: JAXP DOM parsing, JAXP SAX parsing, XML PILL parsing.
XML has become a common format for data exchange. Because of its platform independence, XML is needed in many cases. Deep understanding of front-end knowledge is better able to solve automated exception problems.
I.
There are three ways to parse XML: DOM SAX STAX
The role of XML (enterprise applications): storing data, configuring files, and transmitting data.
Storing and transmitting data are often used together. XML data is usually generated programmatically and parsed programmatically (XML is generally unconstrained).
Configuration files are used alone (usually with constraints)
3、DOM
The full name is: Document Object Model.
DOM parsing idea: read the entire XML data into memory, form a document tree structure in memory,
Operates on the tree structure of documents in memory.
Pros: API is simple. Because the entire document is loaded at once, all the data in the document is in memory, so it is easy to handle
More convenient. XML file content can be modified frequently (i.e., written back).
Disadvantages: Need to load the entire XML document into memory, consuming system resources. slower. When XML documents are too large, it can cause
Unable to load all into memory, memory overflow problem.
**DOM is an official XML parsing standard developed by the W3C.
4、SAX
Simple API for XML Simple XML Parsing API.
SAX parsing idea: bind callback handler to parser, parser reads xml file, triggers corresponding event,
Automatically invoke the corresponding event method in handler
Advantages: SAX is a lightweight interface, parsing speed is fast, do not need to take up too much memory resources.
Disadvantages: SAX has to traverse the node from beginning to end every time, and modification is not easy to implement. Programming complexity, such as not retaining the data read in memory, will not be able to write back.
Note: If SAX and STAX save data while reading in memory, it is similar to DOM.
**SAX is a folk XML parsing standard from the XML community.
** Using "push" mode, PUSH.
5、STAX
The full name is: Streaming API for XML ,XML parsing stream API.
STAX parsing idea: Improve SAX schema parsing efficiency. Also read while processing.
** Use "pull" mode, PULL.
* *** The above three parsing methods: Performance comparison: STAX >SAX >DOM
6. What is Push Mode? What is a pull pattern?
PUSH: server-based, control operation flow mode.
When you hand a document and handler to the parser, the parser automatically parses it and calls the appropriate event handler method (this process is not under your control).
The server actively sends information to the client, and the client cannot intervene during the sending process.
PILL: client-based, control operation flow mode.
********
JAXP:
Java API for XML Processing.
It is an API. DOM, SAX and STAX are just XML parsing ideas. JAXP is DOM, SAX, STAX API concrete implementation.
Provided by SUN, JDK 6.0 fully supports DOM, SAX, STAX three parsing methods.
XML PILL: Pull schema parsing XML framework, built-in integration Android phone internal.
DOM4J: DOM parsing framework, open source. In enterprise Java EE software development. Develop frameworks for the most popular.
javax.xml core xml parsing API, DOM, SAX, STAX common API.
org.w3c.dom Specific APIs related to DOM parsing
org.xml.sax Specific APIs related to SAX parsing
The entire XML is parsed into a tree structure, elements, attributes, and text are parsed into Node nodes.
********
7, DOM parsing entry:
(i)
(1) Creating a parser factory
DocumentBuilderFactory builderFactory=DocumentBuilderFactory.newInstance();
(2) Obtain parser according to parser factory
DocumentBuilder documentBuilder=builderFactory.newDocumentBuilder();
(3) The parser reads the XML document for parsing and is a Document object (document object, representing the entire XML document).
Document document=documentBuilder.parse("test.xml");
(4) After obtaining the document document, you can operate on it.
For example, you can find the NodeList element with the specified name by getElementsByTagName.
NodeList nodeList=document.getElementsByTagName("name");
Then traverse the collection to get each Node.
for(int i=0;i
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.