API_JSP programming FOR XML in Java

Source: Internet
Author: User
Tags soap xml parser xslt xslt processor
A brief introduction to Java's XML API so that you know what you're doing when you see the abbreviation. The level is limited, a lot of excuse.
  
1. JAXP (Java API for XML parsing)

2. JAXB (Java API for XML Binding)

3, JAXM (Java API for XML messaging)

4, Jax-RPC (Java API for XML-RPC)

1. JAXP defines a generic interface for using DOM, SAX, and XSLT in Java. So in your program you just use these generic interfaces, and you don't need to modify the code when you need to change the implementation. For example, the XSLT processor you're using is too slow, you want to change it, you don't need to change your previous code, just change the configuration of JAXP. As a common interface, JAXP also has what is called the "lowest denominator" effect, which means it supports a limited number of things. JAXP1.0 supports Xml1.0,xml namespace1.0,sax1.0 and DOM level 1. and JAXP1.1 increased support for sax2.0,dom Level 2 and XSLT1.0. Obviously if you want to use Xalan XPath-related interfaces, JAXP has no support, and you can only bind the code to a specific Xalan API.

Here's a mention of Jdom, which does not implement JAXP, but is popular because of its simplicity and becomes the API officially recommended by JCP. It is also a tree-like structural representation of XML, which is much simpler to use than the DOM standard of the consortium. The latest version of Jdom has already started using the JAXP API internally, it will try to invoke the Jaxp API as much as possible, and if not, use its own default XML Parser XERCES,XSLT processor Xalan.

2. JAXB defines a bidirectional mapping relationship between a Java data object and an XML structure. This allows you to easily store a Java object as an XML document, or you can instantiate a Java object from an XML document. Its structure is this: first, the XML DTD and the binding schema (this is not an XML schema, but an XML document that defines the mapping between Java objects and XML structures), With these two files, JAXB can generate a Java source file that is consistent with the XML document, and after compilation, it is easy to get the XML structure-consistent Java classes (that is, those generated classes) unmarshalling through specific XML documents. Conversely marshalling can also be.

It is also obvious that once the structure of the XML has changed, it is necessary to bindng the schema and regenerate the compiled Java class.

Sun's actions are always slow, and before JAXB comes up with some frameworks for XML data binding, let's take a look at the same framework that does the XML databinding but does not implement JAXB:

First, Castor

Castor not only supports binding to XML, it also supports LDAP objects, maps SQL queries to objects with OQL, and supports JDO. Unlike JAXB, it requires only XML schemas. Through the XML schema to generate the corresponding Java source code, after the compilation can be marshalling and unmarshalling.

Second, Zeus

Zeus has done more in class generation than Castor and JAXB, so it can support a variety of constraints, including support for Dtd,xml schemas, Trex, and so on. But the project seems to be out of date.

Three, Quick

Quick is also a very flexible framework, the details of which can be Google.

3, JAXM

JAXM is an API that provides access methods and transport mechanisms for SOAP traffic. It currently supports SOAP1.1 specifications as well as synchronous and asynchronous communication. JAXM defines a large number of services, and JAXM's implementation offerings will provide these services so that developers do not have to face complex communication systems. The JAXM architecture includes two important components: JAXM client and provider. The client is often used as part of the Java EE Web or EJB container to provide the ability of the program you write to access the JAXM service. And provider can be implemented in different ways, primarily responsible for sending and receiving SOAP messages. This allows you to directly send and receive SOAP messages directly using the JAXM API.

4, Jax-RPC

Jax-RPC is a Java API for remote procedure calls through XML. It is based on SOAP technology, using SOAP as the underlying protocol. So for developers, only methods, parameters, return values are visible, and the underlying soap traffic is hidden, and developers don't have to deal directly with it.

JAXM and Jax-RPC have an important role to play in Web services.

Add: JAXP Framework to find concrete implementation steps

JDK1.4 is the JAXP reference implementation: The Crimson DOM, the SAX parser, and the Xalan XSLT processor.

If you want to replace them with other implementations, you must understand the specific steps of the JAXP framework lookup implementation:

1, first of all, the algorithm will use such as Javax.xml.transform.TranformerFactory system attributes to locate the specific implementation of the class. You can specify directly on the command line:

Java-djavax.xml.transform.transformerfactory=com.foo.concretetransformer YourApp

Concretetransformer is a subclass of Transformerfactory, and if you are using ant, you can specify it in build file.

Likewise there are, javax.xml.parsers.document. Uilderfactory and Javax.xml.parsers.SAXBuilderFactory properties.

2. Then, if the system attribute is not specified, JAXP looks for the Lib/jaxp.properties property file in the JRE directory, which is composed of name=value like a normal properties file, assuming the following line:

Javax.xml.transform.transformerfactory=com.foo.concretetransformer

Then JAXP will use the corresponding Transformerfactory implementation.

In a Java program, you can get the directory where the JRE is located by using the following code:

String Javahomedir = System.getproperty ("Java.home");

Note, however, that if used in some Ides, the IDE will change the value of this java.home, such as JBuilder.

3, if Jaxp.properties does not exist or does not have a corresponding value, then JAXP will use the jar file's service provider to locate the correct subclass. Simply put, you can meta-inf/in the jar file Services directory to create a new file named Javax.xml.transform.TransformerFactory, this file has only one line: Com.foo.ConcreteTransformer on it.

4, finally, if the above 3 steps are not found any specific implementation, JAXP will use the default implementation: Crimson and Xalan.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.