Yesterday we talked about JSON parsing. Today we will look at XML parsing. It is also very common to need to parse xml in development. It is the same as JSON and is very similar.
XML is the abbreviation of Extensible Markup Language (Extensible Markup Language).
XML element is the basic unit of XML file content. Syntactically, an element contains a start tag, an end tag, and the data content between the tags.
The format is as follows:
This article Three of them will be introduced. dom4j, dom, xpath.
xml file:
DOM4J:
## dom4j is a very excellent Java XML API with excellent performance, powerful functions and extreme ease of use. It is the most used and is now used by many software. XPATH:##XPath is the XML path language (XML Path Language), which is a language used to determine the location of certain parts of an XML document. There are very detailed documents for developers to refer to, specific node path expressions.
You need to add jaxen-1.1-beta-6.jar when using xpath analysis.
DOM:
It loads the entire XML document into memory as an object, no matter how big the document is. It generally handles small files.
#There are many ways to parse XML, and the example is relatively simple. After getting the Document, you can look at the corresponding API to perform XML parsing, including parent nodes, child nodes, sibling nodes, etc. The idea is the same.
Let’s introduce the difference between Element and Node:
Element is an extension of Node, so it is more practical. For example, you can use Element to easily get the attribute getAttribute of Node. If you use Node, you can get an attribute set, and you need to search further to get the desired attribute. A node is not necessarily an element, but an element must be a node.
The above is the content of XML parsing. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!