本文整理汇总了C++中IXMLDOMDocument::createDocumentFragment方法的典型用法代码示例。如果您正苦于以下问题:C++ IXMLDOMDocument::createDocumentFragment方法的具体用法?C++ IXMLDOMDocument::createDocumentFragment怎么用?C++ IXMLDOMDocument::createDocumentFragment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IXMLDOMDocument
的用法示例。
在下文中一共展示了IXMLDOMDocument::createDocumentFragment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dynamDOM
void dynamDOM()
{
HRESULT hr = S_OK;
IXMLDOMDocument *pXMLDom = NULL;
IXMLDOMElement *pRoot = NULL;
IXMLDOMElement *pNode = NULL;
IXMLDOMElement *pSubNode = NULL;
IXMLDOMDocumentFragment *pDF = NULL;
BSTR bstrXML = NULL;
VARIANT varFileName;
VariantInit(&varFileName);
CHK_HR(CreateAndInitDOM(&pXMLDom));
// Create a processing instruction element.
CHK_HR(CreateAndAddPINode(pXMLDom, L"xml", L"version='1.0'"));
// Create a comment element.
CHK_HR(CreateAndAddCommentNode(pXMLDom, L"sample xml file created using XML DOM object."));
// Create the root element.
CHK_HR(CreateElement(pXMLDom, L"root", &pRoot));
// Create an attribute for the <root> element, with name "created" and value "using dom".
CHK_HR(CreateAndAddAttributeNode(pXMLDom, L"created", L"using dom", pRoot));
// Next, we will create and add three nodes to the <root> element.
// Create a <node1> to hold text content.
CHK_HR(CreateAndAddElementNode(pXMLDom, L"node1", L"\n\t", pRoot, &pNode));
CHK_HR(CreateAndAddTextNode(pXMLDom, L"some character data", pNode));
SAFE_RELEASE(pNode);
// Create a <node2> to hold a CDATA section.
CHK_HR(CreateAndAddElementNode(pXMLDom, L"node2", L"\n\t", pRoot, &pNode));
CHK_HR(CreateAndAddCDATANode(pXMLDom, L"<some mark-up text>", pNode));
SAFE_RELEASE(pNode);
// Create <node3> to hold a doc fragment with three sub-elements.
CHK_HR(CreateAndAddElementNode(pXMLDom, L"node3", L"\n\t", pRoot, &pNode));
// Create a document fragment to hold three sub-elements.
CHK_HR(pXMLDom->createDocumentFragment(&pDF));
// Create 3 subnodes.
CHK_HR(CreateAndAddElementNode(pXMLDom, L"subNode1", L"\n\t\t", pDF));
CHK_HR(CreateAndAddElementNode(pXMLDom, L"subNode2", L"\n\t\t", pDF));
CHK_HR(CreateAndAddElementNode(pXMLDom, L"subNode3", L"\n\t\t", pDF));
CHK_HR(CreateAndAddTextNode(pXMLDom, L"\n\t", pDF));
// Append pDF to <node3>.
CHK_HR(AppendChildToParent(pDF, pNode));
SAFE_RELEASE(pNode);
// Add NEWLINE for identation before </root>.
CHK_HR(CreateAndAddTextNode(pXMLDom, L"\n", pRoot));
// add <root> to document
CHK_HR(AppendChildToParent(pRoot, pXMLDom));
CHK_HR(pXMLDom->get_xml(&bstrXML));
wprintf(L"Dynamically created DOM:\n%s\n", bstrXML);
CHK_HR(VariantFromString(L"dynamDOM.xml", varFileName));
CHK_HR(pXMLDom->save(varFileName));
wprintf(L"DOM saved to dynamDOM.xml\n");
CleanUp:
SAFE_RELEASE(pXMLDom);
SAFE_RELEASE(pRoot);
SAFE_RELEASE(pNode);
SAFE_RELEASE(pDF);
SAFE_RELEASE(pSubNode);
SysFreeString(bstrXML);
VariantClear(&varFileName);
}