Language :

TinyXML and std::wstring

Level management (and content) is easily done with XML files. On Windows Mobile, we can use MSXML which is part of the system. However, it sounds like it is slow to work with. Many people advise to use lightweight, non-validating parser. So I chose TinyXML.

However, everything related to the filesystem on WM is based on std::wstring. And TinyXML, even in it’s “USE_STL” implementation, only support std::string and char*. So I thought that before falling back to MSXML, I could try to convert TinyXML to std::wstring.

First, I searched and replaced everything => 

char* to WCHAR*

std::string to std::wstring

All methods ( such as atoi ) converted to their wide char equivalent (… _wtoi)

oh… and all these “String” to L”String” :)

Everything went pretty smoothly, and I was able to get it to compile. However, nothing was working. Here’s the 2 problems that needed to be solved :

1) My XML file was saved as a standard ASCII file, not containing wide chars. I used UltraEdit’s convert to unicode function, and this solved the problem. I could see in the debugger that the file content was all right. Still, it could not be processed.

2) TinyXML is “aware” of Microsoft’s UTF-8 headers – 3 bytes at the beginning of the file. But it does not check for UTF16 signature. I simply added a check for “FEFF”, at the same spot where the UTF-8 check is done, and this solved it.

I can not guarantee everything works, but all the functionality I needed, navigating through nodes and gettings values, work perfectly fine !

Comments are closed.