How to delete a node & its childs in XML
i am facing some problem in Deleting a Node from XML.
Here is the schema of my XML,
<?xml version="1.0" encoding="ISO-8859-1"?>
<file>
<header Description="Lovely Tool"></header>
<ToolPath>C:\MyDocs\MyTool\</ToolPath>
<ToolDetails>
<Name>XML Tool</Name>
<Description>XML parser</Description>
<Comments>Good Tool for XML</Comments>
</Tool开发者_C百科Details>
</file>
I want to delete the Node ToolDetails
and its childs
, i tried like this using MSXML, but its not working,
Here is my code
CString childName;
MSXML2::IXMLDOMNodePtr childPtr = NULL;
MSXML2::IXMLDOMNodePtr delNode = NULL;
int i=0;
MSXML2::IXMLDOMNodeListPtr pChildNodeListPtr = NULL;
delNode = m_pRoot->GetchildNodes()->Getitem(index+2);//m_pRoot is the root ptr
childName=(char*)m_ptrDataBlock->nodeName;
HRESULT hr = m_pRoot->removeChild(delNode);
Getitem(index+2)
will only return the handle for index + 2th
item.
for deleting the node you also need to detach the item by calling
Getitem(index)->detach()
精彩评论