Dom4j parses XML strings

Source: Internet
Author: User
Tags cdata

Compared with the use of Dom, sax, and JAXP mechanisms to parse XML, dom4j is superior in performance, powerful in functionality, and extremely easy to use. As long as you understand the basic concepts of Dom, you can use the dom4j API documentation to parse XML. Dom4j is an open-source API. In actual projects, dom4j is often used as a tool for parsing XML.

Let's take a look at the inheritance relationships established by the DOM tree corresponding to XML in dom4j.

For the XML standard definition that corresponds to the content listed in Figure 2-1, dom4j provides the following implementation:

In addition, the nodetype enumeration of dom4j implements the node type defined in the XML specification. In this way, you can use constants to determine the node type when traversing XML documents.

Common APIs

 

Class org. dom4j. Io. saxreader

 

  • Read provides multiple ways to read XML files and returns a domcument object.

 

Interface org. dom4j. Document

 

  • Iterator uses this method to obtain the node
  • Getrootelement: Get the root node

 

Interface org. dom4j. Node

 

  • Getname: Get the node name. For example, get the root node name as bookstore.
  • Getnodetype: Get the constant value of the node type. For example, get the bookstore type to 1 -- element.
  • Getnodetypename: Get the node type name. For example, the obtained bookstore type name is element.

 

Interface org. dom4j. Element

 

  • Attributes returns the attribute list of this element
  • Attributevalue obtains the attribute value based on the passed attribute name.
  • Elementiterator returns the iterator containing child elements
  • Elements returns a list containing child elements.

 

Interface org. dom4j. Attribute

 

  • Getname
  • Getvalue

 

Interface org. dom4j. Text

 

  • Gettext

 

Interface org. dom4j. CDATA

 

  • Gettext: Get the CDATA section Value

 

Interface org. dom4j. Comment

 

  • Gettext

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.