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


C++ xmlSaveFormatFileEnc函数代码示例

本文整理汇总了C++中xmlSaveFormatFileEnc函数的典型用法代码示例。如果您正苦于以下问题:C++ xmlSaveFormatFileEnc函数的具体用法?C++ xmlSaveFormatFileEnc怎么用?C++ xmlSaveFormatFileEnc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: notepad_save_file

int notepad_save_file()
{
	int i;
	char file[256];
	xmlDocPtr doc = NULL;                      // document pointer
	xmlNodePtr root_node = NULL, node = NULL;  // node pointers

	safe_snprintf (file, sizeof (file), "%snotes.xml", configdir);

	doc = xmlNewDoc (BAD_CAST "1.0");
	root_node = xmlNewNode (NULL, BAD_CAST "PAD");
	xmlDocSetRootElement (doc, root_node);
	for (i = 0; i < nr_notes; i++)
	{
		xmlChar* data;
		char* subst_string = NULL;

		// libxml2 expects all data in UTF-8 encoding.
		xmlChar* name = toUTF8 (note_list[i].name, strlen (note_list[i].name));
		substitute_char_with_string (note_list[i].text.data, &subst_string, '&', "&amp;");		
		data = toUTF8 (subst_string, strlen(subst_string));

		node = xmlNewChild (root_node, NULL, BAD_CAST "NOTE", data);
		xmlNewProp (node, BAD_CAST "NAME", name);

		free (subst_string);
		free (data);
		free (name);
	}

	if (xmlSaveFormatFileEnc (file, doc, "UTF-8", 1) < 0)
	{
#ifndef WINDOWS
		// error writing. try the data directory
		safe_snprintf (file, sizeof (file), "%s/%s", datadir, "notes.xml");
		if (xmlSaveFormatFileEnc(file, doc, "UTF-8", 1) < 0)
		{
			LOG_ERROR_OLD(cant_save_notes, file);
		}
#else
		LOG_ERROR_OLD(cant_save_notes, file);
#endif
		return 0;
	}

	// Success!
	return 1;
}
开发者ID:xaphier,项目名称:Eternal-Lands,代码行数:48,代码来源:notepad.c

示例2: resetQuery

int resetQuery()
{
    int ret;
    xmlDocPtr doc;
    xmlNodePtr video_node, message_node;

    xmlKeepBlanksDefault(0);

    doc = xmlNewDoc(BAD_CAST "1.0");

    /* create pod node as root node */
    video_node = xmlNewNode(NULL, BAD_CAST "video");
    xmlDocSetRootElement(doc, video_node);

    message_node = xmlNewChild(video_node, NULL, BAD_CAST "message", BAD_CAST NULL);
    xmlNewChild(message_node, NULL, BAD_CAST "query", BAD_CAST NULL);

    // Save blank XML RESPONSE to File
    ret = xmlSaveFormatFileEnc(XML_QUERY, doc, "UTF-8", 1);

    // Dump to Console
    // xmlSaveFormatFileEnc("-", doc, "UTF-8", 1);

    xmlFreeDoc(doc);
    return ret;
}
开发者ID:jnbagale,项目名称:podvideoapp,代码行数:26,代码来源:video_responder.cpp

示例3: savestatus

inline void savestatus() {
	xmlNodePtr root = NULL;
	xmlNodePtr node = NULL;
	xmlChar* tmp = NULL;
	if ((strlen(statname) > 0) && (status != NULL)) {
		root = xmlDocGetRootElement(status);
		if (root) {
			xmlMutexLock(finishedMutex);
			for (node = root->children; node; node = node->next) {
				if (xmlStrcmp(node->name, "current") == 0) {
					xmlMutexLock(pwdMutex);
					tmp = xmlEncodeEntitiesReentrant(status, (const xmlChar*) &password);
					xmlMutexUnlock(pwdMutex);
					if (node->children) {
					    if (password[0] == '\0')
						xmlNodeSetContent(node->children, getfirstpassword());
					    else
						xmlNodeSetContent(node->children, tmp);
					    }
					xmlFree(tmp);
				} else if ((finished == 1) && (xmlStrcmp(node->name,"good_password") == 0)) {
					tmp =  xmlEncodeEntitiesReentrant(status, (const xmlChar*) &password_good);
					if (node->children)
						xmlNodeSetContent(node->children, tmp);
					xmlFree(tmp);
				}
			}
			xmlMutexUnlock(finishedMutex);
		}
		xmlSaveFormatFileEnc(statname, status, "UTF-8", 1);
	}
	return;
}
开发者ID:Rudloff,项目名称:rarcrack-debian,代码行数:33,代码来源:rarcrack.c

示例4: printf

void project_t::diff_save() const {
  if(unlikely(!osm))
    return;

  if(osm->is_clean(true)) {
    printf("data set is clean, removing diff if present\n");
    diff_remove_file();
    return;
  }

  const std::string &diff_name = diff_filename(this);

  printf("data set is dirty, generating diff\n");

  /* write the diff to a new file so the original one needs intact until
   * saving is completed */
  const std::string ndiff = path + "save.diff";

  xmlDocGuard doc(xmlNewDoc(BAD_CAST "1.0"));
  xmlNodePtr root_node = xmlNewNode(nullptr, BAD_CAST "diff");
  xmlNewProp(root_node, BAD_CAST "name", BAD_CAST name.c_str());
  xmlDocSetRootElement(doc.get(), root_node);

  std::for_each(osm->nodes.begin(), osm->nodes.end(), diff_save_objects<node_t>(root_node));
  std::for_each(osm->ways.begin(), osm->ways.end(), diff_save_ways(root_node, osm));
  std::for_each(osm->relations.begin(), osm->relations.end(), diff_save_objects<relation_t>(root_node));

  xmlSaveFormatFileEnc(ndiff.c_str(), doc.get(), "UTF-8", 1);

  /* if we reach this point writing the new file worked and we */
  /* can move it over the real file */
  if(renameat(-1, ndiff.c_str(), dirfd, diff_name.c_str()) != 0)
    fprintf(stderr, "error %i when moving '%s' to '%s'\n", errno, ndiff.c_str(), diff_name.c_str());
}
开发者ID:AMDmi3,项目名称:osm2go,代码行数:34,代码来源:diff.cpp

示例5: main

int main (int argc, char **argv)
{
  xmlDocPtr pdoc = NULL;
  xmlNodePtr proot_node = NULL,pnode = NULL,pnode1 = NULL;

  // 创建一个新文档并设置 root 节点
  // 一个 XML 文件只有一个 root 节点
  pdoc = xmlNewDoc (BAD_CAST "1.0");
  proot_node = xmlNewNode (NULL, BAD_CAST "根节点");
  xmlNewProp (proot_node, BAD_CAST "版本", BAD_CAST "1.0");
  xmlDocSetRootElement (pdoc, proot_node);

  pnode = xmlNewNode (NULL, BAD_CAST "子节点1");
  // 创建上面 pnode 的子节点
  xmlNewChild (pnode, NULL, BAD_CAST "子子节点1", BAD_CAST "信息");
  // 添加子节点到 root 节点
  xmlAddChild (proot_node, pnode);

  pnode1 = xmlNewNode (NULL, BAD_CAST "子子节点1");
  xmlAddChild (pnode, pnode1);
  xmlAddChild (pnode1,xmlNewText (BAD_CAST "这是更低的节点,子子子节点1"));

  // 还可以这样直接创建一个子节点到 root 节点上
  xmlNewTextChild (proot_node, NULL, BAD_CAST "子节点2", BAD_CAST "子节点2的内容");
  xmlNewTextChild (proot_node, NULL, BAD_CAST "子节点3", BAD_CAST "子节点3的内容");

  // 保存 xml 为文件,如果没有给出文件名参数,就输出到标准输出
  xmlSaveFormatFileEnc (argc > 1 ? argv[1]:"-", pdoc, "UTF-8", 1);

  // 释放资源
  xmlFreeDoc (pdoc);
  xmlCleanupParser ();
  xmlMemoryDump ();
  return 0;
}
开发者ID:wangkangluo1,项目名称:emacs-d,代码行数:35,代码来源:xml.c

示例6: xmlCopyNode

/**\brief Convert an XML node from the old saved-games.xml format to the new format.
 * \details
 *   The old saved-games.xml format put all of the Player information in one file.
 *   The new saved-games.xml format only stores some Player information, but
 *   nothing that relies on loading the Simulation.  Everything in the old
 *   style format is by itself in a standalone xml file named after the player.
 * \todo This could save a copy of the old saved-games.xml to a backup location.
 * \param[in] doc The XML document.
 * \param[in] xnode The XML Node.
 * \return A new XML node that represents the PlayerInfo for the Player.
 */
xmlNodePtr PlayerInfo::ConvertOldVersion( xmlDocPtr doc, xmlNodePtr node ) {
	char buff[256];
	xmlDocPtr xmlPtr;
	xmlNodePtr  attr;
	xmlNodePtr  copy = xmlCopyNode( node, 1);
	string filename = "Resources/Definitions/"+ name +".xml";

	LogMsg(INFO, "Converting %s to an xml file: %s ", name.c_str(), filename.c_str() );

	xmlPtr = xmlNewDoc( BAD_CAST "1.0" );
	xmlDocSetRootElement(xmlPtr, copy);

	// Version information
	snprintf(buff, sizeof(buff), "%d", EPIAR_VERSION_MAJOR);
	xmlNewChild(copy, NULL, BAD_CAST "version-major", BAD_CAST buff);
	snprintf(buff, sizeof(buff), "%d", EPIAR_VERSION_MINOR);
	xmlNewChild(copy, NULL, BAD_CAST "version-minor", BAD_CAST buff);
	snprintf(buff, sizeof(buff), "%d", EPIAR_VERSION_MICRO);
	xmlNewChild(copy, NULL, BAD_CAST "version-macro", BAD_CAST buff);

	xmlSaveFormatFileEnc( filename.c_str(), xmlPtr, "ISO-8859-1", 1);

	xmlNodePtr new_node = xmlNewNode(NULL, BAD_CAST "player");
	xmlNewChild(new_node, NULL, BAD_CAST "name", BAD_CAST GetName().c_str() );
	xmlNewChild(new_node, NULL, BAD_CAST "file", BAD_CAST filename.c_str() );

	if( (attr = FirstChildNamed(copy, "lastLoadTime")) ){
		xmlNewChild(new_node, NULL, BAD_CAST "lastLoadTime", BAD_CAST NodeToString(doc,attr).c_str() );
	}
	
	return new_node;
}
开发者ID:DuMuT6p,项目名称:Epiar,代码行数:43,代码来源:player.cpp

示例7: config_save

int config_save(xmlDocPtr pdoc, const char *filename)
{
	if (access(filename, F_OK) == 0)
		unlink(filename);

	return xmlSaveFormatFileEnc(filename, pdoc, "UTF-8", 1); 
}
开发者ID:hushi55,项目名称:uaflow,代码行数:7,代码来源:flow_config_xml.c

示例8: xmlNewDoc

void MapaParser::saveMap(const std::string& fileName,
    ReferenceCountPtr<Mapa>& mapa) {
    // Define el nodo raiz del documento XML sobre el cual se va a trabajar.
    xmlNodePtr nodoMapa;

    // Crea el documento XML sobre el cual se va a trabajar.
    this->document = xmlNewDoc(BAD_CAST "1.0");
    // Crea el nodo raiz del documento XML sobre el cual se va a trabajar.
    nodoMapa = xmlNewNode(NULL, BAD_CAST "mapa");
    // Establece el nodo raìz del documento XML sobre el cual se va a trabajar.
    xmlDocSetRootElement(this->document, nodoMapa);

    // Persiste los paises del mapa.
    persistirPaises(nodoMapa, mapa);
    // Persiste los continentes del mapa.
    persistirContinentes(nodoMapa, mapa);
    // Persiste las reglas del mapa.
    persistirReglas(nodoMapa, mapa);

    // Escribe el documento XML a disco.
    xmlSaveFormatFileEnc(fileName.c_str(), this->document, "UTF-8", 1);

    // Libera el documento XML sobre el cual se va a trabajar.
    xmlFreeDoc(this->document);

    // Libera las variables globales que el parser XML haya inicializado.
    xmlCleanupParser();
}
开发者ID:lautaroezequielrinaldi,项目名称:risk-3d,代码行数:28,代码来源:mapaparser.cpp

示例9: init_xml

static void init_xml (void)
{
    doc = xmlNewDoc ("1.0");
    root_node = xmlNewNode (NULL, "sensor_network_logger");
    xmlDocSetRootElement (doc, root_node);
    xmlSaveFormatFileEnc (current_file, doc, "UTF-8", 1);
}
开发者ID:135u5,项目名称:dynamiclinker,代码行数:7,代码来源:client-xml-log.c

示例10: irc_network_manager_file_save

static gboolean
irc_network_manager_file_save (EmpathyIrcNetworkManager *self)
{
  EmpathyIrcNetworkManagerPriv *priv = GET_PRIV (self);
  xmlDocPtr doc;
  xmlNodePtr root;

  if (priv->user_file == NULL)
    {
      DEBUG ("can't save: no user file defined");
      return FALSE;
    }

  DEBUG ("Saving IRC networks");

  doc = xmlNewDoc ("1.0");
  root = xmlNewNode (NULL, "networks");
  xmlDocSetRootElement (doc, root);

  g_hash_table_foreach (priv->networks, (GHFunc) write_network_to_xml, root);

  /* Make sure the XML is indented properly */
  xmlIndentTreeOutput = 1;

  xmlSaveFormatFileEnc (priv->user_file, doc, "utf-8", 1);
  xmlFreeDoc (doc);

  xmlCleanupParser ();
  xmlMemoryDump ();

  priv->have_to_save = FALSE;

  return TRUE;
}
开发者ID:Elleo,项目名称:empathy,代码行数:34,代码来源:empathy-irc-network-manager.c

示例11: saveJobToXML

int saveJobToXML(

  job *pjob,      /* I - pointer to job */
  const char *filename) /* I - filename to save to */

  {
  xmlDocPtr doc = NULL;       /* document pointer */
  xmlNodePtr root_node;
  int lenwritten = 0, rc = PBSE_NONE;
  root_node = NULL;
  char  log_buf[LOCAL_LOG_BUF_SIZE];
  if ((doc = xmlNewDoc((const xmlChar*) "1.0")))
    {
    root_node = xmlNewNode(NULL, (const xmlChar*) JOB_TAG);
    xmlDocSetRootElement(doc, root_node);
    add_fix_fields(&root_node, (const job*)pjob);
    add_union_fields(&root_node, (const job*)pjob);
    if (add_attributes(&root_node, pjob))
      return -1;

#ifdef PBS_MOM
    add_mom_fields(&root_node, (const job*)pjob);
#endif /* PBS_MOM */

#ifndef PBS_MOM
    lock_ss();
#endif /* !defined PBS_MOM */

    lenwritten = xmlSaveFormatFileEnc(filename, doc, NULL, 1);

#ifndef PBS_MOM
    unlock_ss();
#endif /* !defined PBS_MOM */

    xmlFreeDoc(doc);
    }
  else
    {
    snprintf(log_buf, sizeof(log_buf), "could not create a new xml document");
    log_event(
    PBSEVENT_JOB,
    PBS_EVENTCLASS_JOB,
    pjob->ji_qs.ji_jobid,
    log_buf);
    rc = -1;     
    }

  if (lenwritten <= 0)
    {
    snprintf(log_buf, sizeof(log_buf), "failed writing job to the xml file %s", filename);
    log_event(
      PBSEVENT_JOB,
      PBS_EVENTCLASS_JOB,
      pjob->ji_qs.ji_jobid,
      log_buf);
    rc = -1;
    }

  return rc;
  } /* saveJobToXML */
开发者ID:hocks,项目名称:torque,代码行数:60,代码来源:job_recov.c

示例12: diff_rename

bool diff_rename(project_t::ref oldproj, project_t *nproj)
{
  const std::string &diff_name = project_diff_name(oldproj.get());
  if(unlikely(diff_name.empty()))
    return false;

  fdguard difffd(oldproj->dirfd, diff_name.c_str(), O_RDONLY);

  /* parse the file and get the DOM */
  xmlDocGuard doc(xmlReadFd(difffd, nullptr, nullptr, XML_PARSE_NONET));
  if(unlikely(!doc)) {
    error_dlg(trstring("Error: could not parse file %1\n").arg(diff_name));
    return false;
  }

  for (xmlNode *cur_node = xmlDocGetRootElement(doc.get()); cur_node != nullptr;
       cur_node = cur_node->next) {
    if (cur_node->type == XML_ELEMENT_NODE) {
      if(likely(strcmp(reinterpret_cast<const char *>(cur_node->name), "diff") == 0)) {
        xmlSetProp(cur_node, BAD_CAST "name", BAD_CAST nproj->name.c_str());
        break;
      }
    }
  }

  xmlSaveFormatFileEnc((nproj->path + diff_filename(nproj)).c_str(), doc.get(), "UTF-8", 1);

  return true;
}
开发者ID:AMDmi3,项目名称:osm2go,代码行数:29,代码来源:diff.cpp

示例13: exportDatabase

int exportDatabase( const char * filename, struct database_t * databaseList, int * databaseListTotal, struct userAttr_t * userAttr ){
    int subscript;
    char longStr[100000];
    char message[500];
    xmlNodePtr node;
    xmlNodePtr content;
    xmlNodePtr sonNode;
    xmlNodePtr grandsonNode;

    // create the doc and root node
    xmlDocPtr doc = xmlNewDoc( BAD_CAST "1.0" );
    xmlNodePtr root_node = xmlNewNode( NULL, BAD_CAST "databaseList" );

    xitoa( longStr, *databaseListTotal);
    xmlNewProp( root_node, BAD_CAST "databaseListTotal", BAD_CAST longStr );

    if ( userAttr->userStatus == NULL )
        xmlNewProp( root_node, BAD_CAST "userStatus", BAD_CAST "disable" );
    else xmlNewProp( root_node, BAD_CAST "userStatus", BAD_CAST userAttr->userStatus );

    if ( userAttr->mobileNumber != NULL )
        xmlNewProp( root_node, BAD_CAST "userStatus", BAD_CAST userAttr->mobileNumber );

    // set the root node
    xmlDocSetRootElement( doc, root_node );

    // if ( *xmlItemListAlarmTotal > *xmlItemListTotal ) *xmlItemListAlarmTotal = *xmlItemListTotal;

    for (subscript=1; subscript <= *databaseListTotal; subscript++){
        node = xmlNewNode( NULL, BAD_CAST "item" );
        xmlAddChild( root_node, node );

        // xitoa( longStr, subscript );
        // xmlNewProp( node, BAD_CAST "subscript", BAD_CAST longStr );

        sonNode = xmlNewNode( NULL, BAD_CAST "url" );
        content = xmlNewCDataBlock( NULL, BAD_CAST databaseList[subscript].url, strlen(databaseList[subscript].url) );
        xmlAddChild( sonNode, content );
        xmlAddChild( node, sonNode );

        sonNode = xmlNewNode( NULL, BAD_CAST "urlstatus" );
        content = xmlNewCDataBlock( NULL, BAD_CAST databaseList[subscript].urlstatus, strlen(databaseList[subscript].urlstatus) );
        xmlAddChild( sonNode, content );
        xmlAddChild( node, sonNode );

        sonNode = xmlNewNode( NULL, BAD_CAST "filenamePrefix" );
        content = xmlNewCDataBlock( NULL, BAD_CAST databaseList[subscript].filenamePrefix, strlen(databaseList[subscript].filenamePrefix) );
        xmlAddChild( sonNode, content );
        xmlAddChild( node, sonNode );
    }

    int nRel = xmlSaveFormatFileEnc( filename, doc, "UTF-8", 1);
    /*if (nRel != -1)
        printf(" created, %d bytes.\n", nRel);*/

    xmlFreeDoc(doc);

    if (nRel != -1) return 1;
    else return 0;
}
开发者ID:glace,项目名称:RSSReminder,代码行数:60,代码来源:database.c

示例14: callback_ofc_capable_switch

/* !DO NOT ALTER FUNCTION SIGNATURE! */
int callback_ofc_capable_switch (void ** data, XMLDIFF_OP op, xmlNodePtr node, struct nc_err** error)
{
	nc_verb_verbose("%s: data=%p, op=%d\n", __PRETTY_FUNCTION__, data, op);

	xmlSaveFormatFileEnc("-", node->doc, "UTF-8", 1);

	return EXIT_SUCCESS;
}
开发者ID:bisdn,项目名称:of-config,代码行数:9,代码来源:of-config1.1.1.c

示例15: xmlFreeTextWriter

void XMLExporter::close()
{
	//xmlTextWriterEndElement(m_writer);
	xmlFreeTextWriter(m_writer);
	xmlSaveFormatFileEnc(m_file.c_str(), m_doc, MY_ENCODING, 1); 
	xmlCleanupParser();
	xmlMemoryDump();
}
开发者ID:skirk,项目名称:3rdYearMajor,代码行数:8,代码来源:Exporter.cpp


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