示例#1
0
文件: xml_utils.cpp 项目: 8l/insieme
string XmlUtil::convertDomToString() {
    if(!doc)
        throw "DOM is empty"; // FIXME add an exception type for this

    DOMImplementationLS* implLS = dynamic_cast<DOMImplementationLS*>(impl);
    DOMLSSerializer*	theSerializer = implLS->createLSSerializer();
    DOMConfiguration* 	serializerConfig = theSerializer->getDomConfig();

    if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
        serializerConfig->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);

    string stringTemp = XMLString::transcode (theSerializer->writeToString(doc));
    theSerializer->release();

    /*string stringDump;
    for (string::iterator it = stringTemp.begin() ; it < stringTemp.end(); ++it) {
    	if (!isspace (*it))
    		stringDump += *it;
    }
    return stringDump;*/
    return stringTemp;
}
示例#2
0
string tsp::Tool::xmlNode2String(const DOMNode* node) {
	if (!initXmlEngine())
		return NULL;

	DOMImplementation *implementation =
			DOMImplementationRegistry::getDOMImplementation(
					XMLString::transcode("LS"));

	// Create a DOMLSSerializer which is used to serialize a DOM tree into an XML document.
	DOMLSSerializer *serializer =
			((DOMImplementationLS*) implementation)->createLSSerializer();
	// Make the output more human readable by inserting line feeds.
	if (serializer->getDomConfig()->canSetParameter(
			XMLUni::fgDOMWRTFormatPrettyPrint, true))
		serializer->getDomConfig()->setParameter(
				XMLUni::fgDOMWRTFormatPrettyPrint, true);

	// The end-of-line sequence of characters to be used in the XML being written out.
	serializer->setNewLine(XMLString::transcode("\r\n"));

	return XMLString::transcode(serializer->writeToString(node));

}