BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


A closer look at XML Data Binding, including a product appraisal (Part 3/3)
Promised Land XML Data Islands
JaxMe 2 as a Binding Mechanism
XML & Artificial intelligence
String Handling in Java
Interfaces in Java
Interfaces in Java
Hybrid Model Part One: SAX and DOM
Java 2 Platform Micro Edition (J2ME)


 
 

<< XSLT.NET and XML >>


By Simon Sprott
First Posted 09/06/2004
Times viewed 2371

A closer look at XML Data Binding, including a product appraisal (Part 2/3)


Summary An introduction to XML Data Binding, and a review of a number of the leading products.

This is the second part of this article exploring XML data Binding, see Part 1 for an overview of what XML Data Binding is, and Part 3 for a more detailed look at the nuts and bolts of going from an XSD to code. This section of the article will deal with some of products that are currently avalible.

Products

There are many products on the market, and if your schema is very simple and your using java then Castor is probably your best bet. There are already a number of good Castor articles out there and I don't intend to rehash them. However if you are not a Java developer, or your schema contains more advanced features (extensions, restrictions, substitution groups etc.), then you will need to look a little further a field. We have reviewed the main products on the market, and produced a simple summary of their capabilities. For the remained of this article we will refer to the generator provided by Liquid Technologies, as it supports the major schema's (DTD, XDR & XSD) and the main languages (C#, VB6, Java and cross platform C++).

There are also a number of important things to take into account when selecting a suitable product (free is not always cost cheap).

User Created Schema's If you are designing your own schema, then your in a position to tailor your schema to work around any limitations in the data binding product you select. Because of this even a fairly limited binding product can be expected to produce working code if the schema contains constructs that it can deal with. However, this approach may result in you compromising the design of your schema's, forcing you to use very simple constructs and types. These compromises may ultimately impact on the development of your project.

3rd Party Schema's The choice of products is more important when dealing with standard schema's. The problem with standard schema's is your not in a position to change them, you can sometimes tweak the way in which they are written but you can't change there meaning. So imagine you start off using a standard schema, and use a product like JAXB which initially works OK. Later the next version of the schema is released, and it makes use of more of the XSD standard (say extensions), and now JAXB won't work any more. What do you do? Your more or less back to square one. Your only real option is to go and look for a product that does support your new schema, but this will mean re-factoring all your existing code. So on balance it would be better to select a product that provides a large amount of support up front.

This section contains a review of the functionality supported by a number of the main XML Data Binding products.

Product Install Size Ease of Install Getting started Ease of Use Quality of Output Cost Overall Rating Comments (at a glance, see below for a full review)
Castor   6 3 3 62% Open Source 5 Getting up and and running with castor was a real pain. It can generate Java code for simple schema's. The code produced is straight forward and works reasonably well (see full review)
JAXB 46MB 8 7 7 55% ? 6 JAXB installs as part of suns web development toolkit. The install is simple and if you have JDK 1.4 installed, trouble free. A batch file is provided making it simple to use. Unfortunately JAXB fails to cope with anything more than the very basic XSD schema's (see full review).
Liquid Technologies XML Data Binding 11MB 9 8 9 87% £495 8.5 The XML Data Binding wizard installation is simple. Generating code is simple, using a basic wizard. The product can output code for Java, C#, VB6 & C++ (Win32, Solaris & Linux), and is capable of coping with the majority of the XSD standard (see full review)..
Microsoft's xsd.exe N/A N/A 5 7 61% N/A 6 Installs with Visual Studio .Net. The command line interface makes it a little bit annoying to work with. It copes with a good percentage of the XSD standard, but provides no validation, and still requires the user to have an good understanding of the target XSD (see full review)..
Functionality Summary

Gen - Generates code for schema's with these features Sup - Supports these features correctly in the code that is created.

Product Castor JAXB Liquid Tech Xsd.exe
Languages Supported
    C# (.Net)
    Java
    C++ (Win32,Linux,Solaris)
    Visual Basic 6
    VB.Net (.Net)
Product Castor JAXB Liquid Tech Xsd.exe
  Gen Sup Gen Sup Gen Sup Gen Sup
ComplexType groups
    Sequence *1*5
    Choice *4
    All *5
    Multiple Models, same complextype *1*5
Types
    Hex/Base64
    Date/Time/gMonthDay etc. *2 *2
    Collections of primitives *13
All primitive data types *18*19 *18 *18 *18
    unions *2 *2 *2
    any
    anyAttribute
    default values
    Pad chars (&<>" etc.) N/A N/A N/A N/A
    Strongly Typed Output N/A N/A  *23 N/A N/A  *10
Facets
    fractionDigits    
    length    
    maxExclusive *20 *18    
    minExclusive *20 *18    
    maxInclusive *20    
    minInclusive *20    
    maxLength    
    minLength    
    pattern     *9  
    totalDigits    
    whiteSpace  
Cardinality
    Optional *17 *5
    Mandatory *5
    Multiple *5*11
Enumeration's
    Enumerated Attributes *14 *22 *3
    Enumerated Elements *14 *22 *3
    0-n Enumerated Elements *14*15 *22 *3
Documentation
    Documentation Generation *21 *21 *21 *21    
    Include comments from Schema    
complexContent
    extension
    restriction *7 ?
    Different base model types ?
Schema
     Namespace
     Import ?
     Include ?
     groups    
     Recursively defined elements
     substitutionGroups
     Invalid names for the language
     Elements & attributes with same name ?
     Mixed elements *8 *8 *8 *8
                 
TOTAL 87% 62% 75% 55% 97% 87% 86% 61%

*1 No validation is done on the order that the elements are in *2 Treated as strings *3 Only applies on strings *4 A choice with 0 or many elements is falsely accepted *5 No validation is done to ensure mandatory fields are populated. *6 Ignores elements that are valid substitution elements *7 Allows child elements that have been restricted. *8 Can't handle mixed content (like HTML

textmore textSome More Text

'text' & 'Some More Text' get misrepresented; typically concatenated). *9 Supported on some data types *10 Choices, and some uses of extension cause un typed object's to be returned. *11 It is possible to produce invalid XML output *12 Elements are missing from the output *13 Strange bug whereby it invented 2 unsigned Byte elements with arbitrary values where only 1 is declared in the XML. *14 Enumeration's that are not based on strings, are named badly (value0, value1, value2 etc.) *15 No validation is done when setting values *16 No validation is done when reading XML *17 No support for optional groups (i.e. an optional sequence or choice) *18 All data types are supported but the validation rules are not applied to all of the types. *19 Many primitive types are not supported, resulting in code that does not compile (ENTITY, ENTITIES, name, token, UnsignedLong UnsignedInt, UnsignedShort, UnsignedByte) *20 Using facets on some data types (i.e. gDay) causes the output code to be invalid (i.e. not compile) *21 Creates JavaDoc comments *22 Enumerated types are supported but treated as primitives (no validation is performed) *23 Collections are not strongly typed.


Castor (0.9.5)

Castor is one of the first tools of its type. It provides XML & DB data binding for the Java framework. Before we start I should point out that I have only investigated the XML Data Binding functionality. Castor is capable of accepting a XSD files, and generates the source code for a Java library that allows serialization to and from XML. The generated code relies on xerces as its XML parser. The code generated is split; one class is generated to hold information contained in an XML element, a second class is generated that handles the marshaling to and from XML. This split has the advantage to keeping the memory footprint small, but does cause a large number of classes to be generated!

Castor is attractive to developers as it is Open Source, and seems pretty well thought out. It is however far from complete, there are a number of classes and areas of functionality missing. Because of this it copes well with simple schema's, but is unable to cope with the complexities of many of the real world standards.

Limitations include:

  • No support for extending elements (extension & restriction)
  • No support for substitution groups
  • No support for namespace's
  • Patchy support for primitive data types (name, token, ENTITY etc. are not supported)
  • Patchy support for facets.

In Summary; Castor is a good choice when working with simple schema's, it has a strong following and is still being improved. It is however, still a work in progress sporting an awkward command line interface . Eventually it may be smart choice but at the moment it is still maturing. Useful on small schema's, that you have direct control over. Try use this with an externally controlled schema, and your asking for trouble in the long run, when they add in features that Castor just can't deal with.


JAXB

JAXB is provided by SUN as part of their web development toolkit (I believe this makes it free, but I am unceratin of the exact terms of their license - check Sun's end user license). JAXB is something of a half hearted attempt, but is capable of generating Java code for very basic schema's, but give it anything real work and in chokes.

Limitations include:

  • No support for extending elements (extension & restriction)
  • No support for external elements (any, anyType)
  • No support for enumerated elements
  • Collections are not strongly typed
  • Does not work with Web Logic

In Summary; If the product you select has to be free use Castor, otherwise their is little reason to use JAXB.


Liquid Technologies - XML Data Binding Wizard (3.1)

The Liquid Technologies solution is one of the most complete products available, with almost complete support for XSD, XDR & DTD schema's. It also has the advantage of generating code for a number of platforms an languages - C#, Java, VB6, C++ (for Win32, Linux, HP & Solaris). It also produces a full set of documentation (chm & html) for the generated class library, making development simpler.

This product is ideal for dealing with both industry standard and hand made schema's . It is the only system currently available that is reliable enough to use on an evolving industry standard, as it is the only generator on the market that supports so much of the XSD standard.

Limitations include:

  • No validation on restriction's
  • No validation on unions

In Summary; This is the most complete system on the market (at the time of writing), making it ideal for user defined & industry standard schema's. The code generated is clean and easy to use, and the generated documentation is a bonus. This is however a commercial product, and as such needs paying for (£495), that said it should pay for itself within the week!


Xsd.exe (1.0.3705.0.)

Microsoft have taken a very minimal approach to there generator, the classes (C# or VB.Net) that are generated just contain public member variables that map to the XSD's attributes and elements, no accessors, no methods, nothing. The XML serialization is carried out by external libraries that come with the .Net framework. These classes use the attribute data (the stuff in square brackets) that is declared within each of the generated classes.

The generated classes allow many features of the XSD standard to be supported, however they provide practically no validation. They are quite happy to read in almost any XML, and will try to fit it into the generated objects. This is a significant limitation, but it can be mitigated by first reading the data into a validating XML DOM (validating against the schema), before loading it into the generated object model, this of course costs CPU cycles. Furthermore it is all to easy to populate objects that are themselves not valid against the schema, again this can be addressed by validating the output XML against the schema using a validating DOM parser.

Limitations include:

  • A lack of support for namespace's
  • Substitution groups
  • A lack of support for nested groups (sequences containing choices etc.).
  • Optional items with default values can't be excluded from the output XML.
  • All classes are generated into the same file, larger XSD's can become a little unmanageable.
  • Choices are represented as an un typed item, which can be cast to the appropriate type, when the type is ambiguous a property ItemsElementName is created, the name of this enumeration is ItemsChoiceTypeX making it difficult to pick the correct one for an element.

In Summary; the Microsoft offering is an elegant solution to the problem, the decision to avoid validation should make its code generation robust, however it is still unable to cope with a large number of XSD features that occur in many real world schema's This makes it unfit for use on large complex schema's, especially if you don't have the ability to change the schema yourself. It is however, free and simple to use, making idea for small projects in which you get to describe your own schema's


Rate this article on a scale of 1 to 10 (1 votes, average 5)

Your vote :  

<< XSLT.NET and XML >>





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML