You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by pundog <pu...@gmail.com> on 2008/03/23 15:50:32 UTC

Converting a DOMNode to std::string with Default OS codepage

Hi,
i'm looking for a way to convert a DOMNode into a std::string using the
operating system's default codepage.
in the DOMWriter class, there is a function called "writeNode" but when i
use it, i need to pass it an XMLFormatter, which requires me to specify the
encoding i want to use. However, in my personal situation, i don't allways
know which encoding i would like to use at runtime, so i would like to use
the default codepage set in my operating system's configuration.

Is there a way in xerces-c to convert a DOMNode using the operating system's
default codepage? or maybe theres a way to retrieve the default codepage?
(must be a cross-platform solution)

Thanks.
-- 
View this message in context: http://www.nabble.com/Converting-a-DOMNode-to-std%3A%3Astring-with-Default-OS-codepage-tp16236700p16236700.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Converting a DOMNode to std::string with Default OS codepage

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
pundog <pu...@gmail.com> writes:

>
> In my current situation, im dealing with an instance of DOMNode*, i looked
> for a way to maybe convert it to an XMLCh* and then use XMLString::transcode
> on it, but the only way i found to convert the DOMNode to XMLCh is using the
> DOMWriter's "writeToString" function, but the problem is that it allways
> uses UTF-16

Then what's the problem? XMLCh stores data in UTF-16. Pass whatever
writeToString returned to XMLString::transcode and you get the same
data in native encoding.

Boris

-- 
Boris Kolpackov, Code Synthesis Tools
Open source XML data binding for C++:   http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing: http://codesynthesis.com/products/xsde

Re: Converting a DOMNode to std::string with Default OS codepage

Posted by pundog <pu...@gmail.com>.
In my current situation, im dealing with an instance of DOMNode*, i looked
for a way to maybe convert it to an XMLCh* and then use XMLString::transcode
on it, but the only way i found to convert the DOMNode to XMLCh is using the
DOMWriter's "writeToString" function, but the problem is that it allways
uses UTF-16, so when i call it, all of my "exotic" characters turns into
garbage..

help? =\
Thanks for your reply

Boris Kolpackov-2 wrote:
> 
> Hi,
> 
> Here is one approach that might work:
> 
> 1. Serialize your XML into a memory buffer in UTF-16 encoding (
>    I think if you specify just "UTF-16" it will have the same
>    endian'ness as the machine on which this is performed, though
>    I am not 100% sure).
> 
> 2. Get the underlying buffer and cast it to XMLCh*.
> 
> 3. Call one of the XMLString::trascode functions to convert it
>    to a C-string in current/default encoding.
> 
> Boris
> 
> -- 
> Boris Kolpackov, Code Synthesis Tools
> Open source XML data binding for C++:  
> http://codesynthesis.com/products/xsd
> Mobile/embedded validating XML parsing:
> http://codesynthesis.com/products/xsde
> 
> 

-- 
View this message in context: http://www.nabble.com/Converting-a-DOMNode-to-std%3A%3Astring-with-Default-OS-codepage-tp16236700p16269977.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Converting a DOMNode to std::string with Default OS codepage

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi,

Here is one approach that might work:

1. Serialize your XML into a memory buffer in UTF-16 encoding (
   I think if you specify just "UTF-16" it will have the same
   endian'ness as the machine on which this is performed, though
   I am not 100% sure).

2. Get the underlying buffer and cast it to XMLCh*.

3. Call one of the XMLString::trascode functions to convert it
   to a C-string in current/default encoding.

Boris

-- 
Boris Kolpackov, Code Synthesis Tools
Open source XML data binding for C++:   http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing: http://codesynthesis.com/products/xsde

Re: Converting a DOMNode to std::string with Default OS codepage

Posted by pundog <pu...@gmail.com>.
Windows and Linux, the solution has to be cross platform
thanks.


Pete Cordell-5 wrote:
> 
> I might have missed it, but which OS are you using?
> 
> Pete Cordell
> Codalogic
> For XML C++ data binding visit http://www.codalogic.com/lmx/
> 
> ----- Original Message ----- 
> From: "pundog" <pu...@gmail.com>
> To: <c-...@xerces.apache.org>
> Sent: Sunday, March 23, 2008 2:50 PM
> Subject: Converting a DOMNode to std::string with Default OS codepage
> 
> 
>>
>> Hi,
>> i'm looking for a way to convert a DOMNode into a std::string using the
>> operating system's default codepage.
>> in the DOMWriter class, there is a function called "writeNode" but when i
>> use it, i need to pass it an XMLFormatter, which requires me to specify 
>> the
>> encoding i want to use. However, in my personal situation, i don't
>> allways
>> know which encoding i would like to use at runtime, so i would like to
>> use
>> the default codepage set in my operating system's configuration.
>>
>> Is there a way in xerces-c to convert a DOMNode using the operating 
>> system's
>> default codepage? or maybe theres a way to retrieve the default codepage?
>> (must be a cross-platform solution)
>>
>> Thanks.
>> -- 
>> View this message in context: 
>> http://www.nabble.com/Converting-a-DOMNode-to-std%3A%3Astring-with-Default-OS-codepage-tp16236700p16236700.html
>> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>>
>> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Converting-a-DOMNode-to-std%3A%3Astring-with-Default-OS-codepage-tp16236700p16249491.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Converting a DOMNode to std::string with Default OS codepage

Posted by Pete Cordell <pe...@codalogic.com>.
I might have missed it, but which OS are you using?

Pete Cordell
Codalogic
For XML C++ data binding visit http://www.codalogic.com/lmx/

----- Original Message ----- 
From: "pundog" <pu...@gmail.com>
To: <c-...@xerces.apache.org>
Sent: Sunday, March 23, 2008 2:50 PM
Subject: Converting a DOMNode to std::string with Default OS codepage


>
> Hi,
> i'm looking for a way to convert a DOMNode into a std::string using the
> operating system's default codepage.
> in the DOMWriter class, there is a function called "writeNode" but when i
> use it, i need to pass it an XMLFormatter, which requires me to specify 
> the
> encoding i want to use. However, in my personal situation, i don't allways
> know which encoding i would like to use at runtime, so i would like to use
> the default codepage set in my operating system's configuration.
>
> Is there a way in xerces-c to convert a DOMNode using the operating 
> system's
> default codepage? or maybe theres a way to retrieve the default codepage?
> (must be a cross-platform solution)
>
> Thanks.
> -- 
> View this message in context: 
> http://www.nabble.com/Converting-a-DOMNode-to-std%3A%3Astring-with-Default-OS-codepage-tp16236700p16236700.html
> Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>
>