Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNo next file
XML Streams Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

7.4 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.

7.4.1 Output Stream Example

To write out a string encoded in Shift-JIS, use following code.

//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.

7.4.2 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.

//1

Use the toBytes() method of the RWUString to convert from UTF-16 to Shift-JIS.



Previous fileTop of DocumentContentsNo linkNo next file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.