![]() |
Languages »
XML »
JAXB
Beginner
License: The Code Project Open License (CPOL)
Creating XML and Java Technology Based Applications Using JAXBBy KoundinyaExplains about the concepts of JAXB and compares it with JDOM and JSAX. |
Java, Java, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
When my company asked me to work on this article for the client, I got a chance to work with JAXB concepts. I wanted to share my knowledge with you guys so that this will be helpful to me and people who are working on Java XML concepts.
eXtensible Markup Language (XML) is a platform and language-independent way of defining tags. XML allows you to use meaningful tags to represent data in a structured format. Unlike HyperText Markup Language (HTML), which is used to display text, XML is a language to create extensible custom tags to represent the structure of data.
SAX parser is an event driven low-level parser, that responds to the elements of an XML document as it parses through the documents. The data is not maintained in memory. Efficiency of parsing data into elements is the key feature of SAX parser. DOM parser is a high-level parser that maintains the data structures of a document in memory as it parses through the document. This helps you to manage and manipulate data as needed. DOM API follows the tree model for maintaining the data in memory.
Formerly known as Project Adelard, Java Architecture for XML binding (JAXB) combines the benefits of Document Object Model (DOM) parser and Simple API for XML (SAX) parser.
JAXB reduces the execution time significantly and creates a robust object model for enterprise level applications.
This reference point explains how to use JAXB to create and distribute high-performance XML-enabled applications with minimum effort.
This table describes the important components used in XML:
| Component | Description |
|---|---|
| Element tags | Used to describe elements |
| Processing Instructions | Special instructions to the XML processor |
| Document Type Declarations (DTD) | Used to carry out structure bound data modeling |
| Entity references | Used to represent the aliases of an entity data |
| Comments | Used to identify and highlight the importance of a specific function/procedure in an XML document. Similar to other conventional packages, XML processors and parsers do not consider comments while compiling |
| Marked Sections | The data in an XML document, which are marked, will not be processed or parsed by XML applications, although the data is valid for parsing and processing XML documents. |
XML parsers are used to check whether XML documents are well formed or not. In addition, they are used to convert XML nodes into Java objects or elements. There are two types of parsers: validating and non-validating. Validating parsers verify that the XML document conforms to a DTD or a schema.
A Java application that uses XML technologies needs to parse the data objects of XML. The parsing is done based on the schemas and DTDs that are defined for that particular document. You can use various technologies to parse an XML document into Java objects. Some of which are SAX, DOM and JAXB.
You can use JAXB API to map XML documents to Java objects. You can use JAXB API and tools to marshal or convert XML contents to Java objects. You can access and validate the Java objects against a schema. In addition, you can use JAXB API to un-marshal or convert Java objects into an XML document.
JAXB provides a layer of abstraction between XML documents and Java applications. This helps you develop enterprise applications. JAXB applications can match the speed of SAX by using the binding mechanism, which maintains information in the memory.
In addition, JAXB can convert data in XML elements into equivalent valid Java objects and set constraints with the help of XML schemas or DTDs.
JAXB frees you from writing and debugging the XML parsing codes. With generated conversion codes, you can write the applications that can access the XML documents through normal Java data interfaces.
You can extend the functionalities for the generated class codes. In Java applications, you may want to have control over the XML schema components through the Java objects. For this, you can customize the binding schema for the different needs.
Because of the object orientation, JAXB based applications are helpful to access multiple XML documents.
The difference between JAXB and SAX are:
Although both JAXB and DOM have data storage capabilities, JAXB applications are specific to a single schema, whereas DOM applications can be managed with multiple schemas. JAXB applications are faster than DOM applications.
Since JAXB applications are specific to a single schema, they can utilize memory more efficiently in comparison to DOM applications.
The basic components required for XML data binding are:

Complex data contents defined by using DTD or Schema in an XML document are bound to the content interfaces, which are generated by a JAXB compiler. Simple contents such as attributes and elements of an XML node are directly bound to the properties of the content interfaces and can be accessed through setter and getter methods. Using properties, you can reference two interfaces at the same time. You can effectively use the generated classes as both content interfaces and implementation interfaces to extend the functionality, which makes JAXB architecture more flexible and competent.
Binding Framework API helps you to compile XML Schema and Java classes for marshalling and un-marshalling of Java objects.
When you bind DTD with a binding schema:
You can use:
If you do not mention the attribute types for components in the binding schema, the schema compiler uses the default String data type.
You have to validate a binding object against three constraints:
#PCDATA-only elements. The Java programming language ensures that a schema constraint is checked at compile time and dynamically generates the available methods for the attribute mentioned in the schema. For example, if you have a schema constraint attribute by the name String, the derived methods will be:
public void setName (String name);
public String getName ();
The enforcement performs a run-time check and throws an exception on failure. This is best suited for type constraints that do not map directly to the Java classes or primitives.
For example, if an attribute is constrained to an integer value between 0 and 100, the set method can possibly throw a run-time exception when the value passed to the method is out of range.
The enforcement performs a check at run-time and throws an exception on failure.
IDREF has a corresponding ID. The steps that you need to follow before working on JAXB generated classes are:
For getting information about XML based technologies:-
I would like to share my knowledge with you guys and wanted to update this article by putting some extra information. Please help on this so that it will be helpful for me and the persons who are working on Java XML.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 28 Apr 2003 Editor: Chris Maunder |
Copyright 2003 by Koundinya Everything else Copyright © CodeProject, 1999-2010 Web10 | Advertise on the Code Project |