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


C++ TiXmlElement::InsertBeforeChild方法代码示例

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


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

示例1: OnUpdateDataFinish

void CMNewContentListener::OnUpdateDataFinish(void* UserData, int Result)
{
	if(CMGetNewContent::GetInstance()->GetItemCount() > 0)
	{

		CMString sFilePath = CMPath(CMPath::APP_PATH).String() + L"newcontent.xml";
		//创建一个XML的文档对象。
		TiXmlDocument *pContentDoc = new TiXmlDocument(sFilePath);
		TiXmlElement* pRootElement = NULL;
		if(pContentDoc)
		{
			pContentDoc->Parse("<?xml version=\"1.0\" encoding=\"utf-8\" ?><content/>",NULL,TIXML_ENCODING_UTF8);
			if(pContentDoc->Error())
				return;
			pRootElement = pContentDoc->RootElement();
		}
		if(pRootElement)
		{
			TBrowserItem item;
			for(int i=0; i<CMGetNewContent::GetInstance()->GetItemCount(); i++)
			{
				if(CMGetNewContent::GetInstance()->GetItem(i,item))
				{
					TiXmlElement* pAddItem = item.CreateXmlElement();
					if(pAddItem)
					{
						TiXmlElement*pItem = pRootElement->FirstChildElement("item");
						if (pItem) {
							pRootElement->InsertBeforeChild(pItem, *pAddItem);
							SAFEDELETE(pAddItem);
						}
						else
							pRootElement->LinkEndChild(pAddItem);
					}
				}
			}
			pContentDoc->SaveFile();
		}
		SAFEDELETE(pContentDoc);

		/////////////////////////////////////////////////////
		HKEY	hOpenKey;
		long	lResult		= 0;
		LPCTSTR	keyName		= _T("Software\\Microsoft\\Today\\Items\\\"MLPlayer\"");		
		lResult = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, 0, &hOpenKey);
		if(lResult != ERROR_SUCCESS)
			return;
		DWORD	iTemp = 1;
		lResult = ::RegSetValueEx(hOpenKey, _T("NewContent"),0, REG_DWORD, (BYTE*)&iTemp, sizeof(iTemp));
		::RegCloseKey(hOpenKey);
		if(lResult != ERROR_SUCCESS)
			return;
	}
}
开发者ID:jianbinking,项目名称:mlplayer_shzh,代码行数:54,代码来源:cmgetnewcontent.cpp

示例2: AddBookmark

bool CBookmarksDialog::AddBookmark(const wxString &name, const wxString &local_dir, const CServerPath &remote_dir, bool sync)
{
	if (local_dir.empty() && remote_dir.empty())
		return false;
	if ((local_dir.empty() || remote_dir.empty()) && sync)
		return false;

	CInterProcessMutex mutex(MUTEX_GLOBALBOOKMARKS);

	CXmlFile file(wxGetApp().GetSettingsFile(_T("bookmarks")));
	TiXmlElement* pDocument = file.Load();
	if (!pDocument) {
		wxString msg = file.GetError() + _T("\n\n") + _("The bookmark could not be added.");
		wxMessageBoxEx(msg, _("Error loading xml file"), wxICON_ERROR);

		return false;
	}

	TiXmlElement *pInsertBefore = 0;
	TiXmlElement *pBookmark;
	for (pBookmark = pDocument->FirstChildElement("Bookmark"); pBookmark; pBookmark = pBookmark->NextSiblingElement("Bookmark")) {
		wxString remote_dir_raw;

		wxString old_name = GetTextElement(pBookmark, "Name");

		if (!name.CmpNoCase(old_name)) {
			wxMessageBoxEx(_("Name of bookmark already exists."), _("New bookmark"), wxICON_EXCLAMATION);
			return false;
		}
		if (name < old_name && !pInsertBefore)
			pInsertBefore = pBookmark;
	}

	if (pInsertBefore)
		pBookmark = pDocument->InsertBeforeChild(pInsertBefore, TiXmlElement("Bookmark"))->ToElement();
	else
		pBookmark = pDocument->LinkEndChild(new TiXmlElement("Bookmark"))->ToElement();
	AddTextElement(pBookmark, "Name", name);
	if (!local_dir.empty())
		AddTextElement(pBookmark, "LocalDir", local_dir);
	if (!remote_dir.empty())
		AddTextElement(pBookmark, "RemoteDir", remote_dir.GetSafePath());
	if (sync)
		AddTextElementRaw(pBookmark, "SyncBrowsing", "1");

	if (!file.Save(false)) {
		wxString msg = wxString::Format(_("Could not write \"%s\", the bookmark could not be added: %s"), file.GetFileName(), file.GetError());
		wxMessageBoxEx(msg, _("Error writing xml file"), wxICON_ERROR);
		return false;
	}

	return true;
}
开发者ID:juaristi,项目名称:filezilla,代码行数:53,代码来源:bookmarks_dialog.cpp

示例3: GetGenericElement

	TiXmlElement* GetGenericElement(TypeGenRecord* tGenRecord)
	{
		TiXmlElement *genEl = GetGenericElement(tGenRecord->Generic);

		// записываем все поля
		if (!tGenRecord->objects.objList.empty())
		{
			TiXmlElement *fieldsEl = new TiXmlElement("Fields");

			for(unsigned int i = 0; i < tGenRecord->objects.objList.size(); ++i)
			{
				Field *field = static_cast<Field*>(tGenRecord->objects.objList[i]);
				TiXmlElement *fieldEl = GetFieldElement(field);
				fieldsEl->InsertEndChild(*fieldEl);
			}

			genEl->InsertBeforeChild(genEl->FirstChild(), *fieldsEl);
		}

		return genEl;
	}
开发者ID:kpdev42,项目名称:Kaleidoscope,代码行数:21,代码来源:GenProcsManager.cpp

示例4: AddBookmark

bool CSiteManager::AddBookmark(wxString sitePath, const wxString& name, const wxString &local_dir, const CServerPath &remote_dir, bool sync)
{
	if (local_dir.empty() && remote_dir.IsEmpty())
		return false;

	if (sitePath[0] != '0')
		return false;

	sitePath = sitePath.Mid(1);

	// We have to synchronize access to sitemanager.xml so that multiple processed don't write
	// to the same file or one is reading while the other one writes.
	CInterProcessMutex mutex(MUTEX_SITEMANAGER);

	CXmlFile file;
	TiXmlElement* pDocument = file.Load(_T("sitemanager"));

	if (!pDocument)
	{
		wxString msg = file.GetError() + _T("\n") + _("The bookmark could not be added.");
		wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR);

		return false;
	}

	TiXmlElement* pElement = pDocument->FirstChildElement("Servers");
	if (!pElement)
		return false;

	std::list<wxString> segments;
	if (!UnescapeSitePath(sitePath, segments))
	{
		wxMessageBox(_("Site path is malformed."), _("Invalid site path"));
		return 0;
	}

	TiXmlElement* pChild = GetElementByPath(pElement, segments);
	if (!pChild || strcmp(pChild->Value(), "Server"))
	{
		wxMessageBox(_("Site does not exist."), _("Invalid site path"));
		return 0;
	}

	// Bookmarks
	TiXmlElement *pInsertBefore = 0;
	TiXmlElement* pBookmark;
	for (pBookmark = pChild->FirstChildElement("Bookmark"); pBookmark; pBookmark = pBookmark->NextSiblingElement("Bookmark"))
	{
		TiXmlHandle handle(pBookmark);

		wxString old_name = GetTextElement_Trimmed(pBookmark, "Name");
		if (old_name.empty())
			continue;

		if (name == old_name)
		{
			wxMessageBox(_("Name of bookmark already exists."), _("New bookmark"), wxICON_EXCLAMATION);
			return false;
		}
		if (name < old_name && !pInsertBefore)
			pInsertBefore = pBookmark;
	}

	if (pInsertBefore)
		pBookmark = pChild->InsertBeforeChild(pInsertBefore, TiXmlElement("Bookmark"))->ToElement();
	else
		pBookmark = pChild->LinkEndChild(new TiXmlElement("Bookmark"))->ToElement();
	AddTextElement(pBookmark, "Name", name);
	if (!local_dir.empty())
		AddTextElement(pBookmark, "LocalDir", local_dir);
	if (!remote_dir.IsEmpty())
		AddTextElement(pBookmark, "RemoteDir", remote_dir.GetSafePath());
	if (sync)
		AddTextElementRaw(pBookmark, "SyncBrowsing", "1");

	wxString error;
	if (!file.Save(&error))
	{
		if (COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 2)
			return true;

		wxString msg = wxString::Format(_("Could not write \"%s\", the selected sites could not be exported: %s"), file.GetFileName().GetFullPath().c_str(), error.c_str());
		wxMessageBox(msg, _("Error writing xml file"), wxICON_ERROR);
	}

	return true;
}
开发者ID:pappacurds,项目名称:filezilla,代码行数:87,代码来源:sitemanager.cpp

示例5: saveSpawn

	void Level::saveSpawn() {
		string filename = folder + LIBGENS_LEVEL_DATA_STAGE;

		TiXmlDocument doc(filename);
		if (!doc.LoadFile()) {
			return;
		}

		TiXmlHandle hDoc(&doc);
		TiXmlElement* pElem;
		TiXmlElement* pElem_i;
		TiXmlHandle hRoot(0);

		pElem=hDoc.FirstChildElement().Element();
		if (!pElem) {
			return;
		}

		// Update the current spawn point with an active Sonic Spawn object if available
		list<Object *> spawn_objects;
		getObjectsByName(LIBGENS_SPAWN_POINT_OBJECT_NAME, spawn_objects);

		for (list<Object *>::iterator it=spawn_objects.begin(); it!=spawn_objects.end(); it++) {
			ObjectElement *element = (*it)->getElement(LIBGENS_SPAWN_POINT_OBJECT_FLAG);

			if (element) {
				ObjectElementBool *element_bool = static_cast<LibGens::ObjectElementBool *>(element);

				if (element_bool->value) {
					ObjectElementString *element_mode = static_cast<LibGens::ObjectElementString *>((*it)->getElement(LIBGENS_LEVEL_XML_MODE));
					ObjectElementString *element_view = static_cast<LibGens::ObjectElementString *>((*it)->getElement(LIBGENS_LEVEL_XML_CAMERA_VIEW));
					ObjectElementFloat  *element_speed = static_cast<LibGens::ObjectElementFloat *>((*it)->getElement(LIBGENS_LEVEL_XML_SPEED));
					ObjectElementFloat  *element_time = static_cast<LibGens::ObjectElementFloat *>((*it)->getElement(LIBGENS_LEVEL_XML_TIME));

					spawn_yaw         = (*it)->getRotation().getYawDegrees();
					spawn_position    = (*it)->getPosition();
					spawn_mode        = (element_mode  ? element_mode->value  : "Stand");
					spawn_speed       = (element_speed ? element_speed->value : 0.0f);
					spawn_time        = (element_time  ? element_time->value  : 0.0f);
					spawn_camera_view = (element_view ? element_view->value : "Forward");
					break;
				}
			}
		}

		// Search and delete the first appearance of the Sonic Spawn Point Segment
		pElem_i=pElem->FirstChildElement();
		for(pElem_i; pElem_i; pElem_i=pElem_i->NextSiblingElement()) {
			if (pElem_i->ValueStr() == LIBGENS_LEVEL_XML_SONIC) {
				pElem->RemoveChild(pElem_i);
				break;
			}
		}

		// Re-create the Sonic Spawn Point Segment and insert it at the start

		TiXmlElement newSpawnNode(LIBGENS_LEVEL_XML_SONIC);
		pElem_i = pElem->InsertBeforeChild(pElem->FirstChildElement(), newSpawnNode)->ToElement();

		TiXmlElement* positionRoot=new TiXmlElement(LIBGENS_OBJECT_ELEMENT_POSITION);
		spawn_position.writeXML(positionRoot);
		pElem_i->LinkEndChild(positionRoot);

		TiXmlElement* yawRoot=new TiXmlElement(LIBGENS_LEVEL_XML_YAW);
		TiXmlText* yawValue=new TiXmlText(ToString(spawn_yaw));
		yawRoot->LinkEndChild(yawValue);
		pElem_i->LinkEndChild(yawRoot);

		TiXmlElement* startRoot=new TiXmlElement(LIBGENS_LEVEL_XML_START);
		{
			TiXmlElement* modeRoot=new TiXmlElement(LIBGENS_LEVEL_XML_MODE);
			TiXmlText* modeValue=new TiXmlText(spawn_mode);
			modeRoot->LinkEndChild(modeValue);
			startRoot->LinkEndChild(modeRoot);

			TiXmlElement* speedRoot=new TiXmlElement(LIBGENS_LEVEL_XML_SPEED);
			TiXmlText* speedValue=new TiXmlText(ToString(spawn_speed));
			speedRoot->LinkEndChild(speedValue);
			startRoot->LinkEndChild(speedRoot);

			TiXmlElement* timeRoot=new TiXmlElement(LIBGENS_LEVEL_XML_TIME);
			TiXmlText* timeValue=new TiXmlText(ToString(spawn_time));
			timeRoot->LinkEndChild(timeValue);
			startRoot->LinkEndChild(timeRoot);
		}
		pElem_i->LinkEndChild(startRoot);

		TiXmlElement* deadHeightRoot=new TiXmlElement(LIBGENS_LEVEL_XML_DEAD_HEIGHT);
		TiXmlText* deadHeightValue=new TiXmlText(ToString(spawn_dead_height));
		deadHeightRoot->LinkEndChild(deadHeightValue);
		pElem_i->LinkEndChild(deadHeightRoot);

		TiXmlElement* cameraViewRoot=new TiXmlElement(LIBGENS_LEVEL_XML_CAMERA_VIEW);
		TiXmlText* cameraViewValue=new TiXmlText(spawn_camera_view);
		cameraViewRoot->LinkEndChild(cameraViewValue);
		pElem_i->LinkEndChild(cameraViewRoot);

		// Save the changes
		if (!doc.SaveFile(filename)) {
			Error::addMessage(Error::FILE_NOT_FOUND, LIBGENS_OBJECT_H_ERROR_WRITE_SET_XML + filename);
//.........这里部分代码省略.........
开发者ID:BestWanted,项目名称:libgens-sonicglvl,代码行数:101,代码来源:Level.cpp

示例6: SwitchTo

void CfgMgrBldr::SwitchTo(const wxString& fileName)
{
    doc = new TiXmlDocument();

    if (!TinyXML::LoadDocument(fileName, doc))
    {
        doc->InsertEndChild(TiXmlDeclaration("1.0", "UTF-8", "yes"));
        doc->InsertEndChild(TiXmlElement("CodeBlocksConfig"));
        doc->FirstChildElement("CodeBlocksConfig")->SetAttribute("version", CfgMgrConsts::version);
    }

    if (doc->ErrorId())
        cbThrow(wxString::Format(_T("TinyXML error: %s\nIn file: %s\nAt row %d, column: %d."), cbC2U(doc->ErrorDesc()).c_str(), fileName.c_str(), doc->ErrorRow(), doc->ErrorCol()));

    TiXmlElement* docroot = doc->FirstChildElement("CodeBlocksConfig");

    if (doc->ErrorId())
        cbThrow(wxString::Format(_T("TinyXML error: %s\nIn file: %s\nAt row %d, column: %d."), cbC2U(doc->ErrorDesc()).c_str(), fileName.c_str(), doc->ErrorRow(), doc->ErrorCol()));

    const char *vers = docroot->Attribute("version");
    if (!vers || atoi(vers) != 1)
        cbMessageBox(_("ConfigManager encountered an unknown config file version. Continuing happily."), _("Warning"), wxICON_WARNING);

    doc->ClearError();

    wxString info;
#ifndef __GNUC__
    info.Printf(_T( " application info:\n"
                    "\t svn_revision:\t%u\n"
                    "\t build_date:\t%s, %s "), ConfigManager::GetRevisionNumber(), wxT(__DATE__), wxT(__TIME__));
#else
    info.Printf(_T( " application info:\n"
                    "\t svn_revision:\t%u\n"
                    "\t build_date:\t%s, %s\n"
                    "\t gcc_version:\t%d.%d.%d "), ConfigManager::GetRevisionNumber(), wxT(__DATE__), wxT(__TIME__),
                __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#endif

    if (platform::windows)
        info.append(_T("\n\t Windows "));
    if (platform::linux)
        info.append(_T("\n\t Linux "));
    if (platform::macosx)
        info.append(_T("\n\t Mac OS X "));
    if (platform::unix)
        info.append(_T("\n\t Unix "));

    info.append(platform::unicode ? _T("Unicode ") : _T("ANSI "));

    TiXmlComment c;
    c.SetValue((const char*) info.mb_str());

    TiXmlNode *firstchild = docroot->FirstChild();
    if (firstchild && firstchild->ToComment())
    {
        docroot->RemoveChild(firstchild);
        firstchild = docroot->FirstChild();
    }

    if (firstchild)
        docroot->InsertBeforeChild(firstchild, c);
    else
        docroot->InsertEndChild(c);
}
开发者ID:alpha0010,项目名称:codeblocks_sf,代码行数:64,代码来源:configmanager.cpp


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