Introduction to XML Data Binding in C++
Boris Kolpackov put together a full introduction to XML Data Binding in C++: “Anyone who has had to handle a large XML vocabulary using DOM or SAX can attest that the task is hardly enjoyable. After all, both DOM and SAX are raw representations of the XML structure, operating in generic elements, attributes, and text. An application developer often has to write a substantial amount of bridging code that identifies and transforms pieces of information encoded in XML to a representation more suitable for consumption by the application logic. Consider, for example, a simple XML document that describes a person:
<person> <name>John Doe</name> <gender>male</gender> <age>32</age> </person>
If we wanted to make sure the person’s age is greater than some predefined limit, with both DOM and SAX we would first have to find the age element and then parse the string representation of 32 to obtain the integer value that can be compared. Another significant drawback of generic APIs is string-based flow control. In the example above, when we search for the age element we pass the element name as a string. If we misspell it, we (or a user of our program) will most likely only discover this bug at runtime. String-based flow control also reduces code readability and maintainability. Furthermore, generic APIs lack type safety because all the information is represented as text. For example, we can compare the content of the gender element to an invalid value without any warning from the compiler:
DOMElement* gender = ...if (gender->getTextContent () == "man")
{
...
}
”
Read the full article from Artima. References are included at the end of the article, for those who need more information.
