https://msdn.microsoft.com/en-us/library/ms757021 (v=versus 85). Aspx
# include & lt; stdio.h>
# include & lt; Tchar. H>
# import & lt; Msxml6. Dll>
Void dynamDOMsmart ()
{
MSXML2: : IXMLDOMDocumentPtr pXMLDom;
Retrieves the hr=pXMLDom. CreateInstance (__uuidof (MSXML2: : DOMDocument60), NULL, CLSCTX_INPROC_SERVER);
If (FAILED (hr))
{
Printf (" Failed to instantiate an XML DOM. \ n ");
return;
}
Try
{
PXMLDom - & gt; Async=VARIANT_FALSE;
PXMLDom - & gt; ValidateOnParse=VARIANT_FALSE;
PXMLDom - & gt; ResolveExternals=VARIANT_FALSE;
PXMLDom - & gt; PreserveWhiteSpace=VARIANT_TRUE;
//Create a processing instruction targeted for XML.
MSXML2: : IXMLDOMProcessingInstructionPtr PI=pXMLDom - & gt; CreateProcessingInstruction (L "XML," L "version='1.0'");
PXMLDom - & gt; The appendChild (PI);
//Create a comment for the document.
MSXML2: : IXMLDOMCommentPtr PC=pXMLDom - & gt; CreateComment (L "sample XML file created using the XML DOM object.");
PXMLDom - & gt; The appendChild (PC);
//Create the root element (i.e. for the documentElement).
MSXML2: : IXMLDOMElementPtr pRoot=pXMLDom - & gt; The createElement method (L "root");
//Create a "created" attribute for the root element and
//assign the "using dom" character data as the attribute value.
MSXML2: : IXMLDOMAttributePtr pa=pXMLDom - & gt; The createAttribute (L "created");
Pa - & gt; Value=https://bbs.csdn.net/topics/L "using dom";
PRoot - & gt; The setAttributeNode (pa);
//Next, we will create and add more nodes to the root element
//we 've just created.
//Create an element to hold the text content.
MSXML2: : IXMLDOMElementPtr=pXMLDom - PE & gt; The createElement method (L "node1");
//Add newline + TAB for indentation.
PRoot - & gt; The appendChild (pXMLDom - & gt; CreateTextNode (L "\ n \ t"));
PE - & gt; Text=L "some character data";
PRoot - & gt; The appendChild (PE);
//Create an element to hold a CDATA section.
PE=pXMLDom - & gt; The createElement method (L "2");
//Add newline + TAB for indentation.
PRoot - & gt; The appendChild (pXMLDom - & gt; CreateTextNode (L "\ n \ t"));
PE - & gt; The appendChild (pXMLDom - & gt; CreateCDATASection (L "& lt; Some mark - up text>" ));
PRoot - & gt; The appendChild (PE);
//Create an element to hold three empty subelements.
PE=pXMLDom - & gt; The createElement method (L "node3");
//Add newline + TAB for indentation.
PRoot - & gt; The appendChild (pXMLDom - & gt; CreateTextNode (L "\ n \ t"));
MSXML2: : IXMLDOMDocumentFragmentPtr PDF=pXMLDom - & gt; CreateDocumentFragment ();
PDF - & gt; The appendChild (pXMLDom - & gt; The createTextNode (L "\ t \ n \ t"));
PDF - & gt; The appendChild (pXMLDom - & gt; The createElement method (L "subNode1"));
PDF - & gt; The appendChild (pXMLDom - & gt; The createTextNode (L "\ t \ n \ t"));
PDF - & gt; The appendChild (pXMLDom - & gt; The createElement method (L "subNode2"));
PDF - & gt; The appendChild (pXMLDom - & gt; The createTextNode (L "\ t \ n \ t"));
PDF - & gt; The appendChild (pXMLDom - & gt; The createElement method (L "subNode3"));
PDF - & gt; The appendChild (pXMLDom - & gt; CreateTextNode (L "\ n \ t"));
PE - & gt; The appendChild (PDF).
PRoot - & gt; The appendChild (PE);
PRoot - & gt; The appendChild (pXMLDom - & gt; The createTextNode (L "\ n"));
//Add the root element to the DOM instance.
PXMLDom - & gt; The appendChild (pRoot);
Printf (" Dynamically created a DOM: \ n \ n % s ", static_cast & lt; PCSTR> (pXMLDom - & gt; XML));
Hr=pXMLDom - & gt; Save (L "dynaDOMsmart. XML");
If (SUCCEEDED (hr))
{
Printf (" XML DOM saved to dynaDOMsmart. \ n ");
}
The else
{
Printf (" Failed to save the DOM to dynaDomsmart. XML \ n ");
}
}
The catch (_com_error errorObject)
{
Printf (" exception is thrown, the HRESULT: 0 x % x "08, errorObject. Error ());
}
}
Int _tmain (int arg c, _TCHAR * argv [])
{
Retrieves the hr=CoInitialize (NULL);
If (SUCCEEDED (hr))
{
DynamDOMsmart ();
CoUninitialize ();
}
return 0;
}
Copy the VS2015, results like pRoot - & gt; The appendChild have wavy lines, such as tip has no members
Compiler can run through, no problem, but there are activities (error). But in VS2008 is fine. Is there any way to eliminate the wavy lines, too ugly
CodePudding user response:
VS2013 under no wavy linesYou can try
# import & lt; Msxml6. Dll>
# include "the Debug/msxml6 TLH"
If it is in Release mode
# import & lt; Msxml6. Dll>
# include "Release/msxml6 TLH." "
CodePudding user response: