YOUR FEEDBACK
Werner Keil wrote: Java 6 update 10. If I'd be running Apple, I'd probably really drop dead...
AJAXWorld RIA Conference
$300 Savings Expire September 5th. Register Today and SAVE!


2008 East
DIAMOND SPONSOR:
Data Direct
Frontiers in Data Access: The Coming Wave in Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
Intel
Virtualization – Path to Predictive Enterprise
Green Hills
IT Security in a Hostile World
JBoss / freedom oss
Practical SOA Approach
GOLD SPONSORS:
Software AG
The Art & Science of SOA: How Governance Enables Adoption
PlateSpin
Effective Planning for Virtual Infrastructure Growth
Fujitsu
Automated Business Process Discovery & Virtualization Service
Ceedo
Workspace Virtualization
Click For 2007 West
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
XMLBeans

"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.

  • YOUR FEEDBACK
    What? wrote: "The last time I was this excited about a new SDK was probably when .NET 2.0 came out" OK, that's the funniest thing I think I've ever read in one of these articles. I didn't realize how completely sarcastic it was, but then I imagined Lewis Black reading it out loud and it finally made sense. This whole article is supposed to be a joke. If that's the case, I guess I'll play along: "Needless to say, my hopes and dreams came crumbling down when I realized that this new fangled iPhone device contained an operating system, and if that isn't bad enough, one that was based on some kinda open source garbage - not even windows CE (the nerve!). So I threw the thing out, and promptly started working on SharePoint Unleashed 2nd ed. where at least nobody has the gaul to use an undocumented API. Why are these people doing that? Huh? Why did they have to go and do that? I mean, wait for the...
    spinron wrote: Having bought and read the pre-release version of the book discussed here ("Rough-Cuts" edition, available on O'Reilly's site for $20), I tend to disagree with Kevin's opinion and lean more towards the book's author's view that the "unofficial" SDK, or the at least the API represented in it, are likely to more-or-less remain equivalent to the ones that would be exposed by the official Apple iPhone SDK. The iPhone platform implements a subset of the Mac OS X API which the book describes quite nicely. Why on earth would Apple want to re-invent a new API just for the iPhone SDK, after it's worked so hard to perfect its API over a decade? For spite, just to break the existing applications and necessitate a rewrite? Not a strong argument here. Seriously, get the rough-cuts edition now and read it. Consider it a preview for the official SDK. Most of the material it discusses is likely to rema...
    Endre Stølsvik wrote: I think this blog entry is stupid. If you're correct, and the book is about jailbroken iPhones, I think it is really cool of O'Reilly to flip the finger at Apple's idiotic attitude. "Confusing the developers" - are you insane or something? Do you believe that you are the only "developer" with more than about 6 brain cells? A "developer" that starts coding on an iPhone without realizing what he's really up against must be fully brain damaged. No, no one will be confuzed. Seriously. ColdFusion Developer's Journal - wow..
    germ wrote: Hello? There are a million hacked iPhones out there. Hacking the iPhone is the only reason to buy it.
    Brett wrote: Surely they can cater for the reality of iPhone usage in the market ? Hacking the phone and breaking the software license agreement isn't necessarily bad or illegal.. depends who you talk to... There are laws that support the consumer's rights to reverse-engineer their device, or to make changes to allow moving to a different carrier (eg the Digital Millennium Copyright Act). Just because it conflicts with the user's agreement with Apple doesn't make it a 'bad thing', it just means they might have to deal with some contractual consequences, or not...
    Pedro wrote: "How many potential developers might stumble upon the information on O'Reilly's site, follow the instructions to start coding, only to eventually realize that customers with unhacked phones can't run their apps??" I think that a person that starts writing code without even notice that it will work only with jailbreaked phones don't have any idea about iphone development and doesn't even deserve the "developer" title.
    iPhone News Desk wrote: So is O'Reilly actually condoning the hacking of the phones? O'Reilly has had a long and prestigious history as being the ultimate source for *nix manuals, including many books that became so dogeared I actually bought multiple copies, including dozens of 'in a nutshell' books.
    XML JOURNAL LATEST STORIES . . .
    To be able to do anything useful, an ESB must be configured with all sorts of parameters, from endpoint connection URIs to message transformation scripts to content-based routing definitions. Moreover, ESBs like Mule can host custom components, which will process messages and perform u...
    Representatives of the state IT organizations of Brazil, South Africa and Venezuela, three of the four countries that protested ISO’s standardization of Microsoft’s Office Open XML (OOXML) file format, have apparently thrown in the towel on taking their appeal any further. India, t...
    Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be...
    Red Hat CTO Brian Stevens, Citrix CTO Simon Crosby, Egenera CTO Pete Manca, Allen Stewart, Group Manager, Windows Virtualization at Microsoft, and Brian Duckering, Sr. Director of Products and Alliances at Symantec were the top industry executives who joined Jeremy Geelan in the 4th Fl...
    This article is aimed at beginner and intermediate Web developers looking to make the leap into database support of their Web site. The article suggests a new declarative language based on HTML-forms, which is used for development of the database interface. HTML forms can manage not on...
    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

    Security Challenges for the Information Society