无法在所选节点之前将节点插入XML DOM文档中 [英] Can't insert a node into an XML DOM Document before the selected node

查看:73
本文介绍了无法在所选节点之前将节点插入XML DOM文档中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个节点插入XML DOM文档中选定的节点之前.新节点的创建很好,因为我已经将其输出到消息框,但是它始终在"insertBefore"行上崩溃.请告诉我我在做错什么-我看了很多例子,看不到我的代码为什么与众不同.

I am trying to insert a node into an XML DOM document before the selected node. The new node is created fine as I have output it to a mesage box, but it always crashes on the ''insertBefore'' line. Please tell me what I am doing wrong - I have looked at so many examples and can''t see why my code is different.

MSXML2::IXMLDOMDocumentPtr wspXMLDocPtr
MSXML2::IXMLDOMNodePtr selectedNodePtr;//this is set to a valid node - I have checked

MSXML2::IXMLDOMNodePtr newNode = m_wspXMLDocPtr->createNode(_variant_t((short)       MSXML2::NODE_ELEMENT),"SEQUENCE", "");
			
m_wspXMLDocPtr->insertBefore(newNode, _variant_t(selectedNodePtr.GetInterfacePtr()));

推荐答案

您不能在Document上调用insertBefore插入NODE_ELEMENT,请参见
You cannot call insertBefore on a Document for inserting a NODE_ELEMENT, see Calling insertBefore on Documents at MSDN[^].

You probably have to find the actual parent of the selectedNode and call insertBefore on it.


这篇关于无法在所选节点之前将节点插入XML DOM文档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆