XML Data Binding

Altova XMLSpy® includes a built-in code generator that automatically generates Java, C++, or Microsoft C# class files based on data elements defined in an XML Schema. An overview of the simple two-step code generation process is illustrated in the following figure:

xml data binding

XML Schema is ideally suited for data modeling in modern software applications because it supports the concept of datatypes and object-oriented design. This enables XML Schema to bridge the gap between the relational database model and current object-oriented software design methodologies.

What is an XML Data Binding?

An XML data binding is a mapping of one or more XML data elements to a set of related software objects. Implementation of a data binding for XML data elements is required because XML is not a full programming language, in that it cannot be compiled or executed as stand-alone binary executable file. Rather, XML documents must be bound to an external software application or runtime environment such as a business-to-business application or Web service.

An XML data binding allows you to work programmatically with XML documents from within your software application via a set of simple objects. It can be thought of as an abstraction layer between an XML document and your custom application (business logic), alleviating the need for developers to understand the technical intricacies of loading, editing, and saving, an XML document using low-level XML parsing APIs.

The following figure shows a typical example of the application of a data binding in a Web Services application, located in between the inbound XML stream and custom business logic:

xml data binding

Today, there are many tools that create the SOAP "plumbing" - i.e. the client/server stubs and skeletons required to marshal an XML document from one process to another - yet you still must write a data binding to process the inbound XML documents within a SOAP envelope and create the appropriate XML message in response. The XMLSpy code generator can automate the tedious process of implementing a data binding, freeing a developer to focus on implementing business logic.

Implementing an XML Data Binding

Implementing an XML data binding involves writing infrastructure code to create, read, update and delete an XML document in memory using low-level XML processing APIs such as the Simple API for XML Parsing (SAX) or the Document Object Model (DOM). In addition to the basic infrastructure methods, a data binding must include additional higher level functions/methods to validate, process, transform, and perform other common in-memory operations on an XML document. XMLSpy automates this task by providing a simple menu item that can generate program code based on an XML Schema, as shown below:

xml data binding

Implementation of an XML data binding is a tedious, error-prone task, requiring dozens, and possibly hundreds of class files. For example, consider the following data model of a company organization chart, which consists of data elements such as Office, Department, Person, Address, etc. (Click on screenshot to see full data model.)

xml data binding

In this example, the generated program code data binding consists of 24 classes and thousands of lines of code.

XMLSpy Code Generation

Following is a summary of XMLSpy code generator features:

  • Default templates to automatically generate class definitions corresponding to all declared elements or complex types that redefine any complex type in your XML Schema
  • Preservation of class derivation as defined by extensions of complex types in your XML Schema.
  • Support for Java, C++, and Microsoft C# program code output.
  • Support for industry standard XML processing APIs including Microsoft MSXML, Java API for XML Processing (JAXP), and Microsoft System.XML
  • The generated C++ output includes a Visual Studio 6.0 project file; the generated Java output is includes a Sun Forte for Java project file and Apache Ant build script; Microsoft C# output includes a Visual Studio.NET project file.
  • Output code is completely customizable via a simple yet powerful template language that gives full control in mapping XML Schema built-in data-types to the primitive datatypes of a particular programming language.
  • You can easily replace the underlying parsing and validating engine, customize code according to your company's writing conventions, or use different base libraries such as Microsoft Foundation Classes (MFC) and Standard Template Library (STL).
  • Ability to build your own templates to automate the generation of anything imaginable, e.g., SQL scripts, ASP or WML code.
  • Generation of project files for Borland C# Builder and other third party IDEs including MONO.

The following screenshot shows just how easy it is to generate an XML data binding using XMLSpy:

xml data binding

The XMLSpy graphical XML Schema editor is a well equipped software modeling and prototyping tool that allows XML applications to be rapidly prototyped at a high level in XML Schema and then automatically generated. Changes to an application's XML Schema content model can be immediately reconciled with a software implementation simply by re-running the code generator. Built-in code generation frees software developers from the mundane task of writing low level infrastructure code, enabling them to focus on implementing critical business logic. By automatically generating a programming language binding, XMLSpy accelerates project development time from initial design to final implementation, resulting in substantial cost savings and time to market advantages.