Home Backend Development XML/RSS Tutorial Introduction to JAXP parsing of xml parsing methods

Introduction to JAXP parsing of xml parsing methods

Feb 16, 2017 pm 03:41 PM

 XML解析	
		1 引入
		xml文件除了给开发者看,更多的情况使用[程序读取xml文件]的内容。这叫做xml解析
		2 XML解析方式(原理不同)
			DOM解析
			SAX解析
		3 XML解析工具
				DOM解析原理:
						1)JAXP (oracle-Sun公司官方)
						2)JDOM工具(非官方)
						3)Dom4J工具(非官方)
							三大框架(默认读取xml的工具就是Dom4j)
						.......

				SAX解析原理:
						1)Sax解析工具(oracle-sun公司官方)
Copy after login

The following introduces the parsing principle of JAXP:


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

org.w3c.dom:Provides a standard interface for parsing XML##DOM

org.xml.sax: Provides SAX way to parseXML's standard interface

javax.xml:provides parsing XMLDocument class

l

javax.xml.parsersIn the package, several are defined Factory class. We can get the DOM and SAX## that parse the XML document by calling these factory classes. #Parser object.

DocumentBuilderFactory

SAXParserFactoryl

javax.xml.parsers#DocumentBuilderFactory in the package is used to create DOMPattern parser object , DocumentBuilderFactory is an abstract factory class, which cannot be instantiated directly, but this class provides a newInstance method, which will According to the parser installed by default on the local platform, a factory object is automatically created and returned. Process:


##

调用 DocumentBuilderFactory.newInstance() 方法得到创建 DOM 解析器的工厂。

调用工厂对象的 newDocumentBuilder方法得到 DOM 解析器对象。

调用 DOM 解析器对象的 parse() 方法解析 XML 文档,得到代表整个文档的 Document 对象,进而可以利用DOM特性对整个XML文档进行操作了。
Copy after login

The specific code to obtain the document object is as follows:



//1. 获得工厂 
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		
		// 2. 拿到 builder 对象
		DocumentBuilder builder = factory.newDocumentBuilder();
		
		//3. 拿到 代表book.xml文件的document 对象 
		// ctrl+1 --- 提示 快速  分配一个变量值 
		Document document = builder.parse("src/book.xml");
Copy after login




##The next article will include an interlude - unit Test the framework, and then introduce some CRUD examples to have an intuitive understanding of JAXP parsing xml.


The above is the introduction to JAXP parsing of xml parsing method. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Use Gin framework to implement XML and JSON data parsing functions Use Gin framework to implement XML and JSON data parsing functions Jun 22, 2023 pm 03:14 PM

In the field of web development, XML and JSON, one of the data formats, are widely used, and the Gin framework is a lightweight Go language web framework that is simple, easy to use and has efficient performance. This article will introduce how to use the Gin framework to implement XML and JSON data parsing functions. Gin Framework Overview The Gin framework is a web framework based on the Go language, which can be used to build efficient and scalable web applications. The Gin framework is designed to be simple and easy to use. It provides a variety of middleware and plug-ins to make the development

Java Error: XML Parsing Error, How to Fix and Avoid Java Error: XML Parsing Error, How to Fix and Avoid Jun 24, 2023 pm 05:46 PM

As Java becomes more and more widely used in the Internet field, many developers may encounter the problem of "XML parsing error" when using XML for data parsing. XML parsing error means that when using Java to parse XML data, the program cannot parse the data normally due to incorrect data format, unclosed tags, or other reasons, thus causing errors and exceptions. So, how should we solve and avoid when facing XML parsing errors? This article will explain this issue in detail. 1. XML parsing

How to solve the problem of high memory usage of XML parsing in Java development How to solve the problem of high memory usage of XML parsing in Java development Jun 29, 2023 am 09:37 AM

XML is a commonly used data exchange format. In Java development, large-scale XML files often need to be parsed. However, since XML files often contain a large number of nodes and elements, traditional XML parsing methods can easily lead to high memory usage. This article will introduce some methods to solve the problem of high memory usage of XML parsing. Using the SAX parser SAX (SimpleAPI for XML) is an event-driven XML parsing method. Compared to DOM (DocumentO

How to use PHP to parse XML and obtain node content How to use PHP to parse XML and obtain node content Jun 13, 2023 pm 04:31 PM

When developing web applications, XML is a very important data format that can be used in scenarios such as data exchange and information sharing. In PHP, we can use built-in functions and third-party libraries to parse and manipulate XML. Below we will discuss how to use PHP to parse XML and obtain the content of the nodes in it. Parse XML files First, we need to parse XML files. PHP provides two main methods to parse XML: 1.1. Using SimpleXML SimpleXML is within PHP

Solution to solve Java XML parsing exception (XMLParsingException) Solution to solve Java XML parsing exception (XMLParsingException) Aug 19, 2023 pm 01:43 PM

Solution introduction to solving Java XML parsing exceptions (XMLParsingException): When processing XML files, we often encounter XML parsing exceptions (XMLParsingException). This is caused by XML file format errors or incorrect XML parser configuration. This article will introduce some common XML parsing exceptions and solutions to help developers better deal with these problems. 1. The cause of XML parsing exception is parsing XML document.

A guide to XML parsing and generation in PHP A guide to XML parsing and generation in PHP Jun 11, 2023 am 11:01 AM

With the development of the Internet, XML (Extensible Markup Language) has become a popular data exchange format. In PHP, XML parsing and generation are very important skills because PHP is often used to process XML documents. This guide will introduce how to parse and generate XML documents in PHP to help developers better master this skill. 1. XML parsing XML parsing is the process of converting XML documents into data structures in PHP. PHP provides two main XML parsing methods, DOM and SimpleX

PHP8.1 update: enhanced XML parsing capabilities PHP8.1 update: enhanced XML parsing capabilities Jul 07, 2023 am 09:22 AM

PHP8.1 update: Enhanced XML parsing function With the rapid development of the Internet, XML (Extensible Markup Language) plays an important role in data exchange and information transmission. As a universal data format, XML is often used to transfer and store data between different applications. In order to provide better XML parsing capabilities, PHP8.1 has enhanced the XML parsing function to provide developers with more convenience. In PHP8.1, an important improvement is the introduction of libxml_disabl

How to reduce XML parsing memory usage in Java development How to reduce XML parsing memory usage in Java development Jun 30, 2023 pm 09:19 PM

How to solve the problem of XML parsing occupying too much heap memory in Java development Introduction: With the explosive growth of information and data, the importance of XML (Extensible Markup Language) in enterprise application development continues to increase. However, you may encounter problems with excessive heap memory usage during XML parsing, especially when dealing with large XML files. This article will introduce some methods and techniques to solve this problem. 1. Understand the XML parsing process. Before we deeply solve the problem of XML parsing occupying too much heap memory, we first understand the basics of XML parsing.

See all articles