XSD/e: XML for Light-Weight C++ Applications
CodeSynthesis XSD/e is an open-source, dependency-free XML Schema to C++ compiler for mobile, embedded, and light-weight applications. It provides XML parsing, serialization, XML Schema validation and XML data binding while maintaining a small footprint and portability.
Provided with a schema, XSD/e generates C++ classes that represent the given XML vocabulary as well as parsing and serialization code. You can then access the data stored in XML using types and functions that semantically correspond to your application domain rather than dealing with the intricacies of reading and writing XML:
object* obj = ...; // Parse XML. const char* name = obj->name (); position& pos = obj->position (); float lat = pos.lat (); float lon = pos.lon (); delete obj;
<object> <name>Red Hill</name> <position> <lat>-33.69</lat> <lon>18.83</lon> </position> </object>
Manually handling XML in mobile and embedded applications with low-level APIs such as SAX and DOM traditionally leads to increased complexity, poor performance, and a large footprint. With XSD/e you can have all the benefits of using XML without any of the drawbacks. Your application stays small and fast and the code you write will be enjoyable to work with. XSD/e has been successfully used in the following mobile and embedded application domains:
- Mobile Applications (iOS, Android, Windows Mobile, Symbian)
- Automation, Control, and Telemetry
- Network Devices
- Flight Avionics
- Medical Equipment
XSD/e supports several distinct methods, called mappings, for manipulating the data stored in XML. The C++/Hybrid mapping creates a light-weight, tree-like object model of the XML data as shown in the code fragment above. Alternatively, you can forego the in-memory representation and process the data as it becomes available using the lower-level C++/Parser (for XML parsing) and C++/Serializer (for XML serialization) mappings. The C++/Hybrid mapping also supports the hybrid, partially in-memory, partially event-driven processing model which allows you to load/save XML documents a small fragment at a time. In addition to XML, you can serialize the object model into a number of compact binary formats, for example, for storage or over-the-wire transfer.
Based on the static analysis of the schema, XSD/e generates compact, highly-optimized hierarchical state machines that combine data conversion, validation, and even dispatching in a single step. As a result, the XSD/e-generated code is 2-10 times faster than general-purpose XML Schema validators while maintaining the lowest static and dynamic memory footprints. For example, a validating parser executable can be as small as 120KB in size and process a 10MB/s XML stream.
XSD/e is also highly-portable and can be configured to use the C++ feature set ranging from modern C++ to highly-restricted embedded C++. In particular, you can individually enable or disable the use of STL, RTTI, iostream, C++ exceptions, and custom memory allocators.
The following figure and feature list highlight the advantages of XSD/e in comparison to the traditional XML processing architectures:
- Ease of use. The generated code does data conversion and builds the corresponding in-memory object model for you. As a result, you are shielded from the intricacies of parsing and serializing XML.
- Validation. XSD/e provides low-footprint, high-performance XML Schema validation so that you don't need to complicate your code with extra error checking.
- Natural representation. You work with the XML data using your domain vocabulary instead of generic elements, attributes, and text.
- Static typing. The generated code is statically typed which helps catch errors at compile-time rather than at run-time. For example, XML element and attribute names become C++ function names so if you misspell one, the C++ compiler will issue an error.
- Concise code. Thanks to the object representation provided by the generated code, your business logic implementation is simpler and thus easier to read and understand.
- Maintainability. Automatic code generation minimizes the effort needed to adapt your application to changes in the document structure. Thanks to static typing, the C++ compiler will pin-point the places in your code that need to be changed.
These technical advantages translate to the following business-level benefits:
- Faster time to market. Instead of having engineers spend months or years on the boiler plate XML parsing code, let them concentrate on what makes your product unique—the business logic.
- Minimize risks. The generated code is more reliable and has fewer bugs thanks to the repeated and widespread use. Reduction in the amount and simplification of the application code the engineers have to write by hand further reduces the risks. XSD/e also comes with commercial-grade technical support unlike many open-source low-level XML parsers.
- Reduce costs. Automatic code generation is significantly cheaper than manual development. Furthermore, simplified business logic implementation means lower maintenance and development costs.