java XML

Introduction to XML:

Extensible Markup Language (Extensible Markup Language), uses simple markup to describe data.

XML documents follow the basic rules of XML documents, elements are properly nested

The first line of the XML file must be an XML declaration, and there can only be one root node

Among them, there are differences in the size difference of English characters.

The start control tag and the end control tag are indispensable, and the attributes added by the tag must be quoted

Special characters in the document can be replaced by solid characters or <![CDATA[ output characters as they are]]>

The order of properties declared in the document cannot be reversed

XML advantages : simplicity, good readability, extensibility, easy cross-platform application

The role of XML : data storage, data exchange, data configuration

Parse XML using DOM:

1. Basic idea

Document Object Model (Document Object Model)

DOM maps XML documents into an upside-down tree, where each node is an object

2. Basic Concepts

Document

The Document object represents the entire XML document

All other Nodes are contained within the Document object in a certain order

It is also the starting point for operations on XML documents

Node

It is the most basic object in the DOM structure, representing an abstract node in the document tree

In actual use, the Node object is rarely used.

Instead use child objects of Node objects such as Element, Attr, Text, etc.

NodeList

Refers to a list containing one or more nodes (Node)

You can simply think of it as an array of Nodes

Element

Represents a tag element in an XML document

Inherited from the Node object, it is the main sub-object of Node

3. Basic steps

Create a parser factory object

Create a parser object from a parser factory object

The parser object parses the specified XML file, builds the corresponding DOM tree, and creates a Document object

Take the Document object as the starting point to add, delete, modify, and query the nodes of the DOM tree.

4. Disadvantages

Without encapsulating more details, the code is cumbersome

        5. Advantages:

Based on XML tree structure, it is helpful for better understanding and mastery, and the code is easy to write   

During the parsing process, the tree structure is stored in memory, which is easy to modify and is suitable for accessing XML multiple times.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324621530&siteId=291194637