A Look at the Generated Converter
Given a simple schema identifying just one element in charConversion.xsd, such as
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="EncodedData">
<xs:complexType>
<xs:sequence>
<xs:element name="data" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
HydraExpress would generate a data class
EncodedData, a converter utility class called
CharConversionConverter.h, and a sample implementation,
charConversion_main.cpp. (For a basic discussion on the various classes and code created by HydraExpress for an XML Schema, see
Invoking the Generator with an XML Schema.Let’s look at the
rwsf::XmlUtils code that performs the conversion. The generated converter utility class
CharConversionConverter.h contains methods used internally to convert the simple types defined in the default datamap to and from the underlying string class,
string, used by HydraExpress. Generating code using the custom mapping in this example would result in the creation of an additional method in this class to convert your string, such as:
static std::string convertToString(const std::string& value,
std::string xsdType) {
return convertFromShiftJIS(value);
}
Note that this additional
convertToString() method calls the
convertCharset() method of
rwsf::XmlUtils to perform the conversion.
When HydraExpress comes across a string in UTF-8, it will convert it to Shift-JIS automatically.