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

Example Analysis of JAXP parsing in xml

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the example analysis of JAXP parsing in xml, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

XML parsing 1 introduces xml files not only to developers, but also to programs that read the contents of xml files. This is called xml parsing 2 XML parsing (different principles) DOM parsing SAX parsing 3 XML parsing tools DOM parsing principles: 1) JAXP ( Oracle-Sun official) 2) JDOM tools (unofficial) 3) Dom4J tools (unofficial) three frameworks (the default tool for reading xml is Dom4j ). SAX parsing principle: 1) Sax parsing tool (oracle-sun company official)

Here is an introduction to the parsing principle of JAXP:

The lJAXP: (Java API for XML Processing) development package is part of JavaSE and consists of the following packages and their subpackages:

Org.w3c.dom: provides a standard interface for parsing XML in DOM mode

Org.xml.sax: provides a standard interface for parsing XML in SAX mode

Javax.xml: a class that provides parsing XML documents

In the ljavax.xml.parsers package, several factory classes are defined. We can call these factory classes to get the DOM and SAX parser objects that parse the XML document.

DocumentBuilderFactory

SAXParserFactory

The DocumentBuilderFactory in the ljavax.xml.parsers package is used to create a parser object for the DOM schema. DocumentBuilderFactory is an abstract factory class that cannot be instantiated directly, but it provides a newInstance method that automatically creates a factory object and returns based on the parser installed by default on the local platform.

Process:

Call the DocumentBuilderFactory.newInstance () method to get the factory that creates the DOM parser. Call the newDocumentBuilder method of the factory object to get the DOM parser object. Call the parse () method of the DOM parser object to parse the XML document to get the Document object that represents the entire document, and then you can manipulate the entire XML document using the DOM feature.

The specific code for obtaining the document object is as follows:

/ / 1. Get the factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance (); / / 2. Get the builder object DocumentBuilder builder = factory.newDocumentBuilder (); / / 3. Get the document object / / ctrl+1 representing the book.xml file-prompt to quickly assign a variable value Document document = builder.parse ("src/book.xml") Thank you for reading this article carefully. I hope the article "sample Analysis of JAXP parsing in xml" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report