YOUR FEEDBACK
NGASI Releases AppServer Manager 8.1
Dave Jenkins wrote: The remote server management is a welcomed added feature...
SOA World Conference
Virtualization Conference
$200 Savings Expire May 16, 2008... – Register Today!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TODAY'S TOP SOA & WEBSERVICES LINKS


XMLBeans

Digg This!

"Java and XML - portable code and portable data." Even though this saying has been around since Java developers began using XML, developers have always faced a general XML programming-related productivity problem: manipulating XML content is rather different from manipulating Java objects.

This problem has been amplified with the emergence of XML Schema, the W3C standard type system for XML documents. While XML Schema provides a rich type system for XML documents, it isn't simple. Above all, the XML Schema type system differs significantly from the Java type system (e.g., the notion of simple types versus complex types, a rich set of predefined simple types, schema by restriction, etc.)

Several alternatives have already surfaced to solve some of these problems. For example, we have the tree-based Document Object Model (DOM), and the lower-level, events-based SAX (Simple API for XML), implemented by Apache Xerces, the almost de facto standard Java parser implementation. For Java programmers searching for a more natural object-oriented mechanism, there's the Java API for XML Binding (JAXB), which was recently released in its 1.0 specification. JAXB (covered in XML- Journal, Vol. 4, issue 1) intends to create a Java-XML binding framework that provides Java programmers with more natural object-oriented access to the underlying XML data. JAXB also supports XML Schema-based type binding (with some exceptions).

Recently, BEA released a beta of XMLBeans, an XML token stream-based technology that provides easy navigation of XML documents using a combination of interfaces - Java types (which have been mapped to the relevant XML Schema-based types) and native XML cursor- or XQuery-based access. The result is a technology that combines the benefits and convenience of manipulating XML data using a familiar Java type tree but doesn't sacrifice access to the underlying XML infoset.

Key Concepts
XMLBeans has three APIs, or mechanisms to manipulate XML data:

1.   XML Cursor: The XMLBeans implementation provides a simple DOM-like tree navigation API to the underlying XML document. This is available even if XML Schema (xsd files) are not compiled.

2.   JavaBeans: A set of XML Schema (xsd files), known as an XSD type system, is processed by a schema compiler to generate a set of Java classes and interfaces corresponding to the XML Schemas. A one-to-one relationship is maintained - one XSD type corresponds to a single Java type (or interface). All schema types are derived from the base class XmlObject. It's also useful to note that XMLBeans objects are serializable, so they can be transmitted over RMI boundaries. Similar to Java's inherent reflection capabilities, XMLBeans also provides capabilities to introspect the XSD Schema type through a set of classes. In the current beta implementation, the models available for schema compilation are a hosted compiler and the built-in support within BEA WebLogic Workshop.

3.   XQuery: With Apache Xerces2, XMLBeans provides the capability to run XQuery-based queries to query XML for specific data.

What differentiates XMLBeans from other Java binding technologies such as JAXB and Castor is the fact that XMLBeans supports two synchronized XML access models (see Figure 1) - one to the underlying XML content as well as one to the strongly typed Java classes. In addition, one of the primary objectives for XMLBeans (in its final release) is to provide 100 percent support of all features and capabilities in XML Schema (as specified by the W3C Recommendation).

Usage Scenario
Let's take a simple schema that represents a simplified order document. Listing 1 (as well as Figure 2) shows the XML Schema of an order (code for this article is available at www.sys-con.com/xml/sourcec.cfm). Listing 2 shows an example XML instance for the schema.

The next step is to generate a set of classes that represent the Order XSD type system. To do this, upload the Order.xsd file to BEA's hosted XMLBeans compiler on http://dev2dev.bea.com, which returns a JAR file (and source, if required) of the resulting interfaces/ classes. This JAR file can then be included in any project (EJB, Web, or even a stand-alone Java application) to process XML documents for the particular type. Listing 3 shows one such application - calculating the total order amount.

The JavaBeans-based type bindings generated by XMLBeans and JAXB are quite similar by design, which indicates that XMLBeans can almost be an upgradeable option to existing JAXB developers. It also hints at a possible convergence (hopefully!) of the two initiatives.

The fact that XMLBeans preserves the underlying XML content can be illustrated by invocation of xmlText() on the complete document object or a subelement such as lines[i]. You'll find that the call preserves the comments and the order of elements in the original document. This is particularly important in many application scenarios. For instance, if an XML-based configuration file is used, comments will typically be added to enhance readability. XMLBeans can be used to manipulate the content (read/write/update) but will also preserve the important information in it, such as comments. Another scenario in which preserving the original XML text is very important is an XML-based workflow application in which the content is significantly enhanced/processed as it follows the various activities in the application. Checking document validation is simply calling the validate method on the XmlObject (which is the super class of OrderDocument).

So far we've seen a mechanism by which we're simply reading the XML content; the type system generated by XMLBeans also includes full support of modification of XML elements and tags using the generated classes. Listing 4 shows one such example, in which a business rule, "10% discount to all items", is applied to the original XML document.

Running the sample program in Listing 4 will also illustrate that XMLBeans preserves the underlying XML content.

Support for XQuery
The example in Listing 5 uses XQuery to enlist the various lines in which the quantity is greater than 50. Of course, this is a limited usage of XQuery considering the various features that the new query language supports; however, it illustrates the support in XMLBeans. XQuery support does require Apache Xerces classes to be present in the classpath. (Note: for using the schema within Java applications, the only class required other than the generated schema types is the xmlbeans.jar runtime.)

BEA WebLogic Workshop
Support for XMLBeans is a key highlight of the new BEA WebLogic Workshop 8.1. The new version (recently announced at BEA eWorld) supports XMLBeans using a simple drag-and-drop mechanism. Once a schema file is uploaded into a current project, the corresponding schema JAR files are automatically created and the files are added to the project, ready to be available for the "code-complete" features in the tool. This capability is illustrated by Figures 3 and 4.

Note that while BEA WebLogic Workshop provides out-of-the-box support for XMLBeans-based schema type support, any IDE can be used to import the generated class files used in applications.

Availability
The beta is now available from http://dev2dev.bea.com. Currently, XMLBeans is available in two ways: as a hosted service from dev2dev.bea.com, and with WebLogic Workshop 8.1, which is available for download from dev2dev as well. One thing to be mindful of is that XMLBeans requires J2SE v1.4.

According to BEA officials, BEA plans to continue the support for hosted schema compilation service, which compiles schemas into Java classes. BEA is further exploring standardization efforts and ways to make XMLBeans broadly available through channels such as open source. However, there has been no official word on that yet. Support is available for XMLBeans through dev2dev-based newsgroups.

Conclusion
There has been some discussion in the industry that we need a different programming language with more native support for XML. We've also had discussions about how XML should be supported as a native data type in popular programming languages. XMLBeans clearly provides developers a viable, useful, and productive alternative for a number of scenarios in which they need to work with complex XML Schemas and have access to the underlying XML infoset. I'd really like to see technologies like XMLBeans merge and improve existing industry standardization initiatives such as JAXB (out of the Java Community Process).

Resources

  • Hosted XMLBeans Service (Beta): http://dev2dev.bea.com/technologies/xmlbeans/index.jsp
  • WebLogic Workshop 8.1 Beta: http://commerce.bea.com/showproduct.jsp?family =WLW&major=8.1&minor=-1
  • XMLBeans documentation: http://workshop.bea.com/xmlbeans/docindex.html
    About Hitesh Seth
    Hitesh Seth is chief technology officer of ikigo, Inc., a provider of XML-based web-services monitoring and management software. A freelance writer and well-known speaker, he regularly writes for technology publications on VoiceXML, Web Services, J2EE and Microsoft .NET, Wireless Computing & Enterprise/B2B Integration. He is the conference chair for VoiceXML Planet Conference & Expo.

  • XML JOURNAL LATEST STORIES . . .
    3rd International Virtualization Conference & Expo: Themes & Topics
    From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in midtown
    Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
    Red Hat is a trusted open source provider. Red Hat offers enterprise customers a long-term plan for building infrastructures on the quality and innovation of open source. Combining open source operating system platform, Red Hat Enterprise Linux, together with applications, management
    JustSystems Contributes Key XBRL Rendering Technology to Financial Community
    JustSystems announced that it is contributing intellectual property rights for its invention of eXtensible Business Reporting Language (XBRL) rendering technologies to XBRL International, the standards body responsible for the oversight of the XBRL specification. The invention, known a
    JustSystems Launches Campaign for XBRL Success
    JustSystems announced its campaign to help organizations adopt XBRL (eXtensible Business Reporting Language), the XML-based standard for communicating financial and business information. In related news, JustSystems also announced that it has contributed intellectual property rights of
    Virtualization Meets DaaS - Desktop-as-a-Service
    After a $1.5 million angel round, Desktone, which was started in 2006 by Eric Pulier, who also started SOA Software, US Interactive and IVT, picked up $17 million in first-round funding about a year ago from Highland Capital Partners, SoftBank Capital, Citrix Systems and the China-base
    SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
    SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
    Click to Add our RSS Feeds to the Service of Your Choice:
    Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
    myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
    Publish Your Article! Please send it to editorial(at)sys-con.com!

    Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

    SYS-CON FEATURED WHITEPAPERS


    ADS BY GOOGLE
    BREAKING XML NEWS
    RCG IT Addresses BI and SOA Convergence and Business Architecture at TDWI World Conference in Chicago
    RCG Information Technology, Inc. (http://www.rcgit.com/) will participate in The Data Wareho