I want to retrive value from XML which data in CDATA form.But I read XML using ReadFile function(this function is mandatory to read file)I cant use any other option to read XML(no DOM and SAX).Its requirement to read xml using READFile only.
once its read and get full xml in form of string and get value of tag which values are in CDATA.
Below is the XML:
<namespace>
<ns1>
<ns1name><![CDATA[MyData1</ns1name>
<class>
<cs1>
<cs1name><![CDATA[ComputerSystem</cs1name>
<property><![CDATA[DomainName@@SystemInfo@@IPAddress@MacAddress
</property>
</cs1>
</class>
</ns1>
<ns2>
<ns2name><![CDATA[MyData2</ns2name>
<class>
<cs1>
<cs1name><![CDATA[OtherDetails</cs1name>
<property><![CDATA[Caption@#@Description@#@ElementName@#@InstallDate</property>
</cs1>
</class>
</ns2>
</namespace>
output:
Count no of child in XML??
CDATA value inside tags.
What I have tried:
#include "stdafx.h"
#include<windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
#include<string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
wchar_t AppPath[MAX_PATH] = { 0 };
wchar_t XMLfilePath[MAX_PATH] = { 0 };
wchar_t *pwszFindChar = NULL;
GetModuleFileName(NULL,AppPath, MAX_PATH);
pwszFindChar = wcsrchr(AppPath, L'\\');
if (NULL == pwszFindChar)
{
return 0;
}
*pwszFindChar = NULL;
lstrcpyW(XMLfilePath, AppPath);
lstrcatW(XMLfilePath,L"\\HyperV.xml");
DWORD dwIniLen = 0;
dwIniLen = ::GetCompressedFileSizeW(XMLfilePath, 0);
dwIniLen *= 2;
HANDLE hFile = NULL;
DWORD dwFileSize=0;
DWORD dwReadBuffer = 0;
wchar_t* pszBuffer = { 0 };
hFile = CreateFileW(XMLfilePath,
GENERIC_READ ,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
dwIniLen = ::GetCompressedFileSize(XMLfilePath, 0);
dwIniLen *= 2;
pszBuffer = new wchar_t[dwIniLen];
wmemset(pszBuffer, NULL, (dwIniLen));
::ReadFile(hFile, pszBuffer, dwIniLen, &dwReadBuffer, 0);
wstring ws(pszBuffer);
string xmlContent(ws.begin(), ws.end());
if (0 == dwReadBuffer)
{
CloseHandle(hFile);
}
else
{
}
CloseHandle(hFile);
return 0;
}