Data binding object from XML to Java code

xiaoxiao2021-03-06  70

Data binding object from XML to Java code

Author: Time: October 8, 2004 14:38:01 Source:

9cbs

In this first part of the series of articles consisting of four parts, we will figure out what is data binding, what is its advantage over other methods of processing XML data in the Java application, and how to start using it. This section will examine why the data binding is used, and how to establish a model for a variety of constraints, so that the XML document can be converted into Java objects. It also covers inputs and outputs used to generate data binding classes. Do you want to use XML in your Java application? So good, with thousands of others together. When you know in depth, you will find the DOM and SAX API (see Resources), but it is a pan. You may think that there is certain simple way to get an XML document, and access it through the Java application, right? Don't use a callback or complex tree structure, but use methods like SETOWNER (STRINGOWNER) and INT GETNumOrDers ()? If you have considered a problem along this idea, the data binding is the solution you are looking for. Analyze a variety of choices today XML and XMLism are flooding (XSL, RDF, Namespace, RSS, XML Schema, Xslt ...), you may think that there will be many ways to access XML in the Java application. data. Surprisingly, if you find out if you find it, there is only three ways to access XML data. That's right - there are only three ways, one of which is still recently seen with a new Java API. It should be taken like this: The selection range makes it easier to select the method suitable for your method. The callback callback is working as an event drive model. When analyzing an XML document, some events-such as the start of the document and the start of character data in an element - will trigger the callback method. You can implement the Java code for these events by using the data required to perform logic. It is necessary to understand that this approach cannot be completely intuitive; developers usually take a period of time to understand and master the use of the callback model. SAX, a simple API for XML, is a factual standard for this XML usage method. Tree is more common, more popular is this API, which makes an XML document and then creates the tree structure of the data. The XML document has become a tree, which acts as a container. It has several child, such as root elements. The root element has its additional child, and it is pushed until (in a sense) obtains a picture of XML data. Because almost every college student has handled a tree structure at a certain stage, this can be used as a very intuitive way to represent XML data. The most popular API used for XML document tree representation is the recommended standard for W3C, namely document object model (DOM). An updated API, JDOM (this is not the first letter abbreviation) recently being promoted and popular. (Although this program is built with Jason Hunter, I have to say truth.) In addition, DOM and JDom are the basic requirements for Spinnaker scheme design, Spinnaker is a new XML analyzer, which is the Apache XML scheme. Some are under development. Although the tree API looks more easily than the event-driven SAX, they are not always suitable. Very large document may require a lot of memory (especially when using DOM); when the tree structure is converted (XSLT), the system may stop running even completely crash.

Although updated APIs (such as JDOM) can handle these issues, they will still be a problem if you have to handle extremely large amounts of data. Moreover, sometimes developers prefer to model data in the XML document into a simple reading and writing method without a tree model. For example, developers would rather not access the child node named Skunumber and set the text value of the node, and only want to call setskunumber ("mysku") and proceed. The term interpretation of data binding: A new method of accessing XML data within the Java application, using an API, JSR-031, still developed. JSR-031: Sun is still a new Java specification request in development, designed to compile XML documents into one or more Java classes, and can easily use these Java classes in the Java application. Package: Convert Java objects to XML representation, with the current value. Unpack: Create a Java object according to the XML object, usually generate a Java object based on the package. Upon access to XML data with Java code To rely on a new set of Java methods and related APIs, these APIs are still under development. Data binding is a "Java Specification Requirements" built by Sun, seeing a reference, it is designed to make Java objects to XML documents more convenient, so that a format can easily convert For another format, vice versa. Binding references a Java object with a read and write method, reading and writing methods affect the XML document on the bottom layer, and is also directly mapped to the names and features of the XML document. When you enter some details in this series of articles, this illustration will make more meaningful, but in the current, just say it is enough: this makes XML document characteristics Name can pass a setName () Method, change its value, just like I hint above. Data Binding This access method is being popularized and is particularly useful when storing configuration information in an XML document. Many developers have found that it is very convenient to access the required parameters without having to use a more complex tree structure. Although this access is not used for document conversion or messaging, it is extremely convenient for simple data processing. It is our third use of XML in this article and this series of articles. (Of course, any method will then take a range of new terms, so please see the term explanation to understand these new jars.) Can any XML documentation can be converted to a Java object? Or just some types of XML documents can you? Asked! You are likely to simply want to convert documents that meet a set of constraints to Java objects. This is similar to the way to define the Java interface: You make sure you only instantiate and use objects that adapt to the interface, allowing how to operate the object to make assumptions. Similarly, you only allow XML objects that meet a set of constrained conditions to Java objects; this allows you to use the created objects as desired.

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

New Post(0)