Java Xml 简明教程

Java JDOM Parser - Overview

JDOM 是一个基于 Java 的开源库,用于分析 XML 文档。它通常是一个对 Java 开发人员友好的 API。它经过 Java 优化,并且使用类似 List 和 Arrays 这样的 Java 集合。

JDOM is an open source, Java-based library to parse XML documents. It is typically a Java developer friendly API. It is Java optimized and it uses Java collections like List and Arrays.

JDOM 与 DOM 和 SAX API 配合使用,并且结合了这两个 API 的优点。它的内存占用量低,并且速度几乎与 SAX 一样快。

JDOM works with DOM and SAX APIs and combines the best of the two. It is of low memory footprint and is nearly as fast as SAX.

Environment Setup

为了使用 JDOM 解析器,您应该在应用程序的类路径中包含 jdom.jar。下载 jdom-2.0.5.zip.

In order to use JDOM parser, you should have jdom.jar in your application’s classpath. Download jdom-2.0.5.zip.

When to Use JDOM parser?

您应在以下情况下使用 JDOM 解析器 −

You should use a JDOM parser when −

  1. You need to know a lot about the structure of an XML document.

  2. You need to move parts of an XMl document around (you might want to sort certain elements, for example).

  3. You need to use the information in an XML document more than once.

  4. You are a Java developer and want to leverage Java optimized parsing of XML.

What is the result of Parsing?

使用 JDOM 解析器解析 XML 文档时,灵活地可以将包含所有文档元素的树形结构返回,而无需影响应用程序的内存占用空间。

When you parse an XML document with a JDOM parser, you get the flexibility to get back a tree structure that contains all of the elements of your document without impacting the memory footprint of the application.

如果文档结构良好且结构已知,JDOM 会提供各种实用函数来检查 XML 文档的内容和结构。

JDOM provides a variety of utility functions that you can use to examine the contents and structure of an XML document in case the document is well structured and its structure is known.

Advantages

以下为 JDOM 解析器的优点 -

Following are the advantages of JDOM parser −

  1. Developer friendly API.

  2. Flexible and easily maintainable.

  3. Lightweight and quick API

  4. Well integrates with DOM and SAX standards.

JDOM classes

JDOM 定义了几个 Java 类。以下是常见的类:

JDOM defines several Java classes. Here are the most common classes −

JDOM Methods

使用 JDOM 时,经常会使用多种方法 -

When you are working with JDOM, there are several methods you’ll use often −