本文整理汇总了C++中TiXmlDocument::RemoveChild方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlDocument::RemoveChild方法的具体用法?C++ TiXmlDocument::RemoveChild怎么用?C++ TiXmlDocument::RemoveChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlDocument
的用法示例。
在下文中一共展示了TiXmlDocument::RemoveChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DeleteNodeByNameIndex
/***********************************************************************************************************
* 程序作者:赵进军
* 函数功能:删除XML文件中指定的节点的最后一个节点
* 参数说明:
* delNodeName:需要删除的节点的名称
* nodeIndex:需要删除的节点的位置
* 注意事项:null
* 修改日期:2015/12/12 16:49:00
***********************************************************************************************************/
bool OperationProfile_XML::DeleteNodeByNameIndex(char* delNodeName, int nodeIndex)
{
if (nodeIndex >= groupNodeCount)
printf("当前删除的节点位置不存在!");
if (!OperationProfile_XML::XMLExits())
return false;
TiXmlDocument* myDocument = new TiXmlDocument();
if (NULL == myDocument)
return false;
myDocument->LoadFile(IOperationProfile::ProfileAddress);
TiXmlElement* pRootEle = myDocument->RootElement();
if (NULL == pRootEle)
return false;
TiXmlElement *pNode = NULL;
if (arrayIndex != 0)
arrayIndex = 0;
if (!GetNodePointerByName(pRootEle, delNodeName, pNode, nodeIndex))
return false;
if (pRootEle == pNode)
{
if (myDocument->RemoveChild(pRootEle))
{
myDocument->SaveFile(IOperationProfile::ProfileAddress);
return true;
}
else
{
return false;
}
}
if (NULL != pNode)
{
TiXmlNode* pParNode = pNode->Parent();
if (NULL == pParNode)
return false;
TiXmlElement* pParentEle = pParNode->ToElement();
if (NULL != pParentEle)
{
if (pParentEle->RemoveChild(pNode))
myDocument->SaveFile(IOperationProfile::ProfileAddress);
else
return false;
}
}
else
{
return false;
}
return false;
}
示例2: DeleteNodeByNameAll
/***********************************************************************************************************
* 程序作者:赵进军
* 函数功能:删除XML文件中所有符合条件的节点
* 参数说明:
* strNodeName:需要删除的节点指针的名称
* 注意事项:null
* 修改日期:2015/12/13 14:52:00
***********************************************************************************************************/
bool OperationProfile_XML::DeleteNodeByNameAll(char* delNodeName)
{
if (!OperationProfile_XML::XMLExits())
return false;
TiXmlDocument* myDocument = new TiXmlDocument();
if (NULL == myDocument)
return false;
myDocument->LoadFile(IOperationProfile::ProfileAddress);
TiXmlElement* pRootEle = myDocument->RootElement();
if (NULL == pRootEle)
return false;
if (arrayIndex != 0)
arrayIndex = 0;
TiXmlElement* pNodes[] = { NULL, NULL }; // 该处设计存在缺陷,无法定义动态数组
GetNodePointerByNameAll(pRootEle, delNodeName, pNodes);
if (pRootEle == pNodes[0])
{
if (myDocument->RemoveChild(pRootEle))
{
myDocument->SaveFile(IOperationProfile::ProfileAddress);
return true;
}
else
{
return false;
}
}
if (NULL != pNodes)
{
for (int i = 0; i < groupNodeCount; i++)
{
TiXmlNode* pParNode = pNodes[i]->Parent();
if (NULL == pParNode)
return false;
TiXmlElement* pParentEle = pParNode->ToElement();
if (NULL != pParentEle)
if (pParentEle->RemoveChild(pNodes[i]))
myDocument->SaveFile(IOperationProfile::ProfileAddress);
}
}
else
{
return false;
}
return false;
}
示例3: 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");
}
//.........这里部分代码省略.........