Friday, February 24, 2012

Remove Child Node VC++

RemoveChildeNode()
{
::CoInitialize(NULL);

IXMLDOMDocumentPtr domDocument;

HRESULT hr = domDocument.CreateInstance(CLSID_DOMDocument);
if (FAILED(hr))
{
_com_error er(hr);
AfxMessageBox(er.ErrorMessage());
}

CString strFileName ="C:\test.xml";

CComBSTR bstrFileName(strFileName);
VARIANT_BOOL vStatus = VARIANT_FALSE;
CComVariant name(strFileName);
hr = domDocument->load(name, &vStatus);

if (FAILED(hr))
{
int errorCode = ::GetLastError();
AfxMessageBox("Load XML failed!");
return ;
}

CComPtr xnlPage;

long l_CountZone;
long l_CountPage;

_bstr_t TPage = "Page";
hr = domDocument->getElementsByTagName(TPage,&xnlPage);
if (FAILED(hr))
{
int errorCode = ::GetLastError();
AfxMessageBox("get_firstChild failed!");
return ;
}

hr = xnlPage->get_length(&l_CountPage);

for(int iCountPage= m_CurrPageNum-1;iCountPage<l_CountPage; iCountPage++)
{
CComPtr xnPage;
hr = xnlPage->get_item(iCountPage,&xnPage);


CComPtr xnlZone;
hr = xnPage->selectNodes(_bstr_t("Zone"),&xnlZone);
hr = xnlZone->get_length(&l_CountZone);

for(int iCountZone= 0;iCountZone<l_CountZone; iCountZone++)
{
CComPtr xnZone;
CComPtr xnZoneParent;
hr = xnlZone->get_item(iCountZone,&xnZone);

xnZone->get_parentNode(&xnZoneParent);
xnZoneParent->removeChild(xnZone,&pXMLNodeOld);



xnZone.Release();
xnZone=NULL;

xnZoneParent.Release();
xnZoneParent=NULL;

}
xnlZone.Release();
xnlZone=NULL;
}
xnlPage.Release();
xnlPage=NULL;

domDocument->save(name);
domDocument.Release();
domDocument=NULL;
::CoUninitialize();
}

Tuesday, February 14, 2012

Use boolean value in printf VC++

printf("You are married: %s",(married)?"true":"false");

Followers

Link