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


C++ DOMDocument::setEncoding方法代码示例

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


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

示例1: catch

// MÉTODO ContentRDF :: createAction
int
ContentRDF::
createAction(string act, string actor, vector<string> arguments, string &content)
{

  vector<string>::iterator it;
  int errorCode = 0;

  try
    {
      // Inicialización del sistema.
      XMLPlatformUtils::Initialize();
    }
  
  catch(const XMLException& toCatch)
    {
      char *pMsg = XMLString::transcode(toCatch.getMessage());
      XERCES_STD_QUALIFIER cerr << "Error al inicializar xerces-c.\n"
				<< "  Mensaje de excepción:"
				<< pMsg;
      XMLString::release(&pMsg);
      return 1;
    }// Fin catch

  DOMImplementation* impl =  DOMImplementationRegistry::getDOMImplementation(X("Core"));

  if (impl != NULL) {
    
    try
      {

	// *** rdf:RDF es la raíz del mensaje.
	DOMDocument *action = impl->createDocument(0, X("RDF"), 0);
	action->setEncoding(X("UTF-8"));

	// *** Comentario inicial.
	//action->createComment(X("<?xml version=\"1.0\" standalone=\"no\">"));
	//action->createComment(X("<!DOCTYPE fipa-message SYSTEM \"aclRep.dtd\">"));
	
	// *** Atributos de rdf:RDF.
	DOMElement* rootElem = action->getDocumentElement();
	rootElem->setAttribute(X("xmlnsrdf"), X("http://www.w3.org/1999/02/22-rdf-syntax.ns#"));
	rootElem->setAttribute(X("xmlnsfipa"), X("http://www.fipa.org/schemas/fipa-rdf0#"));
	
	DOMElement* actionElem = action->createElement(X("Action"));
	rootElem->appendChild(actionElem);
	actionElem->setAttribute(X("ID"), X((actor + "Action").c_str()));
	
	// *** Actor.
	DOMElement* actorElem = action->createElement(X("Actor"));
	actionElem->appendChild(actorElem);
	DOMText* actorText = action->createTextNode(X(actor.c_str()));
	actorElem->appendChild(actorText);

	// *** Act.
	DOMElement* actElem = action->createElement(X("Act"));
	actionElem->appendChild(actElem);
	DOMText* actText = action->createTextNode(X(act.c_str()));
	actElem->appendChild(actText);

	// *** Arguments.
	DOMElement* argumentsElem = action->createElement(X("Argument"));
	actionElem->appendChild(argumentsElem);
	DOMElement* bagElem = action->createElement(X("Bag"));
	argumentsElem->appendChild(bagElem);

	// Lista de argumentos.
	DOMElement* argumentElem;
	DOMText* argumentText;

	for (it = arguments.begin(); it != arguments.end(); it++) {
	  argumentElem = action->createElement(X("Li"));
	  bagElem->appendChild(argumentElem);
	  argumentText = action->createTextNode(X((*it).c_str()));
	  argumentElem->appendChild(argumentText);
	}// Fin for

	// Serialización a través de DOMWriter
	XMLCh tempStr[100];
	XMLString::transcode("LS", tempStr, 99);
	DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
	DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();

	// Conversión a string
	XMLCh *buf = theSerializer->writeToString(*action);
	char *salida = XMLString::transcode(buf);
	string s1(salida);
	content = s1;
	
	XMLString::release(&buf);
	XMLString::release(&salida);

	delete theSerializer;

	XMLPlatformUtils::Terminate();

      }// Fin try
    
    catch (const OutOfMemoryException&)
//.........这里部分代码省略.........
开发者ID:TheProjecter,项目名称:masyro06,代码行数:101,代码来源:ContentRDF.cpp


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