XML data binding solution based on embedding templates in your C++ code and flexible object model. Instead of writing DOM code or XPath expressions, you put a XML template that is matched against the input XML. You can quote C++ variables or expressions within the template in order to check certain values or get values of attributes, elements or whole XML subtree. Generation of XML by templates is also supported.
Embite (EMbedded BInding TEmplates) is a set of tools that include a programming library and a C++ preprocessor which allow embedding XML statements with a given semantic within the C++ source. By this approach matching XML structures and reading values from them is done by templates, rather than hand written code. Same solution also applies to generation and outputting XML. Additionally, variables and expressions from the hosting C++ language can be quoted in the embedded XML templates. This provides easy and powerful mean for data binding between the XML structures and application data.
Main purpose of Embite is to be used when implementing XML communication protocols. For this purpose often is needed checking if the input XML corresponds to some structure and extracting well-known values from that structure.
Short example:
bool matched; embite::Element* input = GetXMLInput(); std::string name, sirname; int age; embiteGenerated::Match(matched, input, "<person name='%name' sirname='%sirname' age='%age'/>"); if(!matched) throw std::exception("Invalid XML input"); std::cout << name << " " << sirname << " " << age << std::endl;
The Embite preprocessor locates all embiteGenerated:: statements in the C++ file parses the XML template and generates appropriate code in place. This code calls the embite library which offers a suitable object model. Thus is achieved the semantic of the XML template. Note that the standard C++ syntax is not violated.
Implementation is based on libxml2 and libxml++. In future it may provide parser abstraction interface which will offer the option of seamless switching between parsers and even XML representation e.g. binary XML.
Nikola Tassev < ntassev AT embite DOT org >
Site under construction.