Once again, don't you just love it when they change the interface... Here's the cross version code to serialize the DOMNode: (sorry if the formatting doesn't look proper, web mail can do that)
bool serialize ( xercesc::DOMNode * node, xmlstream & str ) const { try { // get a serializer, an instance of DOMLSSerializer XMLCh tempStr[3] = {xercesc::chLatin_L, xercesc::chLatin_S, xercesc::chNull}; xercesc::DOMImplementation * impl = xercesc::DOMImplementationRegistry::getDOMImplementation(tempStr); #ifdef XERCESC_3 xercesc::DOMLSSerializer * theSerializer = ((xercesc::DOMImplementationLS*)impl)->createLSSerializer(); xercesc::DOMLSOutput * theOutputDesc = ((xercesc::DOMImplementationLS*)impl)->createLSOutput(); xercesc::DOMConfiguration* serializerConfig = theSerializer->getDomConfig(); // set features ... theOutputDesc->setByteStream(&str); // do the serialization through DOMLSSerializer::write(); theSerializer->write(node, theOutputDesc); theOutputDesc->release(); #else xercesc::DOMWriter * theSerializer = ((xercesc::DOMImplementationLS*)impl)->createDOMWriter(); xercesc::DOMWriter * serializerConfig = theSerializer; // set features ... theSerializer->writeNode(&str, *node); #endif theSerializer->release(); } catch (const xercesc::OutOfMemoryException& ex) { // handle exception and release memory... return false; } catch (xercesc::XMLException& ex) { // handle exception and release memory... return false; } return true; } Just in case anyone wonders what the xmlstream is all about: //-------------------------------------------------------------- /** Implements a generic XML output stream, that enables output to any type of STL output stream. @ingroup xml */ class xmlstream : public xercesc::XMLFormatTarget { std::ostream * mStr; public: // ----------------------------------------------------------------------- /** constructor */ xmlstream(std::ostream * str) : mStr (str) { } // ----------------------------------------------------------------------- /** destructor */ ~xmlstream() { } virtual void writeChars ( const XMLByte* const toWrite , const unsigned int count , xercesc::XMLFormatter* const formatter ) { mStr->write((char*)toWrite, (std::streamsize)count); mStr->flush(); } // ----------------------------------------------------------------------- /** Implementations of the format target interface */ virtual void writeChars( const XMLByte * const toWrite, const XMLSize_t count, xercesc::XMLFormatter * const formatter ) { mStr->write((char*)toWrite, (std::streamsize)count); mStr->flush(); // Surprisingly, Solaris was the only platform on which // required the char* cast to print out the string correctly. // Without the cast, it was printing the pointer value in hex. // Quite annoying, considering every other platform printed // the string with the explicit cast to char* below. //fwrite(toWrite, sizeof(XMLByte), (size_t)count, stdout); //fflush(stdout); } // ----------------------------------------------------------------------- /** Redirects the flush call to the underlying stream. */ virtual void flush() { mStr->flush(); } private: // ----------------------------------------------------------------------- /** no copy construtor allowed */ xmlstream(const xmlstream& str) : mStr(str.mStr) { } // ----------------------------------------------------------------------- /** no assignment operator allowed */ xmlstream& operator=(const xmlstream&) { return *this; } }; Cheers, Hans > Also, one more thing - DOMWriter seems to have been deprecated from xerces > 3.0. > I'm getting the following error : > * error C2039: 'DOMWriter' : is not a member of 'xercesc_3_0'* > Can anyone suggest how to resolve this or do I have to modify my code to > remove all dependency on DOMWriter ? (Although, It'll be very painful to > remove DOMWriter in my project)