Dave, Thanks for your quick response... you saved me a lot of time...
Steve -----Original Message----- From: David N Bertoni/Cambridge/IBM [mailto:[EMAIL PROTECTED]] Sent: Monday, January 13, 2003 12:15 PM To: [EMAIL PROTECTED] Subject: RE: XalanDOMString to std::string Hi Steve, You are likely mixing runtimes. Make sure your application is using the multithreaded DLL runtime (choose Debug or Release as appropriate) and make sure you're linking with the correct Xalan and Xerces .LIB files. For Debug configurations, use the .LIB files which have the letter "D" after the version number: XalanTransformer_1D.lib xerces-c_2D.lib For release configurations, use the ones without the "D": XalanTransformer_1.lib xerces-c_2.lib Dave "Oliver, Steve" <Steve.Oliver@bestw To: <[EMAIL PROTECTED]> estern.com> cc: (bcc: David N Bertoni/Cambridge/IBM) Subject: RE: XalanDOMString to std::string 01/13/2003 10:18 AM Please respond to xalan-dev Okay, so I'm using the transcode function as suggested but now my program fails with the following assertion... Expression: _CtrlsValidHeapPointer(pUserData) I get the same result with TranscodeToLocalCodePage as well. It appears that the string has been transcoded properly but when the program exits I get the assertion. Any ideas on what's happening... Steve -----Original Message----- From: David N Bertoni/Cambridge/IBM [mailto:[EMAIL PROTECTED]] Sent: Saturday, January 11, 2003 1:25 PM To: [EMAIL PROTECTED] Subject: Re: XalanDOMString to std::string Hi Holger, Close, but not quite! ;-) The Xerces DOM transcode member function returns a pointer to a memory buffer (char*), but XalanDOMString returns a copy of a std::vector which contains the transcoded characters. The reason for this is illustrated by the problem with your sample, if used with the Xerces DOM -- you've introduced a memory leak into your application. The proper way to do this is Xerces is to get a pointer to the result, then delete it after you've finished. Using the old, deprecated Xerces DOM: void foo( DOM_Node node, std::string& nodeName) { DOMString nodeName = node.getNodeName(); char* const temp = node.getNodeName().transcode(); nodeName = temp; delete [] temp; } The same applies to the Xerces function XMLString::transcode(). My approach in Xalan was different, because I don't like transfer of ownership that requires users to read documentation -- I've just seen way to many leaks introduced that way. So, in XalanDOMString::transcode(), you get back a std::vector which will manage the memory. You can get at a null-terminated const char* by doing any of the following: CharVectorType nodeName = node.getNodeName().transcode(); 1. &nodeName[0]; 2. &*nodeName.begin(); 3. c_str(nodeName); If you don't like the inefficiency of multiple copies of the data (because a std::vector is returned by value), you can use the TranscodeToLocalCodePage() function directly. Also, I've just added a new transcode() overload: void transcode(CharVectorType& theResult); Hope that helps... Dave Holger Floerke <floerke@doctron To: [EMAIL PROTECTED] ic.de> cc: (bcc: David N Bertoni/Cambridge/IBM) Subject: Re: XalanDOMString to std::string 01/10/2003 11:55 PM Please respond to xalan-dev Hi Steve, >I'm probably missing something very simple but I can't seem to get a >XalanDOMString converted to a std::string. I'm using Xalan C++ in a >Windows environment. My XML uses UTF-8 encoding. You have to use the member function "transcode" to transcode the string to the local codepage. It doesn't matter, which kind of encoding your XML has. Do you want to transcode the string to the local codepage, or you think of storing the UTF-8 characters in the std::string? I'm more familiar with the XercesDOM, but if you think of transcoding to the local codepage, try this code fragment (unverified): string oLocalString( &(oMyXalanDOMString.transcode()) ) Hope this works and helps, HolgeR -- holger floerke d o c t r o n i c email [EMAIL PROTECTED] information publishing + retrieval phone +49 2222 9292 90 http://www.doctronic.de
