bool CHelpDB::GetItemElement(CTSTRING& _sAlias, MSXML::IXMLDOMElementPtr& Out, bool bCreate) { bool r = false; TSTRING sXPath; MSXML::IXMLDOMNodePtr Node; TSTRING sAlias; { TCHAR* tsz = _tcsdup(_sAlias.c_str()); _tcsupr(tsz); sAlias = tsz; SAFE_FREE(tsz); } // this will look something like MSG[@ALIAS="hithere"] sprintf(sXPath, TAG_MSG _T("[@") TAG_ALIAS _T("=\"%s\"]"), sAlias.c_str()); try { Node = m_root->selectSingleNode(_bstr_t(sXPath.c_str())); if((Node == NULL) && (bCreate == true)) { MSXML::IXMLDOMElementPtr NewEl; MSXML::IXMLDOMNodePtr NewNode; NewEl = m_doc->createElement("MSG"); NewEl.QueryInterface(__uuidof(MSXML::IXMLDOMNode), &NewNode); Node = m_root->appendChild(NewNode); } if(Node != NULL) { Node.QueryInterface(__uuidof(MSXML::IXMLDOMElement), &Out); r = true; } } catch(_com_error& e) { sprintf(m_err, _T("COM Error: %08x"), e.Error()); g_pLog->msg(_T("CHelpDB::GetItemElement(%s)"), _sAlias.c_str()); } return r; }
bool CHelpDB::DeleteItem(CTSTRING& sAlias) { MSXML::IXMLDOMElementPtr El; MSXML::IXMLDOMNodePtr Node; MSXML::IXMLDOMNodePtr Parent; bool r = false; if(m_doc == 0) return false; if(GetItemElement(sAlias, El, false)) { El.QueryInterface(__uuidof(MSXML::IXMLDOMNode), &Node); Parent = Node->GetparentNode(); Parent->removeChild(Node); r = true; } return r; }