[Notes] use Java to perform XML programming (IBM DeveloperWorks)

xiaoxiao2021-03-06  71

Programming interface

Document Object Model (DOM, Document Object Model), Level 2 Simple API for XML (SAX), Version 2.0 JDM, JASON Hunter and Brett McLaughlin founded:

Use the DOM, SAX or JDOM to process the contents of the XML document. If you use DOM or SAX, use JAXP to create a parser. If you use JDOM, the JDOM library creates a parser for you. [ME] The parser is divided into verification and non-verification, generally using non-verified parsers in order to save time, etc. in the case of determining XML effective and in line with Document Type DEFINIT.

Document Object Model (Document Object Model, DOM)

Document Object Model (DOM) is a formal W3C recommendation standard. It defines an interface that enables the program to access and update the structure of the XML document. If an XML parser claims to support DOM, it means it implements the interface defined in this standard. At present, there are two levels of DOMs are formal recommended standards, wisely named DOM Level 1 and Dom Level 2. Dom Level 3 is expected to be officially released in early 2004. The DOM features discussed in this tutorial are part of the DOM Level 1, so these sample code can be used for any DOM parser.

SIMPLE API for XML (SAX)

SIMPLE API for XML (SAX) API is an alternative to handling XML documentation. Its design goal is less memory, but gives more work to programmers. SAX and DOM are complementary and have their own applicable environments. As a fact, SAX was originally developed by David Megginson, absorbing the idea of ​​many users on the Internet. For complete SAX standards, see Resources. Your parser document may also describe the SAX standard.

JDOM

Although SAX and DOM provide a number of useful features, some tasks are still too complicated for programmers. Continuation of open source communities requires the historical tradition of creating tools, Java Technical Experts Jason Hunter and Brett McLaughlin created JDM, which simplifies the processing of XML documents. Similar to the DOM, JDOM also provides an object tree represents an XML document, but these objects work more intuitive. To remember, JDOM contains adapters that use ordinary SAX or DOM parsers behind; JDOM provides adapters for all major (and several secondary) Java XML parsers, so don't worry if your Java XML parser is Support JDOM. JDOM uses a parser behind the scenes that does not require your interference.

How to choose a parser

I will discuss this later, generally said that the DOM parser should be used:

The structure of the document needs to change the structure of the document needs to change the structure of the document (maybe you need to sort the elements, add new elements, etc.) The information needs to be further promoted multiple times, in the following cases, SAX parsers should be used:

转载请注明原文地址:https://www.9cbs.com/read-119617.html

New Post(0)