XML Streams Module User’s Guide : Chapter 7 International Features of the XML Streams Module : Using the XML Streams Package with the Internationalization Module
Using the XML Streams Package with the Internationalization Module
The Internationalization Module allows you to use a wide range of character encodings in your programs, and convert between these encodings with relative ease. If you need to insert or extract strings in a non-UTF-8 or non-UTF-16 encoding, you can use this module's conversion utilities.
Suppose you have a string in Shift-JIS that you need to insert or extract from an XML output stream. You will use the RWUString inserter and extractor interface object streams provided by the Advanced Tools Module’s Serial package. Because these interfaces take and produce UTF-16, you will need to convert your string to UTF-16 before inserting it into the output stream, and after extracting it from the input stream. To perform this conversion, you will use RWUString and the conversion utility classes of the Internationalization Module.
Output Stream Example
To write out a string encoded in Shift-JIS, use following code.
 
#include "rw/i18n/RWUToUnicodeConverter.h" // 1
RWCString myString;
// Initialize myString with characters encoded in Shift-JIS
RWUToUnicodeConverter fromShiftJis("Shift-JIS"); // 2
RWObjectOutputStream out = RWXmlObjectOutputStreamImp::make(cout);// 3
 
out << RWUString(myString, fromShiftJis); // 4
//1 Include the header file for the “to Unicode” converter class.
//2 Create a converter for converting from Shift-JIS to UTF-16.
//3 Create the XML output stream.
//4 Construct an RWUString (using the constructor that takes a second “converter” parameter) from the RWCString containing characters encoded in Shift-JIS. The constructor will convert the Shift-JIS characters to UTF-16. Then shift out the RWUString. The inserter for the XML output stream will convert the UTF-16 characters in the RWUString to the UTF-8 required by XML.
Input Stream Example
Similarly, if you want to read in a document containing a UTF-16 string and then convert the string to Shift-JIS, write the following.
 
#include "rw/i18n/RWUFromUnicodeConverter.h"
RWUFromUnicodeConverter toShiftJis(“Shift-JIS”);
RWObjectInputStream out = RWXmlObjectInputStreamImp::make(cin);
 
RWUString someRWUString;
in >> someRWUString;
someRWUString.toBytes(toShiftJis); // 1
//1 Use the toBytes() method of the RWUString to convert from UTF-16 to Shift-JIS.