XSD/e: XML Processing for Embedded Systems
CodeSynthesis XSD/e is an open-source XML parser/serializer generator for mobile and embedded systems. It provides event-driven, stream-oriented XML parsing, XML serialization, XML Schema validation, and C++ data binding while maintaining a small footprint and portability. XSD/e implements three XML Schema to C++ mappings: Embedded C++/Parser for event-driven XML parsing, Embedded C++/Serializer for event-driven XML serialization, and Embedded C++/Hybrid which provides a light-weight, in-memory object model on top of the other two mappings.
The C++/Hybrid mapping generates C++ classes for types defined in XML Schema as well as parsing and serialization code. The C++ classes represent the data stored in XML as a statically-typed, tree-like object model and support fully in-memory as well as partially in-memory/partially event-driven XML processing. For an introduction to the C++/Hybrid mapping, refer to the Hello World Example from the Embedded C++/Hybrid Mapping Getting Started Guide.
The C++/Parser mapping generates validating C++ parser skeletons for types defined in XML Schema. You can then implement these parser skeletons to build your own in-memory representation or perform immediate processing as parts of your XML documents become available. For an introduction to the C++/Parser mapping, refer to the Hello World Example from the Embedded C++/Parser Mapping Getting Started Guide.
Similarly, the Embedded C++/Serializer mapping generates validating C++ serializer skeletons for types defined in XML Schema which can be used to serialize your data to XML. For an introduction to the C++/Serializer mapping, refer to the Hello World Example from the Embedded C++/Serializer Mapping Getting Started Guide.
Based on the static analysis of the schemas, 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. The following figure highlights the advantages of XSD/e in comparison to the traditional architectures:
XSD/e is also highly-portable and can be used without STL, RTTI, iostream, C++ exceptions, and C++ templates. Compared to APIs such as DOM, SAX, XMLReader, and XMLWriter, XSD/e has the following advantages:
- 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. The C++/Parser and C++/Serializer mappings provides low-footprint, high-performance XML Schema validation so 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 object model as well as parser and serializer skeletons are 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 benefits:
- Faster time to market. Instead of having your engineers spend months or years on the boiler plate 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 your engineers have to write by hand further reduces the risks.
- Reduce costs. Automatic code generation is significantly cheaper than manual development. Furthermore, simplified business logic implementation means lower maintenance and development costs.