Create a Customized Mapping
The mappings element in a HydraExpress project file defines a mapping between each XML element and a C++ type to be used during unmarshaling. For more complete information on the required and optional parts of a <mappings> element of a HydraExpress project file, see “Creating Customized Mappings,” in the HydraExpress XML Binding Development Guide.
The mapping must provide three items:
The C++ type
The code to be used to convert that type to and from the basic string type used (either
string or
RWCString). If you don’t specify any particular conversion code or information, the default is UTF-8.
The header file that provides the conversion code
The following HydraExpress project file maps XML Schema elements to C++ types and identifies two converters, one that converts from UTF-8 to the desired encoding, and one that converts back from the desired encoding to UTF-8.
<rwsf-codegen-project>
<options>
<option name='project-name' value='CharConvert'/>
...
</options>
<mappings>
<type xsdType="string" cppType="std::string"/> 1
<typeinfo cppType="std::string" include="international/myconverter.h"> 2
<fromString>convertToShiftJIS($value$)</fromString> 3
<toString>convertFromShiftJIS($value$)</toString> 4
<defaultValue>std::string("$value$")</defaultValue> 5
<initialValue></initialValue>
</typeinfo>
</mappings>
</rwsf-codegen-project>
Following is one possible way to create a character converter. This example uses the conversion methods of utility class
rwsf::XmlUtils.
// myconverter.h
#include <rwsf/core/XmlUtils.h> //1
#include <rwsf/core/CString.h>
#include <string>
class MyConverter
{
public:
static std::string convertFromShiftJIS(const std::string& str) { //2
return rwsf::XmlUtils::convertCharset(str, "Shift_JIS", "UTF-8");
}
static std::string convertToShiftJIS(const std::string& str) { //3
return rwsf::XmlUtils::convertCharset(str, "UTF-8", "Shift_JIS");
}
};