如何删除节点&它的子级在 XML 中
我在从 XML 中删除节点时遇到一些问题。
这是我的 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>
</ToolDetails>
</file>
我想删除节点 ToolDetails
及其 childs
,我使用 MSXML 尝试这样做,但它不起作用,
这是我的代码
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);
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>
</ToolDetails>
</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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Getitem(index+2)
只会返回index + 2th
项的句柄。要删除节点,您还需要通过调用来分离该项目
Getitem(index)->detach()
Getitem(index+2)
will only return the handle forindex + 2th
item.for deleting the node you also need to detach the item by calling
Getitem(index)->detach()