Problem in using MS XML DOM parser
Hi All,
In my application I have to read and append XML files. I am using MS
XML parser for that. I am using this code to traverse and print all
elements of xml file. But it is not giving desire output-
try
{
IXMLDOMDocumentPtr pXMLDom;
IXMLDOMElementPtr pElemTemp;
IXMLDOMNodePtr pNodeTemp;
// Create the COM DOM Document object
hResult = pXMLDom.CreateInstance(__uuidof(DOMDocument30));
if (FAILED(hResult))
{
cout<<"Failed to instantiate an XML DOM."<<endl;
return 1;
}
// Load the document synchronously
pXMLDom->async = VARIANT_FALSE;
// Load input document.
hResult = pXMLDom->load("mispridlog.xml");
// Check for load, parse, or validation errors
if( hResult != VARIANT_TRUE)
{
cout << "Parsing error" << endl;
return 1;
}
// Get document element
pElemTemp = pXMLDom->documentElement;
cout<< "Document Element name: "<< pElemTemp->nodeName<<endl;
// Walk through children of document element
// and process according to type
pNodeTemp = pElemTemp->firstChild;
while (pNodeTemp != NULL)
{
// Process node depending on type
cNodeType = pNodeTemp->nodeType;
switch (cNodeType)
{
case NODE_ELEMENT:
pElemTemp = (IXMLDOMElementPtr)pNodeTemp;
cout << "Element name: "
<< pElemTemp->nodeName << endl;
default:
break;
}
pNodeTemp = pNodeTemp->nextSibling;
}
For XML File-
<?xml version="1.0"?>
<buildinfo version="1.0"
buildkey="{7e61c930-66f3-48f1-b894-6a7e7bdc8e39}" rid="521">
<terms>
<termsinfo langterms="jp_terms_T12MJP" default="1" toadd="12" dm="2"
trial="0" lang="jp" affid="446-5" domain="jp.mcafee.com"
terms="T12MJP"/>
</terms>
<misprid>
<range min="1" max="10000" />
<ridbuilds>
<ridbuild rid="521" description="dgf fjdf dfdfd" datecreated="20060727"
datemodified="20060727"/>
<ridbuild rid="522" description="dgf fjdf dfdfd" datecreated="20060727"
datemodified="20060801"/>
</ridbuilds>
</misprid>
</buildinfo>
Output is-
Document Element name: buildinfo
Element name: terms
Element name: misprid
It is not considering 'ridbuilds' and 'ridbuild' as a element of file.
Could anyne tell me why?
Please tell me also how can I append XML file using MSXML parser.
Regards,
Rachit