Shallow Java XML programming (reposted)

xiaoxiao2021-03-06  48

Shallow Java XML programming

Author: He Shuangjiang (yarshray) for Xml, my understanding is that a standard format used to store the data to see how I feel and XML Html, completely different, maybe just use the mark as a documentation explains the reasons for it. So people like to compare XML and HTML. For I personally, XML is a simple and convenient data file. Because. Its different and general relational databases, see two-dimensional table. Basic The relationship operation, get the data in the two-dimensional table. XML only uses the data as a document, and then parsing the document parsing data. So my opinion is to operate the XML document, as long as a document interpreter that can explain XML can be explained. Then put the contents of the explanation. The data required to transition into procedures can be written back. Therefore, this is mainly introduced to the XML document interpreter, and Java-related API. They are DOM And SAX. And JDom. We need a simple XML as an example of this article: This XML's main purpose is to store my book information. Including the title of the book, the book of the book, the book number Several basic information, XML examples are as follows: Programming Pearl Jon Bentley 7-5083-1914-1 28.0 Java programming idea (2nd edition) < / bookname> Bruce Eckel 7-111-10441-2 99.0 Inside VCL (in-depth core VCL architecture) Li Wei 7-5053-9489-4 80.0 This XML records three books and their related information. In the body, an XML document can be divided into three steps.

• Verification and non-verified parsers? Support one or more parsers for XML Schema language? Support Document Object Model (DOM) parser? Support SIMPLE API for XML (SAX) parser

Here mainly introduces two. Interpreter. Document Object Model (DOM) interpreter: The DOM interpreter is a standard interpreter API, which is officially developed by W3C. As long as the programming interface is compliant, you can use to operate XML. Currently There are three levels of the unit .level1 Level2 Level3 Only discussed to the Level2.dom model actually converts the data in the XML file into a tree in memory. The tree is constructed of the Doument Nodelist Element. And DOM It is responsible for analyzing the structure of this tree, and then explains the role of the XML document by explaining the tree. It is worth noting that the interpreter is not clearly clear. For example, attributes Value: ID = "1" ID = "1" ID = '1' This is exactly the same for DOM. Because. For the format DOM of the document, do not explain. It is only converting data in the document into one The trees have, the original document format does not appear in the DOM. Simple API for XML (SAX) parser SAX interpreter, can be said to be a programming that leaves the interpretation work to the programmer Model. It does not load the entire XML document into memory as the DOM, but the progressive explanation and use these notifications by the event notification, and the specific program uses these notifications, and then processes, which seems to write the code-driven code. Thus SAX is applicable to the user's occupancy and interpretation efficiency. There is a specific application surface for specific environment DOM and SAX. SAX events mainly include StartDocument events for the document StartDocument events for elements for elements. StartElement and endelement For the Characters event for handling character text, enddocment events JDOM API DOM and SAX have provided a huge burden on developers. Because they are more complicated, the open source community is launched Jason Hunter and Brett Mclaughlin two Java experts launched JDOM as a relatively simple API.jdom will provide the adapter to select the specific XML interpreter. Similarly it also provides a tree structure to process XML, while JDOM So more short. Therefore, it is a bit of DOM and SAX. Of course, it also reduces flexibility. So if you use JDOM is also a nice choice. Three APIs for this DOM model: The whole document structure is a whole understanding The situation that needs to modify the document structure multiple references the document multiple times SAX Model: Solid memory has limited conditions, only need to read the XML part of the element, only need to reference the XML document once XML Document Object Model (DOM) Introduction: The purpose of the W3C is launched to provide a good analysis structure. Used to operate the markers in XML. This model is similar to the HTML marker analysis model. It provides a set of operational interfaces that can be implemented by each specific platform. So you can select any programming interface provided by the DOM-satisfile interpreter. Implementation application. It will be easily ported to other platforms that implement the DOM programming interface. For standard DOM. It provides an interface that describes the object of the XML document tree structure, and through these objects The application can be operated on the XML document. And the application will call these objects and object operations. It is equal to the operation XML file. This simplifies the operation of the XML file. Make the programming interface enough abstraction. So, it is to be familiar with DOM programming Model Our primary is to familiarize yourself with the objects and methods provided by the DOM. Below we are familiar with the objects and methods provided by DOM: Document: The object is described through the entire XML document. That is, the whole tree. Representing the overall object containing many nodes. Node: Node: Node: Node is a relatively abstract concept, so Node is described as an interface in Java definition. The interface extends several sub-interfaces. Element: Representation The element attribute in the document: indicates the attribute text in the XML file: indicating that the other node type in the node includes: Comment Represents the comment in the XML file, the processinginstruction represents the processing instruction, and CDATASECTION indicates the CDATA section.

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

New Post(0)