开发者

How to delete a node & its childs in XML

开发者 https://www.devze.com 2023-03-27 05:19 出处:网络
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\"?>

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 ToolDetailsand 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()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号