コード例 #1
0
ファイル: DirectoryWriter.cpp プロジェクト: BioDice/OS3CS
	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
0
ファイル: profile.cpp プロジェクト: allisonChilton/Presage
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
0
void XMLLanguages::RemoveItem(int id)
{
    TiXmlElement* item = GetItem(id);
    TiXmlNode* parent;
    if(item && (parent = item->Parent()))
    {
        parent->RemoveChild(item);
    }
}
コード例 #4
0
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();
}
コード例 #5
0
ファイル: xml_configuration.cpp プロジェクト: giuppe/mdc
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);
}
コード例 #6
0
ファイル: SQXmlFuncs.cpp プロジェクト: jack9267/vcmpserver
_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;
}
コード例 #7
0
ファイル: eLTE_Xml.cpp プロジェクト: eSDK/esdk_elte
/**************************************************************************
* 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;
}
コード例 #8
0
ファイル: CXMLNodeImpl.cpp プロジェクト: qaisjp/green-candy
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;
    }
}
コード例 #9
0
ファイル: AppManager.cpp プロジェクト: Kr0nZ/boxee
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");

  }

  tmp = BOXEE::BXUtils::IntToString(std::time(NULL));

  CAppDescriptor::AppDescriptorsMap::iterator it = installedAppsDesc.begin();
  for (; it != installedAppsDesc.end(); it++)
  {
    TiXmlElement * appElement = new TiXmlElement( "app" );
    pRootElement->LinkEndChild(appElement);

    TiXmlElement * appIdElement = new TiXmlElement( "id" );
    TiXmlText * appIdText = new TiXmlText(it->first);
    appIdElement->LinkEndChild( appIdText );
    appElement->LinkEndChild(appIdElement);

    TiXmlElement * timesOpenedElement = new TiXmlElement( "timesopened" );
    TiXmlText * timesOpenedText = new TiXmlText( "1" );
    timesOpenedElement->LinkEndChild( timesOpenedText );
    appElement->LinkEndChild(timesOpenedElement);

    TiXmlElement * lastOpenedElement = new TiXmlElement( "lastopeneddate" );
    TiXmlText * lastOpenedText = new TiXmlText(tmp.c_str());
    lastOpenedElement->LinkEndChild( lastOpenedText );
    appElement->LinkEndChild(lastOpenedElement);

    CLog::Log(LOGINFO, "adding %s to app.xml file\n", it->first.c_str());

  }

  xmlDoc.SaveFile();

  m_mapAppNameToStat.clear();
  pRootElement = xmlDoc.RootElement();
  pAppNode = pRootElement->FirstChild("app");

  CLog::Log(LOGDEBUG, "reading apps.xml file");
  // read the content of app.xml file
  while (pAppNode > 0)
  {
    pIdNode = pAppNode->FirstChild("id");
    currAppStr = pIdNode->FirstChild()->Value();
    pLastOpenedDateNode = pAppNode->FirstChild("lastopeneddate");
    pOpenedCntNode = pAppNode->FirstChild("timesopened");
    int lastOpenedTime = 1;
    int timesOpened = 1;
    if (pOpenedCntNode && pLastOpenedDateNode->FirstChild())
    {
      lastOpenedTime = BOXEE::BXUtils::StringToInt(pLastOpenedDateNode->FirstChild()->Value());
    }
    if (pOpenedCntNode && pOpenedCntNode->FirstChild())
    {
      timesOpened = BOXEE::BXUtils::StringToInt(pOpenedCntNode->FirstChild()->Value());
    }
    std::map<CStdString, int> statsMap;
    statsMap["lastopeneddate"] = lastOpenedTime;
    statsMap["timesopened"] = timesOpened;
    m_mapAppNameToStat[currAppStr] = statsMap;
    pAppNode = pAppNode->NextSiblingElement("app");
  }
}
コード例 #10
0
// Process a notify event callback.
void ResourceInstance::notifyEventCallback(const UtlString* dialogHandle,
                                           const UtlString* content)
{
   OsSysLog::add(FAC_RLS, PRI_DEBUG,
                 "ResourceInstance::notifyEventCallback mInstanceName = '%s', content = '%s'",
                 mInstanceName.data(), content->data());
   // Set to true if we find publishable data.
   bool publish = false;

   // Set the subscription state to "active".
   mSubscriptionState = "active";

   // Save the content as text for the RFC 4662 resource list events.
   mContent.remove(0);
   mContent.append(*content);
   mContentPresent = TRUE;

   // Dissect the XML for each dialog event and store it in a map
   // so we can construct BroadWorks-style resource list events
   // (which have to have full state).

   // Initialize Tiny XML document object.
   TiXmlDocument xmlDialogEvent;
   TiXmlNode* dialog_info_node;
   if (
       // Load the XML into it.
       xmlDialogEvent.Parse(mContent.data()) &&
       // Find the top element, which should be a <dialog-info>.
       (dialog_info_node = xmlDialogEvent.FirstChild("dialog-info")) != NULL &&
       dialog_info_node->Type() == TiXmlNode::ELEMENT)
   {
      // Check the state attribute.
      const char* p = dialog_info_node->ToElement()->Attribute("state");
      if (p && strcmp(p, "full") == 0)
      {
         // If the state is "full", terminate all non-terminated dialogs.  (XECS-1668)
         terminateXmlDialogs();
         publish = true;
         OsSysLog::add(FAC_RLS, PRI_DEBUG,
                       "ResourceInstance::notifyEventCallback all non-terminated dialogs");
      }

      // Find all the <dialog> elements.
      for (TiXmlNode* dialog_node = 0;
           (dialog_node = dialog_info_node->IterateChildren("dialog",
                                                            dialog_node));
         )
      {
         if (dialog_node->Type() == TiXmlNode::ELEMENT)
         {
            TiXmlElement* dialog_element = dialog_node->ToElement();

            // Determine if the <dialog> is a bogus report of a NAT Keepalive
            // OPTIONS message, as reported by Polycom SPIP firmware 3.1.2.
            // (XTRN-425)  If so, ignore it.

#ifdef NAT_KEEPALIVE_DETECT
            const char* call_id_attr = dialog_element->Attribute("call-id");
            // Reject <dialog>s on the narrowest grounds, that is, only if the
            // call-id attribute is present and contains NAT_KEEPALIVE_SIGNATURE.
            const bool ok =
               !(call_id_attr &&
                 strstr(call_id_attr,
                        NAT_KEEPALIVE_SIGNATURE) != NULL);
#else
            const bool ok = true;
#endif
            if (ok)
            {
               // Now that we've got a <dialog> element, edit it to fit
               // into a consolidated event notice.
               publish = true;

               // Prepend the resource instance name to the 'id'
               // attribute, so it is unique within the <resource>.
               UtlString id(mInstanceName);
               // mInstanceName is guaranteed to not contain ';', because
               // it is a dialog handle that we generate by concatenating
               // the Call-Id and tags using ',' as a separator.  And ';'
               // may not appear in Call-Ids or tags.
               id.append(";");
               id.append(dialog_element->Attribute("id"));
               dialog_element->SetAttribute("id", id.data());

               // Prepare the display name, so we can insert it easily
               // when we generate consolidated events.
               // Find or add the <local> element.
               TiXmlNode* local = dialog_element->FirstChild("local");
               if (!local)
               {
                  local = dialog_element->LinkEndChild(new TiXmlElement("local"));
               }
               // Find or add the <local><identity> element.
               TiXmlNode* identity = local->FirstChild("identity");
               if (!identity)
               {
                  identity =
                     local->LinkEndChild(new TiXmlElement("identity"));
               }
               // Clear the display attribute.
               identity->ToElement()->SetAttribute("display", "");

               // Put the resource URI as the content of the
               // <local><identity> element.
               // First, remove all text children.
               TiXmlNode* child;
               for (TiXmlNode* prev_child = 0;
                    (child = identity->IterateChildren(prev_child));
                  )
               {
                  if (child->Type() == TiXmlNode::TEXT)
                  {
                     identity->RemoveChild(child);
                     // Leave prev_child unchanged.
                  }
                  else
                  {
                     prev_child = child;
                  }
               }
               // Insert a text child containing the URI.
               identity->LinkEndChild(new TiXmlText(getResourceCached()->
                                                    getUri()->data()));

               // Now that we have the XML all nice and pretty, store a copy of
               // it in mXmlDialogs.
               // Clone the XML and create a UtlVoidPtr to wrap it.
               TiXmlElement* alloc_xml = dialog_element->Clone()->ToElement();

               // Look for an earlier version of this dialog in the hash map.
               UtlVoidPtr* p = dynamic_cast <UtlVoidPtr*> (mXmlDialogs.findValue(&id));
               if (p)
               {
                  // Replace the old XML with new XML.
                  delete static_cast <TiXmlElement*> (p->getValue());
                  p->setValue(alloc_xml);
                  OsSysLog::add(FAC_RLS, PRI_DEBUG,
                                "ResourceInstance::notifyEventCallback replaced dialog with id '%s'",
                                id.data());
               }
               else
               {
                  // Check that we don't have too many dialogs.
                  if (mXmlDialogs.entries() <
                      getResourceListServer()->getMaxDialogsInResInst())
                  {
                     mXmlDialogs.insertKeyAndValue(new UtlString(id),
                                                   new UtlVoidPtr(alloc_xml));
                     OsSysLog::add(FAC_RLS, PRI_DEBUG,
                                   "ResourceInstance::notifyEventCallback added dialog with id '%s'",
                                   id.data());
                  }
                  else
                  {
                     // Free alloc_xml, because we aren't saving a pointer to it.
                     delete alloc_xml;
                     OsSysLog::add(FAC_RLS, PRI_ERR,
                                   "ResourceInstance::notifyEventCallback cannot add dialog with id '%s', already %zu in ResourceInstance '%s'",                                id.data(), mXmlDialogs.entries(),
                                   mInstanceName.data());
                  }
               }
            }
            else
            {
               // The <dialog> was rejected because it appears to report
               // a NAT Maintainer OPTIONS message.
               // We log this at DEBUG level because if these appear,
               // there is likely to be one every 20 seconds.
               OsSysLog::add(FAC_RLS, PRI_DEBUG,
                             "ResourceInstance::notifyEventCallback "
                             "ignored <dialog> reporting a NAT Keepalive message "
                             "in subscription dialog handle '%s' - "
                             "see XTRN-426",
                             mInstanceName.data());
            }
         }
      }
   }
   else
   {
      // Report error parsing XML.
      OsSysLog::add(FAC_RLS, PRI_ERR,
                    "ResourceInstance::notifyEventCallback "
                    "Dialog event from '%s' not parsable.",
                    getResourceCached()->getUri()->data());
      OsSysLog::add(FAC_RLS, PRI_INFO,
                    "ResourceInstance::notifyEventCallback "
                    "Dialog event content is '%s'",
                    content->data());
      // Throw away the content, since we cannot generate matching
      // consolidated content.
      mContentPresent = FALSE;
      mContent.remove(0);
      destroyXmlDialogs();
   }

   // Get the change published, if we found <dialog> that was not incorrect.
   if (publish)
   {
      getResourceCached()->setToBePublished(FALSE, getResourceCached()->getUri());
   }
}
コード例 #11
0
//删除
void CTestScript::OnDelScript()
{
    char strfile[128] = "TestCase\\TestCases.xml";
    TiXmlDocument pDoc(strfile);
    ///载入配置文件
    if(!pDoc.LoadFile())
    {
        PutDebugString("装载配置文件<TestCases.xml>出错!");
        return;
    }
    else
    {
        HTREEITEM mSelItem = m_treeTestCase.GetSelectedItem();
        if( mSelItem == m_treeTestCase.GetRootItem())
        {
            AfxMessageBox("设定为:不能删除根节点下的所有磁盘文件",MB_OK,NULL);
            return;
        }
        long lSelID = (long)m_treeTestCase.GetItemData(mSelItem);
        itTestCase pCase = m_TestCases.find(lSelID);

        CString strSelItemText = m_treeTestCase.GetItemText(mSelItem);
        //如果不是某个lua文件
        if(strSelItemText.Right(4) != ".lua")
        {
            //分类节点
            TiXmlElement* rootElem = pDoc.RootElement();
            TiXmlNode	* rootNode = pDoc.FirstChild(rootElem->Value());

            TiXmlElement* caseElem = rootElem->FirstChildElement();
            TiXmlNode	* caseNode = rootElem->FirstChild(caseElem->Value());
            for( ; caseElem != NULL; caseElem = caseElem->NextSiblingElement(),
                    caseNode = caseNode->NextSibling()	)
            {
                if( caseElem->Attribute("name") == strSelItemText )
                {
                    rootNode->RemoveChild(caseElem);
                    break;
                }
            }
            //删除磁盘文件
            DeleteFile(strSelItemText);
            //删除控件
            m_treeTestCase.DeleteItem(mSelItem);
            pDoc.SaveFile(strfile);
            //
            m_TestCases.erase(pCase);
            //显示
            char strText[256]="";
            sprintf(strText,"所有案例(%d)",m_TestCases.size());
            m_treeTestCase.SetItemText(m_treeTestCase.GetRootItem(),strText);
            return;
        }
        //是lua文件
        else
        {
            //删除xml配置文件
            TiXmlElement* RootEle = pDoc.RootElement();									//根
            TiXmlNode* pRootNode = pDoc.FirstChild(RootEle->Value());

            TiXmlElement* caseElem = RootEle->FirstChildElement();
            TiXmlNode* caseNode = RootEle->FirstChild(caseElem->Value());

            bool bDel = false;
            for(; caseElem != NULL; caseElem = caseElem->NextSiblingElement())
            {
                TiXmlElement* scriptElem = caseElem->FirstChildElement();
                TiXmlNode* scriptNode = caseElem->FirstChild(scriptElem->Value());
                for(; scriptElem!=NULL; scriptElem = scriptElem->NextSiblingElement(),
                        scriptNode = scriptNode->NextSibling()  )
                {
                    if(scriptElem->Attribute("scriptname") == strSelItemText)
                    {
                        caseElem->RemoveChild(scriptNode);
                        bDel = true;
                        break;
                    }
                }
                if( bDel )	break;
            }
            //删除磁盘文件
            DeleteFile(strSelItemText);
            //删除控件
            m_treeTestCase.DeleteItem(mSelItem);
            //显示
            char strText[256]="";
            sprintf(strText,"所有案例(%d)",m_TestCases.size());
            m_treeTestCase.SetItemText(m_treeTestCase.GetRootItem(),strText);
        }
        pDoc.SaveFile(strfile);
        return;
    }
}
コード例 #12
0
ファイル: HsMiscellany.cpp プロジェクト: hefen1/XCaimi
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();
	}

}