本文整理汇总了C++中IXMLDOMNode::appendChild方法的典型用法代码示例。如果您正苦于以下问题:C++ IXMLDOMNode::appendChild方法的具体用法?C++ IXMLDOMNode::appendChild怎么用?C++ IXMLDOMNode::appendChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IXMLDOMNode
的用法示例。
在下文中一共展示了IXMLDOMNode::appendChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WcaFinalize
//.........这里部分代码省略.........
{
case xaWriteValue:
if (pwzName && *pwzName)
{
// We're setting an attribute
hr = XmlSetAttribute(pixn, pwzName, pwzValue);
ExitOnFailure2(hr, "failed to set attribute: %ls to value %ls", pwzName, pwzValue);
}
else
{
// We're setting the text of the node
hr = XmlSetText(pixn, pwzValue);
ExitOnFailure2(hr, "failed to set text to: %ls for element %ls. Make sure that XPath points to an element.", pwzValue, pwzElementPath);
}
break;
case xaWriteDocument:
if (NULL != pwzVerifyPath && 0 != pwzVerifyPath[0])
{
hr = XmlSelectSingleNode(pixn, pwzVerifyPath, &pixnVerify);
if (S_OK == hr)
{
// We found the verify path which means we have no further work to do
continue;
}
ExitOnFailure1(hr, "failed to query verify path: %ls", pwzVerifyPath);
}
hr = XmlLoadDocumentEx(pwzValue, XML_LOAD_PRESERVE_WHITESPACE, &pixdNew);
ExitOnFailure(hr, "Failed to load value as document.");
hr = pixdNew->get_documentElement(&pixeNew);
ExitOnFailure(hr, "Failed to get document element.");
hr = pixn->appendChild(pixeNew, NULL);
ExitOnFailure(hr, "Failed to append document element on to parent element.");
ReleaseNullObject(pixeNew);
ReleaseNullObject(pixdNew);
break;
case xaCreateElement:
if (NULL != pwzVerifyPath && 0 != pwzVerifyPath[0])
{
hr = XmlSelectSingleNode(pixn, pwzVerifyPath, &pixnVerify);
if (S_OK == hr)
{
// We found the verify path which means we have no further work to do
continue;
}
ExitOnFailure1(hr, "failed to query verify path: %ls", pwzVerifyPath);
}
hr = XmlCreateChild(pixn, pwzName, &pixnNewNode);
ExitOnFailure1(hr, "failed to create child element: %ls", pwzName);
if (pwzValue && *pwzValue)
{
hr = XmlSetText(pixnNewNode, pwzValue);
ExitOnFailure2(hr, "failed to set text to: %ls for node: %ls", pwzValue, pwzName);
}
while (cAdditionalChanges > 0)
{
hr = WcaReadStringFromCaData(&pwz, &pwzName);
ExitOnFailure(hr, "failed to process CustomActionData");
hr = WcaReadStringFromCaData(&pwz, &pwzValue);
示例2: Save
//.........这里部分代码省略.........
// Теперь собственно значение
if (nType != REG_MULTI_SZ)
{
_ASSERTE(bsValue != NULL);
SetAttr(pChild, pAttrs, L"data", bsValue);
::SysFreeString(bsValue); bsValue = NULL;
}
else // Тут нужно формировать список элементов <list>
{
VARIANT_BOOL bHasChild = VARIANT_FALSE;
DOMNodeType nodeType = NODE_INVALID;
// Если ранее был параметр "data" - удалить его из списка атрибутов
hr = pAttrs->getNamedItem(L"data", &pNode);
if (SUCCEEDED(hr) && pNode)
{
hr = pChild->removeChild(pNode, &pNodeRmv);
pNode->Release(); pNode = NULL;
if (pNodeRmv) { pNodeRmv->Release(); pNodeRmv = NULL; }
}
//TODO: может оставить перевод строки?
// Сначала почистим
#ifdef _DEBUG
hr = pChild->get_nodeType(&nodeType);
#endif
hr = pChild->hasChildNodes(&bHasChild);
if (bHasChild)
{
while((hr = pChild->get_firstChild(&pNode)) == S_OK && pNode)
{
hr = pNode->get_nodeType(&nodeType);
#ifdef _DEBUG
BSTR bsDebug = NULL;
pNode->get_text(&bsDebug);
if (bsDebug) ::SysFreeString(bsDebug); bsDebug = NULL;
#endif
hr = pChild->removeChild(pNode, &pNodeRmv);
if (pNodeRmv) { pNodeRmv->Release(); pNodeRmv = NULL; }
pNode->Release(); pNode = NULL;
}
}
// Теперь - добавляем список
wchar_t* psz = (wchar_t*)value;
BSTR bsNodeType = ::SysAllocString(L"line");
VARIANT vtType; vtType.vt = VT_I4; vtType.lVal = NODE_ELEMENT;
long nAllLen = nSize/2; // длина в wchar_t
long nLen = 0;
while(psz && *psz && nAllLen > 0)
{
hr = mp_File->createNode(vtType, bsNodeType, L"", &pNode);
if (FAILED(hr) || !pNode)
break;
if (!SetAttr(pNode, L"data", psz))
break;
hr = pChild->appendChild(pNode, &pNodeRmv);
pNode->Release(); pNode = NULL;
if (pNodeRmv) { pNodeRmv->Release(); pNodeRmv = NULL; }
if (FAILED(hr))
break;
nLen = _tcslen(psz)+1;
psz += nLen;
nAllLen -= nLen;
}
_ASSERTE(nAllLen <= 1);
}
mb_Modified = true;
wrap:
if (pIXMLDOMAttribute) { pIXMLDOMAttribute->Release(); pIXMLDOMAttribute = NULL; }
if (pNode) { pNode->Release(); pNode = NULL; }
if (pNodeRmv) { pNodeRmv->Release(); pNodeRmv = NULL; }
if (pChild) { pChild->Release(); pChild = NULL; }
if (pAttrs) { pAttrs->Release(); pAttrs = NULL; }
if (bsValue) { ::SysFreeString(bsValue); bsValue = NULL; }
if (bsType) { ::SysFreeString(bsType); bsType = NULL; }
}