Game Development Reference
In-Depth Information
C++: XSD library developed by Code Synthesis [CC 10];
Java: XStream library developed by Joe Walnes [Walnes 08];
Python: xmlobjects library developed by Mikeal Rogers [Rogers 08];
Ruby: XMLObject library developed by Jordi Bunster [Bunster 09].
XML data binding in C++. Because C++ is a common language used in conjunc-
tion with C#/.NET, let us take a look at how we'd make use of our existing XSD
from Listing 12.12 to automatically generate C++ classes. In my evaluation of C++
data binding libraries, the open-source XSD library from Code Synthesis [CC 10]
seemed the most robust. In order to not confuse the XSD library from XML schema
document (XSD), I'll refer to the library as XSDlib . XSDlib comes with example
programs, one of which is called “generated.” Once you've got the library and it's
dependencies installed, simply rename the original library.xml and library.xsd files,
copy the XML and XSD from Listings 12.5 and 12.13, and, respectively, rename
the new files. On first execution, you'll most likely encounter an error message:
error: no declaration found for element 'Characters' .Thiserroriscov-
ered in the XSDlib documentation and occurs because the validating parser cannot
find a schema for the XML document. There are a few ways to fix this issue:
passing the flag dont validate to the parse function in your driver module;
specifying the noNamespaceSchemaLocation in the original XML.
Since the generated example project that we are using generates all of the C++
code, including a sample driver to print out the parsed results, we'll use the second
option. We can simply modify our original XSL document from Listing 12.7 to
include a noNameSpaceSchemaLocation attribute:
<xsl:stylesheet xmlns:usos=
"urn:schemas -microsoft-com:office:spreadsheet"
version="1.0"
xmlns:xsl=" http: // www . w3 . org /1999/ XSL / Transform "
xsl:version="1.0">
<xsl:output indent="yes" />
<xsl:template match="/">
<Characters xmlns:xsi=
" http: // www . w3 . org /2001/ XMLSchema - instance "
xsi:noNamespaceSchemaLocation="library.xsd">
<xsl:for-each select=
"/usos:Workbook/usos:Worksheet/usos:Table/usos:Row">
<xsl:if test="position()!=1">
<CharacterData>
<xsl:for-each select="usos:Cell">
<xsl:variable name="cellPos" select="position()" />
<xsl:element name=
Search WWH ::




Custom Search