Got what I was missing :) Actually I needed to give doc->createTextNode(mlEventPtr->getComponentName().c_str()); Instead of doc->createTextNode(mlEventPtr->getComponentName());
c_str() function returns wchar_t* for a log4cxx::String Its working now. Thanks a lot for your help! -----Original Message----- From: Kamdar, Devang (MLITS) Sent: Friday, February 29, 2008 4:44 PM To: [email protected] Subject: RE: How to convert from wchar_t* to XMLCh*? Thanks Alberto for the response, I tried using the function directly in createTextnode as: DOMText* businessFlowElemDataVal = doc->createTextNode(mlEventPtr->getComponentName()); But its giving me following error: Error 1 error C2664: 'xercesc_2_8::DOMDocument::createTextNode' : cannot convert parameter 1 from 'log4cxx::String' to 'const XMLCh *' c:\working\instrumentation\vc++_projects\mllog4cxx_working\mllog4cxx\sou rce\mllog4cxx\mlsoaloggerlayout.cpp 81 I assumed that function was returning type wchar_t* because, in log4cxx (opensource port of log4j by apache), the variable String is defined like this: typedef std::basic_string<TCHAR> String; And TCHAR is defined like this: typedef wchar_t TCHAR; So am I misinterpreting something here? Also, I checked my Visual Studio settings. The option Treat wchar_t as Built-in Type is set to Yes Looks like I am missing something fairly basic here. Really appreciate your feedback. -----Original Message----- From: Alberto Massari [mailto:[EMAIL PROTECTED] Sent: Friday, February 29, 2008 4:29 PM To: [email protected] Subject: Re: How to convert from wchar_t* to XMLCh*? If you are sure that mlEventPtr->getComponentName().c_str() returns a wchar_t*, you can directly use that pointer (on Windows, XMLCh* and wchar_t* points to UTF-16 data). If you don't want to use casts all over the place, you can also recompile Xerces with the 'treat wchar_t as a native type' and this will defined XMLCh to be a synonym for wchar_t. Alberto Kamdar, Devang (MLITS) wrote: > Hi, > When I am using the following function transcode > > XMLCh* xmlChComponentName = > XMLString::transcode(mlEventPtr->getComponentName().c_str()); > > Compiler is throwing following error: > Error 1 error C2440: 'initializing' : cannot convert from 'char > *' to 'XMLCh *' > c:\working\instrumentation\vc++_projects\mllog4cxx_working\mllog4cxx\sou > rce\mllog4cxx\mlsoaloggerlayout.cpp 78 > > mlEventPtr->getComponentName().c_str() returns string of type wchar_t* > > I am using Visual Studio 2005 to compile this. > > I need to do this transformation, because I need to pass this as a > parameter in DomDodumentPtr->createTextNode() function which accepts > only XMLCh* as a parameter. > > Can some one suggest, how to transcode a value of type wcaht_t* to > XMLCh* using the transcode function or by any other way? > > Thanks > Devang Kamdar > > >
