Important note: It is with great sadness that we have decided to end-of-life Codalogic LMX. With XML becoming an increasingly legacy technology and Covid reducing new sales we can no longer viably support the product. As a result we will not be selling new licenses or renewing Annual Maintenance. We will honour existing Annual Maintenance commitments until they expire. We will be notifying existing licensees in due course.
If you have any questions about this, please contact us on .
Thank you.
This guide explains what C++ XML data binding is, how to use it and how it can help you speed up code development and reduce the potential for bugs.
Data binding is the process of transferring data from one representation to another, usually in an automated way. For example, in Windows programming, GUI controls can use data binding to load their data from a data base.
In the case of XML data binding with C++ the data is being exchanged between instances of XML documents (which could be in files or in memory) and C++ objects. Specifically in the case of XML data binding, the process of converting XML into programming language objects (e.g. C++ objects) is called 'unmarshalling' and the process of converting programming language objects to XML is called 'marshalling'. The terms 'de-serializing' and 'serializing' are sometimes used in these contexts also.
In C++ XML data binding the C++ objects that the XML data is marshaled to and from are instances of application specific C++ classes. In other words, a set of C++ classes are created that mirror the structure of the XML data. These C++ classes are generated automatically using tools such as Codalogic's LMX XML C++ Databinder during the code development process.
To generate the C++ classes, LMX needs to know the valid set of XML data that the C++ code will be required to handle. To do this, LMX uses a W3C XML Schema (also known as an XSD) description of the valid set of XML data. From this, Codalogic LMX can generate the C++ classes (see diagram). The generated C++ classes also contain all the logic needed to convert C++ object instances to XML, and to convert input XML to a set of C++ objects.
As part of this process the generated C++ code checks that the input XML conforms to the specified range of valid XML input as described by the XML Schema Description (XSD) from which the C++ code was generated.
Referring to the diagram once more, your code can then access the XML data by interfacing to the C++ objects that are instantiated from the generated C++ classes.
We will dig in more depth into how C++ XML data binding works later, but already from the above brief description it's possible to see some of the many benefits of using XML data binding with C++.
For example, your code doesn't need detailed knowledge of XML. Also, programmers on the development team don't need XML knowledge because they can interface to the data using standard C++ class interfaces that they already understand how to do. (Codalogic LMX XML C++ Databinder actually includes a number of features that help developers interface to the generated C++ code. This includes generation of an HTML documentation file, comments in the generated C++ .h file, and, in the case of the Windows WinLMX version, a dialog that allows dragging-and-dropping code snippets into your code.)
And with a number of software development IDEs, because the IDE understands the generated C++ code, you are able to use technology such as Intellisense to speed up the entry of C++ code.
Additionally, the amount of C++ code you have to write is generally less, and more self-documenting than other ways of accessing XML data further easing the software development process.
Hence XML data binding with C++ allows you to operate at a higher level of abstraction, which speeds up the code development process. It also means that more members of your programming team can access the data as they don't need detailed knowledge of XML technology in addition to their C++ skills.
Another benefit of using C++ XML data binding is that, because data is accessed via custom generated methods that are named specific to the XML being accessed, as opposed to using generic methods that have the names of desired elements as string parameters, the C++ compiler is able to do a lot of compile-time checking to ensure that the code you write is correct.
This compile-time checking greatly reduces the potential for accidently introducing bugs into your code, which, for example, can so easily happen as a result of cut-and-paste style errors that so readily happen when code has a large number of very similar code segments. Without these compile-time checks such bugs are only found at run-time, either as a result on extensive and costly testing, or, worse still, by your product's users.
Hence, C++ XML data binding enables you to more readily detect bugs, and also detect them very early in the code development process. Not only does this aspect of C++ XML data binding help reduce the number of bugs in your code, it also helps speed up the code development process.
In summary, the key benefits of using XML data binding with C++ are speeding up code development, and reducing bugs. Both of these gains help you reduce the cost of developing your product, helping you maximize the return on your investment.
Finally, because the generated C++ code is customized to the specific XML data used by your application, the performance is usual better than more general solutions.
C++ XML data binding is a tool and even we have to admit that, like all tools, there are jobs that C++ XML data binding is suited for, and those which it is not.
One of the key things about XML data binding with C++ is that it hides the details of the underlying XML. Therefore, if you want intimate detail about the structure of XML documents, such as information on XML comments and processing instructions, then XML data binding is likely not appropriate. For example, if you are transforming one XML document into another XML document, then there are more appropriate technologies available, such as XSLT. However, if XML is mainly a means to an end, then XML data binding is likely to be ideal.
XML data binding does require an XSD XML schema in order to generate the C++ code. Hence the XML documents' structure does have to be quite rigorously defined. If your XML documents are rather ill-defined, then you may find it difficult applying XML data binding to them. That said, we would recommend using an explicitly defined XML document structure where possible, and you may find that defining an XSD XML schema for your XML structure can be a very useful design exercise which gives structure to your XML data, and may potentially reduce interworking issues.
While XML data binding is useful when looking at XML tags in sequential document order, XML data binding really excels when you want random access to the data and you want to access the data in an order different to that in the original XML document.
This makes XML data binding ideal for machine-to-machine, and process-to-process communication such as communication protocols and web services. Similarly XML data binding is ideal for persisting program data in the same way that Microsoft Word persists Word documents. Similarly, XML data binding is great for storing application configuration information, such as user preferences. Such information can be read into objects at the start of the program, interrogated and manipulated as the program runs, and then saved at program shutdown.
When assessing XML data binding, it may be worth bearing in mind that your application may have a number of uses for XML, and different XML uses may be best served by different techniques. For example, just because part of your project needs more detailed access to XML data than XML data binding provides (such as XML comments and processing instructions), that does not mean that you should rule out XML data binding for the other parts of the project that could benefit from using XML data binding, as this may be the most efficient and expedient technique to handle those particular tasks. In such a scenario adopting XML data binding where it is appropriate may speed up implementation of those particular tasks, allowing you more time to focus on other parts of your project.
Finally, while discussing the suitability of XML data binding using C++ for your task, it's worth mentioning that not all XML data binding solutions are alike. For example, a number of C++ XML data binding solutions build an XML DOM-tree (using libraries such as Xerces) and then generate wrapper objects that interrogate the DOM-tree when a method is called to access a particular XML data item. Others first build a DOM-tree, and then build a C++ object structure from the data in the DOM-tree, discarding the DOM-tree once the C++ object structure is created. Using DOM in this way is inefficient. For a start generic schema-aware DOM parsers are generally large pieces of software, introducing undesirable software bloat into your product. Also, DOM-trees typically consume a large amount of run-time memory, increasing the resources your product needs to run. Accessing XML data via DOM methods can also require relatively large numbers of CPU cycles.
LMX does not use a DOM parser. Instead it has its own light-weight pull-parser. This allows the XML data to be streamed straight into C++ objects without using any intermediate form, increasing efficiency both in memory use and CPU cycles. The LMX XML pull-parser can be light weight because the generated code implements the constraints defined in the XSD XML schema, and therefore the LMX XML pull-parser does not have to be XSD schema aware.
Thus when deciding whether XML data binding is appropriate for your application, it's also worth considering the type of XML data binding technology you want to use.
Codalogic LMX XML C++ Databinder has many features, such a the ability to augment the generated classes with your own code, the ability to customize the names of methods, the ability to set and manage C++ and XML namespaces, the ability to customize string handling plus other aspects of XML to C++ type mapping, and many more.
To experiment with XML data binding using C++ we suggest downloading the evaluation version of Codalogic LMX XML C++ Databinder. This can be done from the download page. If you enter your e-mail address on the download page we can then send you a 30-day evaluation license that enables full functionality.
Providing exceptional support is very important to us. If you have questions about Codalogic LMX XML C++ Databinder, please send a message to .