本文整理汇总了C++中TiXmlNode::RemoveChild方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlNode::RemoveChild方法的具体用法?C++ TiXmlNode::RemoveChild怎么用?C++ TiXmlNode::RemoveChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlNode
的用法示例。
在下文中一共展示了TiXmlNode::RemoveChild方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DeleteNode
void DirectoryWriter::DeleteNode(char *nodeName)
{
TiXmlDocument doc("Config.xml");
bool loadOkay = doc.LoadFile();
if (!loadOkay)
{
printf("Could not load test file 'Config.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc());
exit(1);
}
TiXmlNode *versionNode = 0;
versionNode = doc.FirstChild("Version");
TiXmlElement *versionelement = versionNode->ToElement();
std::string version = versionelement->Attribute("Number");
int value = atoi(version.c_str());
value += 1;
versionelement->SetAttribute("Number", value);
TiXmlNode *node = 0;
node = doc.FirstChild("Filesystem");
TiXmlElement *searchNode = 0;
for (TiXmlElement* e = node->FirstChildElement("File"); e != NULL; e = e->NextSiblingElement("File"))
{
const char *attribute = e->Attribute("filename");
if (strcmp(attribute, nodeName) == 0)
{
node->RemoveChild(e);
break;
}
}
doc.SaveFile();
}
示例2: read_from_configuration
void Profile::read_from_configuration (Configuration* configuration)
{
TiXmlNode* node = 0;
// insert initial mandatory declaration if not present
TiXmlNode* decl = 0;
for (TiXmlNode* child = xmlProfileDoc->FirstChild();
child && !decl; child = child->NextSibling() ) {
decl = child->ToDeclaration ();
}
if (! decl) {
node = xmlProfileDoc->InsertEndChild( TiXmlDeclaration( "1.0", "UTF-8", "no" ) );
assert (node);
}
// for each configuration variable in configuration
for (std::map<std::string, Variable*>::const_iterator conf_it = configuration->begin();
conf_it != configuration->end();
conf_it ++) {
// start from root of DOM
node = xmlProfileDoc;
// get the variable name and break it up in its component vector
std::string variable_name = conf_it->second->get_name ();
std::vector<std::string> variable_name_vector = Variable::string_to_vector (variable_name);
// for each component in variable name vector
for (size_t i = 0; i < variable_name_vector.size(); i++) {
// check if component element exists
TiXmlElement* existing = node->FirstChildElement (variable_name_vector[i].c_str());
if (existing) {
// carry on with existing component
node = existing;
} else {
// create missing component element and carry on with new component
node = node->InsertEndChild (TiXmlElement (variable_name_vector[i].c_str()));
assert (node);
}
}
// check if a text node for element exists
TiXmlText* text = 0;
for(TiXmlNode* child = node->FirstChild(); child && !text; child = child->NextSibling() ) {
text = child->ToText ();
}
if (text) {
// text child already exists, so remove it to set new value
node->RemoveChild (text);
}
node = node->InsertEndChild (TiXmlText (conf_it->second->get_value ().c_str ()));
assert (node);
}
}
示例3: DoLayers
static void DoLayers()
{
/* ---- */
/* Open */
/* ---- */
XML_TKEM xml( gArgs.GetXML(), flog );
TiXmlElement* layer = xml.GetFirstLayer();
/* ------------------------- */
/* Kill layers outside range */
/* ------------------------- */
TiXmlNode* lyrset = layer->Parent();
TiXmlElement* next;
for( ; layer; layer = next ) {
// next layer0 before deleting anything
next = layer->NextSiblingElement();
int z = atoi( layer->Attribute( "z" ) );
if( z < gArgs.zmin || z > gArgs.zmax )
lyrset->RemoveChild( layer );
}
/* --------------------------- */
/* Copies for remaining layers */
/* --------------------------- */
layer = lyrset->FirstChild( "t2_layer" )->ToElement();
for( ; layer; layer = layer->NextSiblingElement() ) {
int z = atoi( layer->Attribute( "z" ) );
gArgs.NewLayer( z );
UpdateTiles( layer );
}
/* ---- */
/* Save */
/* ---- */
xml.Save( "xmltmp.txt", true );
/* ------------------ */
/* Rename version two */
/* ------------------ */
gArgs.RenameXML();
}
示例4: remove_object
void XMLConfiguration::remove_object(const string& section_name, const string& object_name)
{
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_name)
{
section_found = true;
}
}
}
if(section_found == false)
{
return;
}
if(child->NoChildren()==false)
{
while((!object_found) && ( nephew = child->IterateChildren( nephew ) ))
{
if(string(nephew->Value())==object_name)
{
object_found = true;
}
}
}
if(object_found == false)
{
return;
}
child->RemoveChild(nephew);
}
示例5: sa
_MEMBER_FUNCTION_IMPL( XmlNode, Remove )
{
StackHandler sa(v);
_CHECK_SELF( TiXmlNode, XmlNode );
TiXmlNode* pParent = self->Parent();
if ( pParent )
{
pParent->RemoveChild( self );
sa.Return( true );
return 1;
}
sa.Return( false );
return 1;
}
示例6: RemoveElem
/**************************************************************************
* name : RemoveElem
* description: 删除元素
* input : NA
* output : NA
* return : true - 成功,false - 失败
* remark : NA
**************************************************************************/
bool CXml::RemoveElem()
{
if (NULL == m_pXmlNode)
{
return false;
}
TiXmlNode* pTempParentNode = NULL;
TiXmlNode* pTempNode = NULL;
pTempParentNode = m_pXmlNode->Parent();//lint !e838
if ((m_pXmlNode->PreviousSibling()) && (m_pXmlNode->PreviousSibling()->ToElement()))
{
pTempNode = m_pXmlNode->PreviousSibling();
}
else if ((m_pXmlNode->NextSibling()) && (m_pXmlNode->NextSibling()->ToElement()))
{
pTempNode = m_pXmlNode->NextSibling();
}
else
{
pTempNode = pTempParentNode;
}
//判断指针是否为空
CHECK_POINTER(pTempParentNode,false);
if (!pTempParentNode->RemoveChild(m_pXmlNode))
{
return false;
}
m_pXmlNode = pTempNode;
return true;
}
示例7: DeleteAllSubNodes
CXMLNodeImpl::~CXMLNodeImpl ( void )
{
// Remove from array over XML stuff
if ( m_bUsingIDs )
CXMLArray::PushUniqueID ( this );
// Delete our children
DeleteAllSubNodes ();
// We need a parent to delete the node
if ( m_pParent )
{
// Remove from parent list
m_pParent->RemoveFromList ( this );
}
else
{
// NULL it in the file if any
if ( m_pFile )
{
m_pFile->m_pRootNode = NULL;
}
}
// Need to delete the node?
if ( m_pNode )
{
// Grab the parent of our node and delete it using that if any to prevent crashing.
// Otherwize delete it directly.
TiXmlNode* pParent = m_pNode->Parent ();
if ( pParent )
pParent->RemoveChild ( m_pNode );
else
delete m_pNode;
}
}
示例8: UpdateAppStat
void CAppManager::UpdateAppStat(const std::string& AppId)
{
CStdString fileName = _P("special://profile/apps/apps.xml");
CStdString strValue, currAppStr;
CStdString tmp;
CStdString appsPath = _P("special://home/apps/");
CAppDescriptor::AppDescriptorsMap installedAppsDesc;
GetInstalledAppsInternal(installedAppsDesc, appsPath, "", false);
TiXmlDocument xmlDoc;
TiXmlElement *pRootElement = NULL;
TiXmlNode *pTempNode = NULL;
bool fixDoc = true;
CLog::Log(LOGINFO, "updating %s's information in apps.xml", AppId.c_str());
if ( xmlDoc.LoadFile( fileName) )
{
pRootElement = xmlDoc.RootElement();
if (pRootElement)
{
strValue = pRootElement->Value();
if ( strValue == "apps")
{
fixDoc = false;
}
}
}
if (fixDoc)
{
if (pRootElement)
{
xmlDoc.RemoveChild(pRootElement);
}
else
{
pTempNode = xmlDoc.FirstChild();
if (pTempNode > 0)
xmlDoc.RemoveChild(pTempNode);
}
pRootElement = new TiXmlElement( "apps" );
pRootElement->SetAttribute("version", "1.0");
xmlDoc.LinkEndChild(pRootElement);
}
TiXmlNode *pAppNode = pRootElement->FirstChild("app");
TiXmlNode *pOpenedCntNode = NULL, *pIdNode = NULL, *pLastOpenedDateNode = NULL;
while (pAppNode > 0)
{
pIdNode = pAppNode->FirstChild("id");
if (pIdNode && pIdNode->FirstChild())
{
currAppStr = pIdNode->FirstChild()->Value();
if (currAppStr == AppId)
{
pLastOpenedDateNode = pAppNode->FirstChild("lastopeneddate");
pOpenedCntNode = pAppNode->FirstChild("timesopened");
if (pOpenedCntNode && pOpenedCntNode->FirstChild())
{
int openedCnt = atoi (pOpenedCntNode->FirstChild()->Value());
openedCnt++;
tmp = BOXEE::BXUtils::IntToString(openedCnt);
pOpenedCntNode->FirstChild()->SetValue(tmp.c_str());
//CLog::Log(LOGDEBUG," Found name: %s", strName.c_str());
}
else
{
if (pOpenedCntNode)
{
pAppNode->RemoveChild(pOpenedCntNode);
}
TiXmlElement * timesOpenedElement = new TiXmlElement( "timesopened" );
TiXmlText * timesOpenedText = new TiXmlText( "1" );
timesOpenedElement->LinkEndChild( timesOpenedText );
pAppNode->LinkEndChild(timesOpenedElement);
}
if (pLastOpenedDateNode)
{
pAppNode->RemoveChild(pLastOpenedDateNode);
}
tmp = BOXEE::BXUtils::IntToString(std::time(NULL));
TiXmlElement * lastOpenedElement = new TiXmlElement( "lastopeneddate" );
TiXmlText * lastOpenedText = new TiXmlText(tmp.c_str());
lastOpenedElement->LinkEndChild( lastOpenedText );
pAppNode->LinkEndChild(lastOpenedElement);
}
CLog::Log(LOGDEBUG, "deleting %s from apps map\n", currAppStr.c_str());
installedAppsDesc.erase(currAppStr);
}
pAppNode = pAppNode->NextSiblingElement("app");
}
//.........这里部分代码省略.........
示例9: 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();
}
}