i have a global structure like this :-
typedef struct MachineList
{
BSTR AccountId;
BSTR MachineId;
BSTR Make;
char* Make1;
BSTR Model;
char* Model1;
BSTR SerialNumber;
BSTR IpAddress1;
char* IpAddress;
BSTR Port1;
int Port;
BSTR LocationCode;
SOCKET Sock;
BSTR Status;
} MACHINELIST,*PMACHINELIST;
int MachineCount=-1;
i have an xml parser like this :-
in the start of this file (which contain parse function) i added
these code
vector<struct MACHINELIST > SS;
now i get the error
error C2371: 'MACHINELIST' : redefinition; different basic types
error C2512: 'MACHINELIST' : no appropriate default constructor available
void parse()
{
{
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);
PMACHINELIST MachineList;
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);
if(0== wcscmp(bstrItemNode, L"ModuleSettings"))
{
isModuleSettings=TRUE;
printf("");
}
printf("Node: %ls\n", bstrItemNode);
if(0== wcscmp(bstrItemNode, L"Machine"))
{
count++;
isMachineList=TRUE;
MachineList=new MACHINELIST;
MachineCount++;
}
if(0== wcscmp(bstrItemNode, L"/Machine"))
{
printf("detected");
}
pIDOMNode->get_text(&bstrItemText);
printf("Text: %ls\n", bstrItemText);
if(isModuleSettings) {
if(0== wcscmp(bstrItemNode, L"capture_local_dir"))
{
CapturelocalDir=bstrItemText;
printf("CapturelocalDir is %ls\n",CapturelocalDir);
}
if(0== wcscmp(bstrItemNode, L"capture_log_dir"))
{
CapturelogDir=bstrItemText;
printf("CapturelogDir is %ls\n",CapturelogDir);
}
if(0== wcscmp(bstrItemNode, L"capture_log_level"))
{
CapturelogLevel=bstrItemText;
printf("CapturelogLevel is %ls\n",CapturelogLevel);
}
if(0== wcscmp(bstrItemNode, L"capture_request_interval"))
{
CapturerequestInterval=bstrItemText;
printf("CapturerequestInterval is %ls\n",CapturerequestInterval);
}
if(0== wcscmp(bstrItemNode, L"capture_connection_interval"))
{
CaptureConnectionInterval=bstrItemText;
printf("CaptureConnectionInterval is %ls\n",CaptureConnectionInterval);
}
}
if(isMachineList)
{
if(0== wcscmp(bstrItemNode, L"MachineId"))
{
m_LocalStorage.machinelist[count].MachineId=bstrItemText;
MachineList->MachineId=bstrItemText;
}
if(0== wcscmp(bstrItemNode, L"IpAddress"))
{
m_LocalStorage.machinelist[count].IpAddress=bstrItemText;
m_LocalStorage.machinelist[count].IpAddress1=_com_util::ConvertBSTRToString(bstrItemText);
printf("ip address1 is %s\n",m_LocalStorage.machinelist[count].IpAddress1);
MachineList->IpAddress=_com_util::ConvertBSTRToString(bstrItemText);
}
if(0== wcscmp(bstrItemNode, L"Port"))
{
m_LocalStorage.machinelist[count].Port=bstrItemText;
m_LocalStorage.machinelist[count].Port1=_wtoi(bstrItemText);
MachineList->Port==_wtoi(bstrItemText);
printf("port1 is %d\n",m_LocalStorage.machinelist[count].Port1);
}
if(0== wcscmp(bstrItemNode, L"Model"))
{
m_LocalStorage.machinelist[count].Model=bstrItemText;
m_LocalStorage.machinelist[count].Model1=_com_util::ConvertBSTRToString(bstrItemText);
MachineList->Model1=_com_util::ConvertBSTRToString(bstrItemText);
}
if(0== wcscmp(bstrItemNode, L"Make"))
{
m_LocalStorage.machinelist[count].Make=bstrItemText;
m_LocalStorage.machinelist[count].Make1=_com_util::ConvertBSTRToString(bstrItemText);
MachineList->Make1=_com_util::ConvertBSTRToString(bstrItemText);
}
if(0== wcscmp(bstrItemNode, L"SerialNumber"))
{
m_LocalStorage.machinelist[count].SerialNumber=bstrItemText;
MachineList->SerialNumber=bstrItemText;
}
if(0== wcscmp(bstrItemNode, L"AccountId"))
{
m_LocalStorage.machinelist[count].AccountId=bstrItemText;
MachineList->AccountId=bstrItemText;
}
if(0== wcscmp(bstrItemNode, L"location_code"))
{
m_LocalStorage.machinelist[count].LocationCode=bstrItemText;
MachineList->LocationCode=bstrItemText;
}
}
int j = 0; long length;
DOMNamedNodeMapPtr = pIDOMNode->attributes;
hResult = DOMNamedNodeMapPtr->get_length(&length);
}
}
}
pIDOMNode->Release();
pIDOMNode = NULL;
pIParentNode = NULL;
}
catch(...)
{
wLog->WriteErrorLog("Exception occurred while parsing XML\n");
}
CoUninitialize();
}