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 Mike Ellery <mi...@s2technologies.com> on 2007/02/28 22:11:12 UTC
XMLBase64 into cdata section
I'm encoding some data using Base64::encode, which returns me XMLByte*.
Now I want to create a CDATA section using the encoded bytes - the
document's createCDATASection method takes XMLCh*. How do I get to here
from there? Do I need to use XMLString::transcode to get XMLCh?
Apologies if this is covered in the docs - I couldn't find it.
-Mike Ellery
Re: XMLBase64 into cdata section
Posted by David Bertoni <db...@apache.org>.
Mike Ellery wrote:
> I'm encoding some data using Base64::encode, which returns me XMLByte*.
> Now I want to create a CDATA section using the encoded bytes - the
> document's createCDATASection method takes XMLCh*. How do I get to here
> from there? Do I need to use XMLString::transcode to get XMLCh?
>
> Apologies if this is covered in the docs - I couldn't find it.
You could use a UTF-8 transcoder, but since the data is guaranteed to be
ASCII-only, you could simply copy each code unit:
unsigned int outputLength = 0;
const XMLByte* const bytes =
Base64::encode(
bytesIn,
bytesInLength,
&outputLength);
XMLCh* wideChars = new XMLCh [outputLength + 1];
for (unsigned int i = 0; i < outputLength; ++i)
{
wideChars[i] = bytes[i];
}
XMLString::release(&bytes);
wideChars[outputLength] = 0;
doc->createCDATASection(wideChars);
delete wideChars;
Dave