|
CLAM-Development
1.3
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 #include "XercesDomWriter.hxx" 00023 #include "XercesEncodings.hxx" 00024 #include "XercesInitializer.hxx" 00025 00026 #include <xercesc/dom/DOMImplementation.hpp> 00027 #include <xercesc/dom/DOMImplementationLS.hpp> 00028 #include <xercesc/dom/DOMImplementationRegistry.hpp> 00029 #include <xercesc/dom/DOMLSSerializer.hpp> 00030 #include <xercesc/dom/DOMLSOutput.hpp> 00031 #include <xercesc/framework/MemBufFormatTarget.hpp> 00032 #include <string> 00033 #include <sstream> 00034 00035 namespace CLAM 00036 { 00037 void XercesDomWriter::write(std::ostream & target, xercesc::DOMNode * node) 00038 { 00039 XercesInitializer::require(); 00040 const XMLCh * propertyCanonical = xercesc::XMLUni::fgDOMWRTCanonicalForm; 00041 const XMLCh * propertyPrettyPrint = xercesc::XMLUni::fgDOMWRTFormatPrettyPrint; 00042 xercesc::DOMImplementationLS *impl = 00043 (xercesc::DOMImplementationLS*) 00044 xercesc::DOMImplementationRegistry::getDOMImplementation(U("LS")); 00045 xercesc::DOMLSSerializer *serializer = impl->createLSSerializer(); 00046 xercesc::DOMLSOutput *output = impl->createLSOutput(); 00047 00048 output->setEncoding(U("UTF-8")); 00049 00050 xercesc::DOMConfiguration* serializerConfig = serializer->getDomConfig(); 00051 00052 if (serializerConfig->canSetParameter(propertyPrettyPrint, mShouldIndent)) 00053 serializerConfig->setParameter(propertyPrettyPrint, mShouldIndent); 00054 if (serializerConfig->canSetParameter(propertyCanonical, mShouldCanonicalize)) 00055 serializerConfig->setParameter(propertyCanonical, mShouldCanonicalize); 00056 00057 xercesc::MemBufFormatTarget formatTarget; 00058 output->setByteStream(&formatTarget); 00059 serializer->write(node, output); 00060 00061 const char * buffer = (char *) formatTarget.getRawBuffer(); 00062 const unsigned bufferLen = formatTarget.getLen(); 00063 target << std::string(buffer,bufferLen); 00064 serializer->release(); 00065 output->release(); 00066 } 00067 00068 } 00069
1.7.6.1