This C/C++ source code performs the following steps:
pXMLDom
) and sets it to synchronous mode.pXMLDom.
loadXML
method on pXMLDom
, specifying the XML data as the following string:
<r>\n<t>top</t>\n<b>bottom</b>\n</r>
save
method on pXMLDom
to serialize the DOM content to a file (myData.xml).C/C++ Source File (saveDOMsmart.cpp)
#include <stdio.h> #import <msxml5.dll> using namespace MSXML2; int main(int argc, char* argv[]) { IXMLDOMDocument3Ptr pXMLDom; HRESULT hr; CoInitialize(NULL); hr= pXMLDom.CreateInstance(__uuidof(DOMDocument50)); if (FAILED(hr)) { printf("Failed to instantiate an XML DOM.\n"); return -1; } pXMLDom->async = VARIANT_FALSE; // The default is true. if(pXMLDom->loadXML( "<r>\n<t>top</t>\n<b>bottom</b>\n</r>")!=VARIANT_TRUE) { printf("Failed to loadXML:\n%s\n", (LPCSTR)pXMLDom->parseError->Getreason()); return -1; } else printf("XML DOM loaded from app:\n%s\n", (LPCSTR)pXMLDom->xml); hr = pXMLDom->save("myData.xml"); if (FAILED(hr)) { printf("Failed to save DOM to myStocks.xml.\n"); return -1; } else printf("XML DOM saved to myData.xml.\n"); pXMLDom.Release(); CoUninitialize(); return 0; }
To add the saveDOMsmart source code to the project
Next, build and run the saveDOMsmart project. The result should be the output shown in the following topic.