Java Xml 简明教程
Java DOM Parser - Overview
Java DOM 解析器是一个 API(应用程序编程接口),它具有解析 XML 文档的类、接口和方法,方法是创建 DOM 树结构。
Java DOM parser is an API (Application Programming Interface) that has classes, interfaces and methods to parse XML documents by creating DOM tree structure.
文档对象模型 (DOM) 是万维网联盟 (W3C) 的官方推荐规范。它定义了一个使程序能够访问和更新 XML 文档的样式、结构和内容的接口。
The Document Object Model (DOM) is an official recommendation of the World Wide Web Consortium (W3C). It defines an interface that enables programs to access and update the style, structure, and contents of XML documents.
When to use Java DOM Parser?
你应在下列情况下使用 DOM 解析器:
You should use a DOM parser when −
-
You need to know a lot about the structure of a document.
-
You need to move parts of an XML document around (you might want to sort certain elements, for example).
-
You need to use the information in an XML document more than once.
What is the result of Parsing?
当您使用 DOM 解析器解析 XML 文档时,您将获得一个 tree structure ,其中包含了文档的所有元素。DOM 提供了多种功能,您可以使用它们来检查文档的内容和结构。
When you parse an XML document with a DOM parser, you will get a tree structure that contains all of the elements of your document. The DOM provides a variety of functions you can use to examine the contents and structure of the document.
Advantages
以下是一些 Java DOM 解析器的优点 −
Following are some advantages of Java DOM parser −
-
DOM is a very simple API to use.
-
Easy to access and modify any part of the document since entire document is loaded into memory.
-
Java code written for one DOM-compliant parser should run on any other DOM-compliant parser without having to do any modifications.