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


C++ DOMImplementation::createDOMWriter方法代码示例

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


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

示例1: main

int main()
{
   XMLPlatformUtils::Initialize();

   // Populate vector of items
   vector<Item> items;
   items.push_back(Item(Product("Toaster", 29.95), 3));
   items.push_back(Item(Product("Hair dryer", 24.95), 1));

   // Build the DOM document
   DOMImplementation* implementation
      = DOMImplementation::getImplementation();
   DOMDocument* doc = implementation->createDocument();
   doc->setStandalone(true);

   DOMElement* root = create_item_list(doc, items);
   doc->appendChild(root);

   // Print the DOM document

   DOMWriter* writer = implementation->createDOMWriter();
   writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
   XMLFormatTarget* out = new StdOutFormatTarget();
   writer->writeNode(out, *doc);

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

   return 0;
}
开发者ID:jervisfm,项目名称:ExampleCode,代码行数:30,代码来源:builder.cpp

示例2: writeXMLFile

    //-----------------------------------------------------------------------
    void XercesWriter::writeXMLFile(const XMLNode* root, const Ogre::String& filename)
    {
        XERCES_CPP_NAMESPACE_USE;

        DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(L"Core");
        DOMDocumentType* docType = NULL;
        DOMDocument* doc = impl->createDocument(NULL, transcode(root->getName()).c_str(), docType);

        populateDOMElement(root, doc->getDocumentElement());

        LocalFileFormatTarget destination(filename.c_str());
        DOMWriter* writer = impl->createDOMWriter();
        writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
        writer->writeNode(&destination, *doc);
        writer->release();
        doc->release();
    }
开发者ID:dodong471520,项目名称:pap,代码行数:18,代码来源:FairyXercesWriter.cpp

示例3: buildParameterSetXML


//.........这里部分代码省略.........
			rootElem->appendChild(psetdefElem);

			string xmlFileName = xmlFileNamePrefix + ".xml";
			DOMText* psetdefValTextNode = doc->createTextNode(StrX(xmlFileName.c_str()).unicodeForm());
			psetdefElem->appendChild(psetdefValTextNode);
			DOMElement*  nameElem = doc->createElement(StrX(NAME_STRING).unicodeForm());
			rootElem->appendChild(nameElem);
			DOMText* nameValTextNode = doc->createTextNode(StrX("command-line values").unicodeForm());
			nameElem->appendChild(nameValTextNode);

			map<string, vector<string> >::iterator position;
			// for each parameter in the parameterMap
			for(position = parameterMap.begin(); position != parameterMap.end(); ++position) {
				// determine the type by looking it up in our parameter set definition, i.e. psetdef 
				// (which we have obtained by parsing the task's psetdef xml file containing the task's metadata)
				// and add an element of the proper type to the XML document being constructed, with name equal to the
				// key portion of the current map entry, value equal to the value portion of the current map entry.
				ParamSetDef::paramTypesEnum paramType = paramSetDef->getParamTypeForName(position->first);
				switch(paramType) {
					case ParamSetDef::BOOL: {
						DOMElement *boolElem = createBoolElement(position->first, position->second, doc);
						rootElem->appendChild(boolElem);
						break;
					}
					case ParamSetDef::INT: {
						DOMElement *intElem = createIntElement(position->first, position->second, doc);
						rootElem->appendChild(intElem);
						break;
					}
					case ParamSetDef::INT_ARRAY: {
						DOMElement *intArrayElem = createIntArrayElement(position->first, position->second, doc);
						rootElem->appendChild(intArrayElem);
						break;
					}
					case ParamSetDef::DOUBLE: {
						DOMElement *doubleElem = createDoubleElement(position->first, position->second, doc);
						rootElem->appendChild(doubleElem);
						break;
					}
					case ParamSetDef::DOUBLE_ARRAY: {
						DOMElement * doubleArrayElem = 
							createDoubleArrayElement(position->first, position->second, doc);
						rootElem->appendChild(doubleArrayElem);
						break;
					}
					case ParamSetDef::STRING: {
						DOMElement *stringElem = createStringElement(position->first, position->second, doc);
						rootElem->appendChild(stringElem);
						break;
					}
					case ParamSetDef::STRING_ARRAY: {
						DOMElement * stringArrayElem = createStringArrayElement(position->first, position->second, doc);
						rootElem->appendChild(stringArrayElem);
						break;
					}
				}
			}

			// construct the DOM writer
			DOMWriter *domWriter = impl->createDOMWriter();
			if (domWriter->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true)) {
				domWriter->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
			}

			// construct the MemBufFormatTarget
			XMLFormatTarget *myFormatTarget = new MemBufFormatTarget();

			// set the encoding to be ISO-8859-1
			XMLCh tempStr[100];
			XMLString::transcode("ISO-8859-1", tempStr, 99);
			domWriter->setEncoding(tempStr);

			// serialize the document to an internal memory buffer
			domWriter->writeNode(myFormatTarget, *doc);

			// get the string which is encoded in ISO-8859-1 from the MemBufFormatTarget
			char* theXMLString_Encoded = (char*) 
  					((MemBufFormatTarget*)myFormatTarget)->getRawBuffer();

			retVal = string(StrX(theXMLString_Encoded).localForm());

			// release the memory
			delete myFormatTarget;
			delete domWriter;

			//doc->release();
		}
		catch (const OutOfMemoryException& e)
		{
			ACS_LOG(LM_ERROR, "parameterTask::buildParameterSetXML", 
				(LM_ERROR, "Error - OutOfMemoryException - info: %s\n", StrX(e.getMessage()).localForm()))
		}
		catch (const DOMException& e)
		{
			ACS_LOG(LM_ERROR, "parameterTask::buildParameterSetXML", 
				(LM_ERROR, "Error - DOMException - info: %s\n", StrX(e.getMessage()).localForm()))
		}
	}
	else
	{
开发者ID:ACS-Community,项目名称:ACS,代码行数:101,代码来源:parameterTask.cpp


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