本文整理汇总了C++中CXmlFile::Save方法的典型用法代码示例。如果您正苦于以下问题:C++ CXmlFile::Save方法的具体用法?C++ CXmlFile::Save怎么用?C++ CXmlFile::Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CXmlFile
的用法示例。
在下文中一共展示了CXmlFile::Save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClearBookmarks
bool CSiteManager::ClearBookmarks(wxString sitePath)
{
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 bookmarks could not be cleared.");
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;
}
TiXmlElement *pBookmark = pChild->FirstChildElement("Bookmark");
while (pBookmark)
{
pChild->RemoveChild(pBookmark);
pBookmark = pChild->FirstChildElement("Bookmark");
}
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;
}
示例2: SaveConditions
void CSearchDialog::SaveConditions()
{
CInterProcessMutex mutex(MUTEX_SEARCHCONDITIONS);
CXmlFile file;
TiXmlElement* pDocument = file.Load(_T("search"));
if (!pDocument)
{
wxMessageBox(file.GetError(), _("Error loading xml file"), wxICON_ERROR);
return;
}
TiXmlElement* pFilter;
while ((pFilter = pDocument->FirstChildElement("Filter")))
pDocument->RemoveChild(pFilter);
pFilter = pDocument->LinkEndChild(new TiXmlElement("Filter"))->ToElement();
CFilterDialog::SaveFilter(pFilter, m_search_filter);
file.Save();
}
示例3: 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;
}
示例4: AddServer
wxString CSiteManager::AddServer(CServer server)
{
// 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 server could not be added.");
wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR);
return _T("");
}
TiXmlElement* pElement = pDocument->FirstChildElement("Servers");
if (!pElement)
return _T("");
std::list<wxString> names;
for (TiXmlElement* pChild = pElement->FirstChildElement("Server"); pChild; pChild = pChild->NextSiblingElement("Server"))
{
wxString name = GetTextElement(pChild, "Name");
if (name.empty())
continue;
names.push_back(name);
}
wxString name = _("New site");
int i = 1;
for (;;)
{
std::list<wxString>::const_iterator iter;
for (iter = names.begin(); iter != names.end(); ++iter)
{
if (*iter == name)
break;
}
if (iter == names.end())
break;
name = _("New site") + wxString::Format(_T(" %d"), ++i);
}
server.SetName(name);
TiXmlElement* pServer = pElement->LinkEndChild(new TiXmlElement("Server"))->ToElement();
SetServer(pServer, server);
char* utf8 = ConvUTF8(name);
if (utf8)
{
pServer->LinkEndChild(new TiXmlText(utf8));
delete [] utf8;
}
wxString error;
if (!file.Save(&error))
{
if (COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 2)
return _T("");
wxString msg = wxString::Format(_("Could not write \"%s\", any changes to the Site Manager could not be saved: %s"), file.GetFileName().GetFullPath().c_str(), error.c_str());
wxMessageBox(msg, _("Error writing xml file"), wxICON_ERROR);
return _T("");
}
return _T("0/") + EscapeSegment(name);
}