HRESULT XMLHelper::CreateNode(MSXML2::IXMLDOMDocument2 *doc, MSXML2::IXMLDOMNode *parent, MSXML2::IXMLDOMNode **newNode, const TCHAR *name) { HRESULT hr = S_OK; bool release = false; if(!parent) { MSXML2::IXMLDOMElement *element = 0; hr = doc->get_documentElement(&element); if(hr == S_OK) { hr = element->QueryInterface(IID_IXMLDOMNode, reinterpret_cast<void **>(&parent)); } release = true; } if(hr == S_OK && parent) { hr = XMLHelper::CreateChild(parent, newNode, name); } if(release) { parent->Release(); parent = 0; } return hr; }
HRESULT XMLHelper::SetAttribute(MSXML2::IXMLDOMNode *pNode, const TCHAR *pAttr, const TCHAR *pVal) { HRESULT hr = S_FALSE; if(pNode && pAttr) { MSXML2::IXMLDOMElement *pElem = 0; hr = pNode->QueryInterface(IID_IXMLDOMElement, reinterpret_cast<void **>(&pElem)); if(hr == S_OK) { BSTR attr = SysAllocString(pAttr); VARIANTARG varg; VariantInit(&varg); varg.vt = VT_BSTR; varg.bstrVal = SysAllocString(pVal); hr = pElem->setAttribute(attr, varg); SysFreeString(attr); SysFreeString(varg.bstrVal); pElem->Release(); } } else { hr = E_INVALIDARG; } return hr; }
HRESULT XMLHelper::SetAttribute(MSXML2::IXMLDOMNode *pNode, const TCHAR *pAttr, int val) { MSXML2::IXMLDOMElement *pElem = 0; HRESULT hr = pNode->QueryInterface(IID_IXMLDOMElement, reinterpret_cast<void **>(&pElem)); if(hr == S_OK) { BSTR attr = SysAllocString(pAttr); VARIANTARG varg; VariantInit(&varg); varg.vt = VT_BSTR; StringBuffer sb; sb.appendInt(val); varg.bstrVal = SysAllocString(sb); hr = pElem->setAttribute(attr, varg); if(attr) { SysFreeString(attr); attr = 0; } if(varg.bstrVal) { SysFreeString(varg.bstrVal); varg.bstrVal = 0; } pElem->Release(); } return hr; }
void NXMLSettings::WriteStandardSetting(MSXML2::IXMLDOMDocument *pXMLDom, MSXML2::IXMLDOMElement *pGrandparentNode, const TCHAR *szElementName, const TCHAR *szAttributeName, const TCHAR *szAttributeValue) { MSXML2::IXMLDOMElement *pParentNode = NULL; MSXML2::IXMLDOMAttribute *pa = NULL; MSXML2::IXMLDOMAttribute *pa1 = NULL; BSTR bstr = NULL; BSTR bstr_wsntt = SysAllocString(L"\n\t\t"); VARIANT var; bstr = SysAllocString(szElementName); pXMLDom->createElement(bstr,&pParentNode); SysFreeString(bstr); bstr = NULL; NXMLSettings::AddWhiteSpaceToNode(pXMLDom,bstr_wsntt,pParentNode); /* This will form an attribute of the form: name="AttributeName" */ bstr = SysAllocString(L"name"); var = NXMLSettings::VariantString(szAttributeName); pXMLDom->createAttribute(bstr,&pa); pa->put_value(var); pParentNode->setAttributeNode(pa,&pa1); SysFreeString(bstr); bstr = NULL; if (pa1) { pa1->Release(); pa1 = NULL; } pa->Release(); pa = NULL; VariantClear(&var); bstr = SysAllocString(szAttributeValue); pParentNode->put_text(bstr); SysFreeString(bstr); bstr = NULL; SysFreeString(bstr_wsntt); bstr_wsntt = NULL; NXMLSettings::AppendChildToParent(pParentNode,pGrandparentNode); pParentNode->Release(); pParentNode = NULL; }
MSXML2::IXMLDOMNode * RecurrenceManager::GetRecurrencesNode() { MSXML2::IXMLDOMNode *pNode = 0; MSXML2::IXMLDOMElement *pRoot = 0; HRESULT hr = m_pXMLDoc->get_documentElement(&pRoot); BSTR xpath = SysAllocString(_T("//recurrences")); hr = m_pXMLDoc->selectSingleNode(xpath, reinterpret_cast<MSXML2::IXMLDOMNode **>(&pNode)); SysFreeString(xpath); if(hr == S_FALSE) { MSXML2::IXMLDOMNode *pRootNode = 0; pRoot->QueryInterface(IID_IXMLDOMNode, reinterpret_cast<void **>(&pRootNode)); XMLHelper::CreateChild(pRootNode, &pNode, _T("recurrences")); pRootNode->Release(); } pRoot->Release(); return pNode; }
HRESULT XMLHelper::SetAttributeId(MSXML2::IXMLDOMNode *node, const TCHAR *attribute, const Id &id) { MSXML2::IXMLDOMElement *pElem = 0; HRESULT hr = node->QueryInterface(IID_IXMLDOMElement, reinterpret_cast<void **>(&pElem)); if(hr == S_OK) { BSTR attr = SysAllocString(attribute); VARIANTARG varg; VariantInit(&varg); varg.vt = VT_BSTR; TCHAR buf[128] = {}; varg.bstrVal = SysAllocStringLen(id.AsHex(buf), 128); hr = pElem->setAttribute(attr, varg); SysFreeString(attr); SysFreeString(varg.bstrVal); pElem->Release(); } return hr; }
HRESULT XMLHelper::SetAttributeI64(MSXML2::IXMLDOMNode *pNode, const TCHAR *pAttr, unsigned __int64 val) { MSXML2::IXMLDOMElement *pElem = 0; HRESULT hr = pNode->QueryInterface(IID_IXMLDOMElement, reinterpret_cast<void **>(&pElem)); if(hr == S_OK) { BSTR attr = SysAllocString(pAttr); VARIANTARG varg; VariantInit(&varg); varg.vt = VT_BSTR; TCHAR buf[16]; varg.bstrVal = SysAllocStringLen(loadngo::data::ModelUtils::toHexString(val, buf), 16); hr = pElem->setAttribute(attr, varg); SysFreeString(attr); SysFreeString(varg.bstrVal); pElem->Release(); } return hr; }
LRESULT CSCProgramBlacklistDlg::OnApplyMessage(WPARAM wParam, LPARAM lParam) { MSXML2::IXMLDOMDocument *pXmlDoc = reinterpret_cast<MSXML2::IXMLDOMDocument *>(wParam); ASSERT(pXmlDoc); MSXML2::IXMLDOMElement *pRootElem = reinterpret_cast<MSXML2::IXMLDOMElement *>(lParam); ASSERT(pRootElem); MSXML2::IXMLDOMElementPtr ProccessList = pXmlDoc->createElement(_T("ProccessList")); pRootElem->appendChild(ProccessList); for (int i = 0; i < m_list.GetItemCount(); i++) { MSXML2::IXMLDOMElementPtr ProccessInfo = pXmlDoc->createElement(_T("ProccessInfo")); ProccessList->appendChild(ProccessInfo); ProccessInfo->setAttribute(_T("Name"), (LPCTSTR)m_list.GetItemText(i, 1)); ProccessInfo->setAttribute(_T("AddTime"), (LPCTSTR)m_list.GetItemText(i, 0)); ProccessInfo->setAttribute(_T("Description"), (LPCTSTR)m_list.GetItemText(i, 2)); } return TRUE; }