I am trying to receive a xml over HTTP and use CParser to parse it.
The HTTP API has MHTTPDataSupplier which returns a dataChunk which is a HBufC which is a 16 bit representation, But the CParser APIs need a TDesc8 and am having a problem with this inconsistency. If i try to just take the data chunk as a TptrC8 and create a HBufC8 from that, I am losing every alternate character as shown in the sample below.
Before conversion ::
<?xml version="1.0" encoding="utf-8"?><content><userid>578283</userid></content>
After Conversion ::
<xlvrin"."ecdn=uf8?<otn>uei>723/srd<cnet<
What is happenning is that the alternate characters are being lost in the 16 bit to 8 bit conversion!!!
can anybody help me on this,
Thanks in advance.
Here i am attaching my code pieces.
case THTTPEvent::EGotResponseBodyData:
{
// Get the body data supplier
MHTTPDataSupplier* body = aTransaction.Response().Body();
TPtrC8 dataChunk;
// GetNextDataPart() returns ETrue, if the received part is the last
// one.
TBool isLast = body->GetNextDataPart(dataChunk);
RDebug::Print( _L("***** ResponseBuffer length: %d"), dataChunk.Length() );
HBufC* buf = HBufC::NewLC(dataChunk.Length());
buf->Des().Copy(dataChunk);
RDebug::Print( _L("***** buf: %S"), buf );
// Append to iResponseBuffer
if (iResponseBuffer==NULL)
{
iResponseBuffer = buf->AllocL();
RDebug::Print( _L("***** ResponseBuffer: %S"), iResponseBuffer );
}
else
{
RDebug::Print( _L("***** ResponseBuffer content length: %d"), iResponseBuffer->Length()+buf->Length() );
iResponseBuffer = iResponseBuffer->ReAllocL(iResponseBuffer->Length()+buf->Length());
iResponseBuffer->Des().Append(*buf);
}
// xml parser StartParsingL method with TDesC
iXmlHandler->StartParsingL(*iResponseBuffer);
------------------
XmlHandler class
------------------
void CXmlHandler::StartParsingL( TDesC& xmlContent )
{
HBufC8 *pHeapUTF = CnvUtfConverter::ConvertFromUnicodeToUtf8L(xmlContent);
RDebug::Print( _L("***** content: %S"), pHeapUTF );
iParser->ParseBeginL();
iParser->ParseL( *pHeapUTF);
iParser->ParseEndL();
}
I tried with the following ::
HBufC* buf = HBufC::NewLC(xmlContent.Length());
buf->Des().Copy(xmlContent);
TPtrC8 representation((TUint8*)buf->Ptr(), buf->Size());
HBufC8* myBuf = HBufC8::NewLC( buf->Size());
myBuf->Des().Copy(representation);
RDebug::Print( _L("***** content8: %S"), myBuf );
Getting null characters at the end and missing even characters also.
Log information ::
26.975 ***** ResponseBuffer length: 80
26.975 ***** buf: <?xml version="1.0" encoding="utf-8"?><content><userid>578283</userid></content>
26.975 ***** ResponseBuffer: <?xml version="1.0" encoding="utf-8"?><content><userid>578283</userid></content>
26.985 ***** ResponseBuffer: <?xml version="1.0" encoding="utf-8"?><content><userid>578283</userid></content>
27.000 ***** content: <xlvrin"."ecdn=uf8?<otn>uei>723/srd<cnet<

Reply With Quote




