This is mine XML parsing code
try
{
MSXML2::IXMLDOMDocumentPtr docPtr; MSXML2::IXMLDOMNodeListPtr NodeListPtr; MSXML2::IXMLDOMNodePtr DOMNodePtr;
MSXML2::IXMLDOMNode *pIDOMNode = NULL; MSXML2::IXMLDOMNode *pIParentNode = NULL; MSXML2::IXMLDOMNode *pIAttrNode = NULL; MSXML2::IXMLDOMNamedNodeMapPtr DOMNamedNodeMapPtr; MSXML2::IXMLDOMNodeList *childList=NULL; BSTR strFindText = L" ";
BSTR bstrItemText,bstrItemNode, bstrItemParent,bstrNodeType;
BSTR bstrAttrName, bstrAttrType, bstrAttrText;
HRESULT hResult;
int i = 0; int n = 0;
CoInitialize(NULL);
docPtr.CreateInstance(__uuidof(DOMDocument30));
_variant_t varXml(Xmlpath); _variant_t varResult((bool)TRUE);
varResult = docPtr->load(varXml);
if ((bool)varResult == FALSE)
{
wLog->WriteErrorLog("failed to load XML file. Check the file name\n");
printf("failed to load XML file. Check the file name\n");
return 1;
}
NodeListPtr = docPtr->getElementsByTagName(strFindText);
docPtr->documentElement->get_nodeName(&bstrItemText);
printf("\nRoot: %ls\n", bstrItemText);
for(i = 0; i < (NodeListPtr->length); i++)
{
if (pIDOMNode) pIDOMNode->Release();
NodeListPtr->get_item(i, &pIDOMNode);
if(pIDOMNode )
{
pIDOMNode->get_nodeTypeString(&bstrNodeType);
BSTR temp = L"element";
if (lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)temp)==0)
{
n++; printf("\n\n%d\n", n); printf("Type: %ls\n", bstrNodeType);
pIDOMNode->get_nodeName(&bstrItemNode);
printf("Node: %ls\n", bstrItemNode);
pIDOMNode->get_text(&bstrItemText);
printf("Text: %ls\n", bstrItemText);
int j = 0; long length;
DOMNamedNodeMapPtr = pIDOMNode->attributes;
}
}
}
pIDOMNode->Release();
pIDOMNode = NULL;
pIParentNode->Release();
pIParentNode = NULL;
}
catch(...)
{
wLog->WriteErrorLog("Exception occurred while parsing XML\n");
}
CoUninitialize();
wLog->WriteDebugLog("Ends GetMachineList\n");
return 0;
}
This is mine XML
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">="1.0"="UTF-8"<DataCaptureSettings><ModuleSettings><capture_local_dir>c:\</capture_local_dir><capture_log_dir>c:\log</capture_log_dir><capture_log_level>debug</capture_log_level><capture_request_interval>2</capture_request_interval><capture_connection_interval>2</capture_connection_interval><smtp_server_name>n1</smtp_server_name><smtp_server_port>80</smtp_server_port></ModuleSettings><Machines><Machine><MachineId>0022</MachineId><AccountId>1</AccountId><location_code>LOC_100</location_code><Make>Nipro</Make><Model>Model1</Model><SerialNumber>126649E</SerialNumber><IpAddress>10.10.10.10</IpAddress><Port>80</Port></Machine><Machine><MachineId>3000</MachineId><AccountId>1</AccountId><location_code>LOC_100</location_code><Make>Make3</Make><Model>Model3</Model><SerialNumber>SN3</SerialNumber><IpAddress>30.30.30.30</IpAddress><Port>80</Port></Machine></Machines></DataCaptureSettings></string>
When i run the code my output shown is as below
Root: string
1
Type: element
Node: string
Text: <?xml version="1.0" encoding="UTF-8"?><DataCaptureSettings><ModuleSettings
><capture_local_dir>c:\</capture_local_dir><capture_log_dir>c:\log</capture_log_
dir><capture_log_level>debug</capture_log_level><capture_request_interval>2</cap
ture_request_interval><capture_connection_interval>2</capture_connection_interva
l><smtp_server_name>n1</smtp_server_name><smtp_server_port>80</smtp_server_port>
</ModuleSettings><Machines><Machine><MachineId>0022</MachineId><AccountId>1</Acc
ountId><location_code>LOC_100</location_code><Make>Nipro</Make><Model>Model1</Mo
del><SerialNumber>126649E</SerialNumber><IpAddress>10.10.10.10</IpAddress><Port>
80</Port></Machine><Machine><MachineId>3000</MachineId><AccountId>1</AccountId><
location_code>LOC_100</location_code><Make>Make3</Make><Model>Model3</Model><Ser
ialNumber>SN3</SerialNumber><IpAddress>30.30.30.30</IpAddress><Port>80</Port></M
achine></Machines></DataCaptureSettings>
And the code breaks at "pIParentNode->Release();"
Can you please guide why is it so?