本文整理汇总了C++中TiXmlNode::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlNode::Clear方法的具体用法?C++ TiXmlNode::Clear怎么用?C++ TiXmlNode::Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlNode
的用法示例。
在下文中一共展示了TiXmlNode::Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nameNode
/** Changes the server's technical note
*
* The xml document should be saved after this call.
*
* \param v The new server's technical note
*
*/
void RainbruRPG::Server::xmlServerConf::setTechNote(const std::string& v){
TiXmlText nameNode(v.c_str());
TiXmlNode* childNode = root->FirstChild( "TechnicalNote" );
if (childNode){
childNode->Clear();
childNode->InsertEndChild(nameNode);
}
}
示例2: set_value
void XMLConfiguration::set_value(const string& section, const string& object, const string& value)
{
bool section_found = false;
bool object_found = false;
TiXmlNode* child = 0;
TiXmlNode* nephew = 0;
if(m_document->NoChildren()==false)
{
while((!section_found) && ( child = m_document->IterateChildren( child ) ))
{
if(string(child->Value())==section)
{
section_found = true;
}
}
}
if(section_found == false)
{
LOG_INFO("XMLConfiguration: no section "<<section<<" found, creating.");
child = new TiXmlElement( section.c_str() );
m_document->LinkEndChild( child );
}
if(child->NoChildren()==false)
{
while((!object_found) &&( nephew = child->IterateChildren( nephew ) ))
{
if(string(nephew->Value())==object)
{
object_found = true;
}
}
}
if(object_found == false)
{
LOG_INFO("XMLConfiguration: no object "<<section<<"/"<<object<<" found, creating.");
nephew = new TiXmlElement( object.c_str() );
child->LinkEndChild( nephew );
}
nephew->Clear();
TiXmlText* text_element = new TiXmlText( value.c_str() );
nephew->LinkEndChild( text_element );
}
示例3: Save
bool CSettings::Save()
{
// Are we not flagged as open?
if(!m_bOpen)
return false;
// Are we not flagged as allowed to save the file?
if(!m_bSave)
return false;
// Loop through all values
for(std::map<String, SettingsValue *>::iterator iter = m_values.begin(); iter != m_values.end(); iter++)
{
// Get the setting pointer
SettingsValue * setting = iter->second;
// Find all nodes for this value
bool bFoundNode = false;
for(TiXmlNode * pNode = m_XMLDocument.RootElement()->FirstChildElement(iter->first.Get()); pNode; pNode = pNode->NextSibling())
{
// Is this not an element node?
if(pNode->Type() != TiXmlNode::ELEMENT)
continue;
// Is this not the node we are looking for?
if(iter->first.Compare(pNode->Value()))
continue;
// Is this a list node?
if(setting->IsList())
{
// Remove the node
m_XMLDocument.RootElement()->RemoveChild(pNode);
}
else
{
// Clear the node
pNode->Clear();
// Get the node value
String strValue = GetEx(iter->first);
// Create a new node value
TiXmlText * pNewNodeValue = new TiXmlText(strValue.Get());
// Add the new node value to the new node
pNode->LinkEndChild(pNewNodeValue);
}
// Flag as found a node
bFoundNode = true;
break;
}
// Is this a list value?
if(setting->IsList())
{
// Loop through each list item
for(std::list<String>::iterator iter2 = setting->listValue.begin(); iter2 != setting->listValue.end(); iter2++)
{
// Create a new node
TiXmlElement * pNewNode = new TiXmlElement(iter->first.Get());
// Create a new node value
TiXmlText * pNewNodeValue = new TiXmlText((*iter2).Get());
// Add the new node value to the new node
pNewNode->LinkEndChild(pNewNodeValue);
// Add the new node to the XML document
m_XMLDocument.RootElement()->LinkEndChild(pNewNode);
}
}
else
{
// Do we need to create a new node?
if(!bFoundNode)
{
// Create a new node
TiXmlElement * pNewNode = new TiXmlElement(iter->first.Get());
// Get the node value
String strValue = GetEx(iter->first);
// Create a new node value
TiXmlText * pNewNodeValue = new TiXmlText(strValue.Get());
// Add the new node value to the new node
pNewNode->LinkEndChild(pNewNodeValue);
// Add the new node to the XML document
m_XMLDocument.RootElement()->LinkEndChild(pNewNode);
}
}
}
// Save the XML document
return m_XMLDocument.SaveFile();
}
示例4: SetSectionValue
int CHsMiscellany::SetSectionValue( CString lpszSection, CString lpszValue )
{
CString strPath = "";
TiXmlNode* pNode = NULL;
if (lpszSection.IsEmpty())
{// 删除所有<Section>下子节点
strPath = "//Miscellany/Section";
pNode = m_pConfigBase->GetNode(strPath, "", "", UserDoc);
if (pNode && !::IsBadReadPtr(pNode, 1))
{
pNode->Clear(); // 删除所有子节点
m_pConfigBase->GetXmlDocument(UserDoc)->SetModified(TRUE);
}
return 1;
}
else if (lpszValue.IsEmpty())
{// 删除<Section>下 id=lpszSection的节点
strPath = "//Miscellany/Section";
pNode = m_pConfigBase->GetNode(strPath, "", "", UserDoc);
if (pNode && !::IsBadReadPtr(pNode, 1))
{
strPath = "//Miscellany/Section/Item";
TiXmlNode* pChildNode = m_pConfigBase->GetNode(strPath, "id", lpszSection, UserDoc);
if (pChildNode && !::IsBadReadPtr(pChildNode, 1))
{
pNode->RemoveChild(pChildNode);
}
}
return 1;
}
else
{// 都不为空 更新节点
strPath = "//Miscellany/Section";
pNode = m_pConfigBase->SetNode(strPath);
if (pNode && !::IsBadReadPtr(pNode, 1))
{
TiXmlNode* pChildNode = pNode->FirstChild();
while(pChildNode)
{
if ( pChildNode->ToElement()->Attribute("id") == lpszSection)
{
m_pConfigBase->SetNodeAttrString(pChildNode, "value", lpszValue);
return lpszValue.GetLength();
}
pChildNode = pChildNode->NextSibling();
}
TiXmlElement* pElement = new TiXmlElement("Item");
pElement->SetAttribute("id", lpszSection);
pElement->SetAttribute("value", lpszValue);
pNode->LinkEndChild(pElement);
}
return lpszValue.GetLength();
}
}