当前位置: 首页>>代码示例>>C++>>正文


C++ DOMLSSerializer::release方法代码示例

本文整理汇总了C++中DOMLSSerializer::release方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMLSSerializer::release方法的具体用法?C++ DOMLSSerializer::release怎么用?C++ DOMLSSerializer::release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DOMLSSerializer的用法示例。


在下文中一共展示了DOMLSSerializer::release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: serialize

void serializer::serialize(EObject_ptr obj)
{
    m_root_obj = obj;

    m_impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));

    if (m_impl)
    {
        EClass_ptr cl = obj->eClass();
        EPackage_ptr pkg = cl->getEPackage();

        ::ecorecpp::mapping::type_traits::string_t const& ns_uri = pkg->getNsURI();

        m_doc = m_impl->createDocument(
                (ns_uri.empty()) ? X("NULL") : W(ns_uri), // root element namespace URI.
                W(get_type(obj)), // root element name
                0); // document type object (DTD)

        m_root = m_doc->getDocumentElement();

        // common attributes
        // xmlns:xmi="http://www.omg.org/XMI"
        m_root->setAttribute(X("xmlns:xmi"), X("http://www.omg.org/XMI"));
        // xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        m_root->setAttribute(X("xmlns:xsi"),
                X("http://www.w3.org/2001/XMLSchema-instance"));
        // xmi:version="2.0"
        m_root->setAttribute(X("xmi:version"), X("2.0"));

        serialize_node(m_root, obj);

        // write
        // TODO: outta here

        DOMLSSerializer *theSerializer =
                ((DOMImplementationLS*) m_impl)->createLSSerializer();
        DOMLSOutput *theOutputDesc =
                ((DOMImplementationLS*) m_impl)->createLSOutput();

        DOMConfiguration* serializerConfig = theSerializer->getDomConfig();

        // TODO: set as option
        if (serializerConfig->canSetParameter(
                XMLUni::fgDOMWRTFormatPrettyPrint, true))
            serializerConfig->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
                    true);

        XMLFormatTarget *myFormTarget;
        myFormTarget = new LocalFileFormatTarget(X(m_file));
        theOutputDesc->setByteStream(myFormTarget);

        theSerializer->write(m_doc, theOutputDesc);

        theOutputDesc->release();
        theSerializer->release();
        delete myFormTarget;
    }
    else
        throw "Error";
}
开发者ID:Ecapo,项目名称:vishnu,代码行数:60,代码来源:serializer-xerces.cpp

示例2: Write

/* Write the file. */
bool GQCFileData::Write(const std::string &fileName)
{    
	// Initialize the XML4C2 system.
	try
	{
		XMLPlatformUtils::Initialize();
	}
	catch (const XMLException&)
	{
		return false;
	}

	// Create a DOM implementation object and create the document type for it.
	DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(ToXMLCh(L"LS"));
	DOMDocument* doc = impl->createDocument();
	//doc->setStandalone(true);

	// Create the serializer.
	DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
	DOMLSOutput     *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
	//theSerializer->setEncoding(ToXMLCh(GENERIC_REPORT_FILE_ENCODING));
	theOutputDesc->setEncoding(ToXMLCh(GENERIC_REPORT_FILE_ENCODING));

    // Create the root element
    DOMElement *rootElement = CreateGenericReportElement(doc);

	// store the parameters
	AddNameValuePairs(ANALYSIS_PARAMETERS, analysisParameters, doc, rootElement);
	AddNameValuePairs(QC_RESULTS, qcResults, doc, rootElement);
	AddNameValuePairs(SAMPLE_SIGNATURE, sampleSignature, doc, rootElement);

    // Add an empty table (required by the DTD)
    AddBlankReportTable(doc, rootElement);

    // Store the element to the document.
    doc->appendChild(rootElement);

	// Write the file.
	bool status = false;
	XMLFormatTarget *myFormTarget = new LocalFileFormatTarget(fileName.c_str());
	theOutputDesc->setByteStream(myFormTarget);
	try
	{
		theSerializer->write(doc, theOutputDesc);
		status = true;
	}
	catch (...)
	{
		status = false;
	}

	// Clean up
	doc->release();
	theOutputDesc->release();
	theSerializer->release();
	delete myFormTarget;
	XMLPlatformUtils::Terminate();

	return status;
}
开发者ID:HenrikBengtsson,项目名称:Affx-Fusion-SDK,代码行数:61,代码来源:GQCFileData.cpp

示例3: SerializeXercesDocument

void SerializeXercesDocument(xercesc::DOMDocument& document, xercesc::XMLFormatTarget& target) {

	// call into xerces for serialization
	// cf. http://xerces.apache.org/xerces-c/program-dom-3.html#DOMLSSerializer

	static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
	DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);

	// construct the DOMWriter
	DOMLSSerializer *writer = ((DOMImplementationLS*)impl)->createLSSerializer();

    // optionally you can set some features on this serializer
    if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true))
        writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true);

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

	// prepare output
	DOMLSOutput *outp = ((DOMImplementationLS*)impl)->createLSOutput();
	outp->setByteStream(&target);

	// serialize the DOMNode to a UTF-16 string
	writer->write(&document, outp);

	// release the memory
	outp->release();
	writer->release();

}
开发者ID:Limecraft,项目名称:ebu-mxfsdk,代码行数:30,代码来源:XercesUtils.cpp

示例4: domPrint

//
// domPrint  -  Dump the contents of a DOM node.
//              For debugging failures, when all else fails.
//                 Works recursively - initially called with a document node.
//
void ThreadParser::domPrint()
{
    printf("Begin DOMPrint ...\n");
    if (gRunInfo.dom)
    {
        try
        {
            XMLCh tempStr[100];
            XMLString::transcode("LS", tempStr, 99);
            DOMImplementation *impl          = DOMImplementationRegistry::getDOMImplementation(tempStr);
            DOMLSSerializer   *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
            DOMLSOutput       *theOutput     = ((DOMImplementationLS*)impl)->createLSOutput();
            XMLFormatTarget   *myFormTarget  = new StdOutFormatTarget();
            theOutput->setByteStream(myFormTarget);
            DOMNode           *doc           = fXercesDOMParser->getDocument();
            theSerializer->write(doc,theOutput);
            delete myFormTarget;
            theSerializer->release();
            theOutput->release();
        }
        catch (...)
        {
            // do nothing
        }
    }
    printf("End DOMPrint\n");
}
开发者ID:ideasiii,项目名称:ControllerPlatform,代码行数:32,代码来源:ThreadTest.cpp

示例5: dumpTree

 /// Dump DOM tree using XercesC handles
 void dumpTree(DOMNode* doc, ostream& os) {
   if ( doc )  {
     DOMImplementation  *imp = DOMImplementationRegistry::getDOMImplementation(Strng_t("LS"));
     MemBufFormatTarget *tar = new MemBufFormatTarget();
     DOMLSOutput        *out = imp->createLSOutput();
     DOMLSSerializer    *wrt = imp->createLSSerializer();
     out->setByteStream(tar);
     wrt->getDomConfig()->setParameter(Strng_t("format-pretty-print"), true);
     wrt->write(doc, out);
     os << tar->getRawBuffer() << endl << flush;
     out->release();
     wrt->release();
     return;
   }
   printout(ERROR,"dumpTree","+++ Cannot dump invalid document.");
 }
开发者ID:vvolkl,项目名称:DD4hep,代码行数:17,代码来源:DocumentHandler.cpp

示例6: serializeNode

void Normalizer::serializeNode(const DOMNode * const node) {
    XMLCh tempStr[100];
    XMLString::transcode("LS", tempStr, 99);
    DOMImplementation *impl          = DOMImplementationRegistry::getDOMImplementation(tempStr);
    DOMLSSerializer   *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
    DOMLSOutput       *theOutput     = ((DOMImplementationLS*)impl)->createLSOutput();
    theSerializer->getDomConfig()->setParameter(X("format-pretty-print"), true);
    XMLFormatTarget *myFormTarget;
    myFormTarget = new StdOutFormatTarget();

    theOutput->setByteStream(myFormTarget);
    theSerializer->write(node,theOutput);
    delete myFormTarget;
    theSerializer->release();
    theOutput->release();
}
开发者ID:kanbang,项目名称:Colt,代码行数:16,代码来源:Normalizer.cpp

示例7: LocalFileFormatTarget

Triggerconf::~Triggerconf ()
{
	if( savechanges ){
	
		//
		// save file
		//
	
		static const XMLCh	gLS []	= {chLatin_L, chLatin_S, chNull};
		DOMImplementation*	impl	= DOMImplementationRegistry::getDOMImplementation(gLS);
		DOMLSSerializer*	writer	= ((DOMImplementationLS*)impl)->createLSSerializer();
	
		if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
			writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
	
		if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTBOM, true))
			writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTBOM, true);
	
		XMLFormatTarget* target	= new LocalFileFormatTarget (file.c_str ());
		target->flush();
	
		DOMLSOutput* output = ((DOMImplementationLS*)impl)->createLSOutput();
		output->setByteStream( target );
		writer->write( rootnode , output );
		
		writer->release();
		delete target;
		delete output;

	} // if( savechanges )

	//
	// delete all stuff here
	//

	delete parser;
	delete errhandler;

	//
	// now we can safely terminate xerces
	//

	XMLPlatformUtils::Terminate();
}
开发者ID:freshbob,项目名称:worms-attack,代码行数:44,代码来源:triggerconf.cpp

示例8: commit

int XmlParser::commit(const char* xmlFile) {
   try {
      // Obtain DOM implementation supporting Load/Save
      DOMImplementationLS* pImplementation = dynamic_cast<DOMImplementationLS *>(DOMImplementationRegistry::getDOMImplementation(DualString("LS").asXMLString()));
      if (pImplementation == NULL){
         throw( std::runtime_error( "Unable to obtain suitable DOMImplementation!" ) ) ;
      }

      DOMLSSerializer *pSerializer = pImplementation->createLSSerializer();

      DOMLSOutput *pOutput = pImplementation->createLSOutput();
#if 1
      // Change output format to be pretty (but it isn't)
      DOMConfiguration *pConfiguration = pSerializer->getDomConfig();
      if (pConfiguration->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
         pConfiguration->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
#if 0
      // Overrides above but seems to have little effect!
      if (pConfiguration->canSetParameter(XMLUni::fgDOMWRTCanonicalForm, true))
         pConfiguration->setParameter(XMLUni::fgDOMWRTCanonicalForm, true);
#endif
#if 1
      //
      if (pConfiguration->canSetParameter(XMLUni::fgDOMWRTEntities, true))
         pConfiguration->setParameter(XMLUni::fgDOMWRTEntities, true);
#endif
#endif
      LocalFileFormatTarget *pTarget = new LocalFileFormatTarget(DualString( xmlFile ).asXMLString());
      pOutput->setByteStream(pTarget);

//      mergeDocument->normalizeDocument(); // Needed?
      pSerializer->write(mergeDocument, pOutput);

      delete pTarget;
      pOutput->release();
      pSerializer->release();

   } catch( const xercesc::XMLException& e ){
      return -1;
   }

   return 0;
}
开发者ID:CoffeeHacker,项目名称:usbdm-eclipse-makefiles-build,代码行数:43,代码来源:xmlParser.cpp

示例9: PrintXMLdoc

void PrintXMLdoc(const XERCES_CPP_NAMESPACE::DOMDocument* doc)
{
	DOMImplementation* impl =  DOMImplementationRegistry::getDOMImplementation(L"Core");
	DOMLSSerializer   *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
    DOMLSOutput       *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
	
	DOMConfiguration* serializerConfig=theSerializer->getDomConfig();
	if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
		serializerConfig->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);

	XMLFormatTarget *outputStream = new StdOutFormatTarget();
	theOutputDesc->setByteStream(outputStream);

	theSerializer->write(doc, theOutputDesc);

    theOutputDesc->release();
    theSerializer->release();

	delete outputStream;
}
开发者ID:Letractively,项目名称:koritools,代码行数:20,代码来源:filetree2xml.cpp

示例10: convertDomToString

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;
}
开发者ID:8l,项目名称:insieme,代码行数:22,代码来源:xml_utils.cpp

示例11: write_document

void Deployment_Plan_Visitor::write_document (const std::string & basename)
{
  std::ostringstream filename;
  filename << this->config_.output_ << "\\" << basename << ".cdp";

  using namespace xercesc;

  // Write the XML document to a file.
  DOMLSSerializer * serializer = this->document_->impl ()->createLSSerializer ();

  if (serializer->getDomConfig ()->canSetParameter (XMLUni::fgDOMWRTDiscardDefaultContent, true))
    serializer->getDomConfig ()->setParameter (XMLUni::fgDOMWRTDiscardDefaultContent, true);

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

  if (serializer->getDomConfig ()->canSetParameter (XMLUni::fgDOMWRTBOM, false))
    serializer->getDomConfig ()->setParameter (XMLUni::fgDOMWRTBOM, false);

  serializer->writeToURI (this->document_->root (), GAME::Xml::String (filename.str ()));
  serializer->release ();
}
开发者ID:DOCGroup,项目名称:CoSMIC,代码行数:22,代码来源:Deployment_Plan_Visitor.cpp

示例12: save

//save the document to an external file
void ResultXML::save()
{
    //create the serializer for saving the document
    DOMLSSerializer *serializer = (DOMLSSerializer*)imp->createLSSerializer();

    //configure for saving it in a well presented human readable format
    if(serializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true)){
       serializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
    }

    //set the output for serializing as a stream
    DOMLSOutput *output = ((DOMImplementationLS*)imp)->createLSOutput();
    output->setByteStream(ftarget);

    //use the serializer to save the document and catch any errors encountered
    try{
        serializer->write(root, output);
    }
    catch (const XMLException& e) {
        char* msg = XMLString::transcode(e.getMessage());
        cout << "Error Exception Encountered: " << endl << msg << endl;
        XMLString::release(&msg);
    }
    catch (const DOMException& e) {
        char* msg = XMLString::transcode(e.getMessage());
        cout << "Error Exception Encountered: " << endl << msg << endl;
        XMLString::release(&msg);
    }
    catch (...) {
        cout << "Error Unknown Exception" << endl;
    }

    //force the release of resources held by the serializer and output manager
    output->release();
    serializer->release();
}
开发者ID:iq-dot,项目名称:performer,代码行数:37,代码来源:resultxml.cpp

示例13: OutputXML

void OutputXML(xercesc::DOMDocument* pmyDOMDocument, std::string filePath) 
{ 
	//Return the first registered implementation that has the desired features. In this case, we are after a DOM implementation that has the LS feature... or Load/Save. 
	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"));  

	// Convert the path into Xerces compatible XMLCh*. 
	XMLCh *tempFilePath = XMLString::transcode(filePath.c_str()); 

	// Specify the target for the XML output. 
	XMLFormatTarget *formatTarget = new LocalFileFormatTarget(tempFilePath); 

	// Create a new empty output destination object. 
	DOMLSOutput *output = ((DOMImplementationLS*)implementation)->createLSOutput(); 

	// Set the stream to our target. 
	output->setByteStream(formatTarget); 

	// Write the serialized output to the destination. 
	serializer->write(pmyDOMDocument, output); 

	// Cleanup. 
	serializer->release(); 
	XMLString::release(&tempFilePath); 
	delete formatTarget; 
	output->release(); 
} 
开发者ID:usnistgov,项目名称:QIF,代码行数:36,代码来源:XercesUtils.cpp

示例14: saveConfig


//.........这里部分代码省略.........
	    delemDataClient->appendChild(delemParameter);
	    DOMText *dtxtParamValue = ddocConfig->createTextNode(XMLString::transcode(strParamValue.c_str()));
	    delemParameter->appendChild(dtxtParamValue);
	}

 	DOMElement *delemSVD;
	delemSVD = ddocConfig->createElement(XMLString::transcode(ConfigTagLibrary::StateVariableDisplayTag()));
	delemDataClient->appendChild(delemSVD);

	list<ClsStateVariableDisplayConfig>lstSVDConfigs =  (*itConfigs).getListStateVariableDisplayConfig();
	list<ClsStateVariableDisplayConfig>::iterator itSVD;
	for(itSVD = lstSVDConfigs.begin(); itSVD != lstSVDConfigs.end(); itSVD++){
	    DOMElement *delemStateVariable;
	    delemStateVariable = ddocConfig->createElement(XMLString::transcode(ConfigTagLibrary::StateVariableDisplaysTag()));
	    delemSVD->appendChild(delemStateVariable);
	    delemStateVariable->setAttribute(XMLString::transcode(ConfigTagLibrary::IDTag()), 
					     XMLString::transcode((*itSVD).getID().c_str()));
	    
/*
	    delemStateVariable->setAttribute(XMLString::transcode(ConfigTagLibrary::TypeTag()), 
					     XMLString::transcode((*itSVD).getItemType().c_str()));
*/
	
	    delemStateVariable->setAttribute(XMLString::transcode(ConfigTagLibrary::ItemIDTag()), 
					     XMLString::transcode((*itSVD).getItemID().c_str()));

	    delemStateVariable->setAttribute(XMLString::transcode(ConfigTagLibrary::SelectedIndicesTag()), 
					     XMLString::transcode((*itSVD).getSelectedIndices().c_str()));

	    list<pair<string, string> > lstParametersSVD = (*itSVD).getListParameters();
	    list<pair<string, string> >::iterator itLstParametersSVD;
	    for(itLstParametersSVD = lstParametersSVD.begin(); itLstParametersSVD != lstParametersSVD.end(); itLstParametersSVD++){
		string strParamName = (*itLstParametersSVD).first;
		string strParamValue = (*itLstParametersSVD).second;
		DOMElement *delemParameter;
		delemParameter = ddocConfig->createElement(XMLString::transcode(strParamName.c_str()));
		delemStateVariable->appendChild(delemParameter);
		DOMText *dtxtParamValue = ddocConfig->createTextNode(XMLString::transcode(strParamValue.c_str()));
		delemParameter->appendChild(dtxtParamValue);
	    }
	}
    }


#if XERCES_VERSION_MAJOR >= 3
    DOMLSSerializer* theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
    if (theSerializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true))
	theSerializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true);

    if (theSerializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
	theSerializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
#else
    DOMWriter* theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
    if (theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true))
	theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true);

    if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
	theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
#endif

    XMLFormatTarget *myFormTarget = new LocalFileFormatTarget(strFileName.c_str());

#if XERCES_VERSION_MAJOR >= 3
    DOMLSOutput* theOutput = ((DOMImplementationLS*)impl)->createLSOutput();
    theOutput->setByteStream(myFormTarget);
#endif


    try {
#if XERCES_VERSION_MAJOR >= 3
	theSerializer->write(delemConfig, theOutput);
#else
	theSerializer->writeNode(myFormTarget, *delemConfig);
#endif
    }
    catch (const XMLException& toCatch) {
	char* message = XMLString::transcode(toCatch.getMessage());
	cerr << "Exception message is: \n"
	     << message << "\n";
	XMLString::release(&message);
    }
    catch (const DOMException& toCatch) {
	char* message = XMLString::transcode(toCatch.msg);
	cerr << "Exception message is: \n"
	     << message << "\n";
	XMLString::release(&message);
    }
    catch (...) {
	cerr << "Unexpected Exception \n" ;
    }

//    cout << myFormTarget->getRawBuffer() << endl;

    theSerializer->release();
    delete myFormTarget;


    return true;

}
开发者ID:jeez,项目名称:iqr,代码行数:101,代码来源:ClsDataClientConfigWriter.cpp

示例15: file

Triggerconf::Triggerconf(string _filename, bool _autocreateitems, bool _mustexist, bool _savechanges)
	: file( _filename ), autocreate( _autocreateitems ), savechanges( _savechanges ) {

	rootnode	= NULL;
	goodstate	= true;
	lasterror	= "";
    
	try {

		XMLPlatformUtils::Initialize();

		//
		// if the file does not exists we create it with the root node
		// but only if the constructor parameter is fine with this
		//

		FileHandle filehandle = XMLPlatformUtils::openFile (file.c_str ());
		
		if (filehandle == NULL && _mustexist == false) {

			static const XMLCh	gLS []	= {chLatin_L, chLatin_S, chNull};
			DOMImplementation*	impl	= DOMImplementationRegistry::getDOMImplementation(gLS);
			
			XMLCh*			xroot	= XMLString::transcode( ROOT_NAME );
			DOMDocument*		doc	= impl->createDocument( 0, xroot, 0 );
			DOMElement*		elemrt	= doc->getDocumentElement();
			DOMLSSerializer* 	writer  = ((DOMImplementationLS*)impl)->createLSSerializer();
			
			XMLString::release (&xroot);

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

			if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTBOM, true))
				writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTBOM, true);

			XMLFormatTarget* target	= new LocalFileFormatTarget (file.c_str ());
			target->flush();

			DOMLSOutput* output = ((DOMImplementationLS*)impl)->createLSOutput();
        		output->setByteStream( target );
            		writer->write( elemrt, output );

			writer->release();
			doc->release();

			delete output;
			delete target;

		} else if (filehandle == NULL && _mustexist == true) {

			setError ("file " + file + " does not exist");
			return;

		} else {

			XMLPlatformUtils::closeFile (filehandle);

		}

		//
		// parse the file
		//

		parser		= new XercesDOMParser ();
		errhandler	= (ErrorHandler*) new HandlerBase ();

		parser->setErrorHandler	(errhandler);
		parser->parse		(file.c_str ());
		rootnode		= getChildOfType (parser->getDocument (), DOMNode::ELEMENT_NODE);

		if (rootnode != NULL) {
		
			char* xmlstring = XMLString::transcode (rootnode->getNodeName ());

			if (((string) ROOT_NAME).compare (xmlstring) == 0)
				resetError();
			else
				setError("invalid root item in file " + file);
		
			XMLString::release (&xmlstring);

		} else
			setError("parsing xml file " + file + " failed");	

	} catch (const XMLException& toCatch) {
		char* message = XMLString::transcode (toCatch.getMessage());
		setError ("failed parsing file " + file + ": " + message);
		XMLString::release(&message);
	}
	catch (const DOMException& toCatch) {
		char* message = XMLString::transcode (toCatch.msg);
		setError ("failed parsing file " + file + ": " + message);
		XMLString::release(&message);
	}
	catch (...) {
		setError( "failed parsing file " + file );
	}

}
开发者ID:freshbob,项目名称:worms-attack,代码行数:100,代码来源:triggerconf.cpp


注:本文中的DOMLSSerializer::release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。