请高手指教如何xml中dom操作,如何使用insertBefore,尤其是第二个参数,

xiao_xiao_xiao 2002-09-13 08:03:58
insertBefore Method [C/C++]
Inserts a child node to the left of the specified node or at the end of the list.

[Script]
Script Syntax
var objXMLDOMNode = oXMLDOMNode.insertBefore(newChild, refChild);
Parameters
newChild
An object. The address of the new node to be inserted.
refChild
A variant. The address of the reference node; newChild is inserted to the left of refChild. If Null, newChild is inserted at the end of the child list.
Return Value
Object. On success, returns the child node that was inserted.

Example
The following script example creates a new IXMLDOMNode object and inserts it before the second child of the top-level node.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
var root;
var newNode;
var currNode;
xmlDoc.async = false;
xmlDoc.load("books.xml");
root = xmlDoc.documentElement;
alert(root.xml);
newNode = xmlDoc.createNode(1, "VIDEOS", "");
currNode = root.insertBefore(newNode, root.childNodes.item(1));
alert(root.xml);
[Visual Basic]
Visual Basic Syntax
Set objXMLDOMNode = oXMLDOMNode.insertBefore(newChild, refChild)
Parameters
newChild
An object. The address of the new node to be inserted.
refChild
A variant. The address of the reference node; newChild is inserted to the left of refChild. If Null, newChild is inserted at the end of the child list.
Return Value
An object. On success, returns the child node that was inserted.

Example
The following Visual Basic example creates a new IXMLDOMNode object and inserts it before the second child of the top-level node.

Dim xmlDoc As New Msxml2.DOMDocument
Dim root As IXMLDOMElement
Dim newNode As IXMLDOMNode
Dim currNode As IXMLDOMNode
xmlDoc.async = False
xmlDoc.Load ("books.xml")
Set root = xmlDoc.documentElement
MsgBox root.xml
Set newNode = xmlDoc.createNode(NODE_ELEMENT, "VIDEOS", "")
Set currNode = root.insertBefore(newNode, root.childNodes.Item(1))
MsgBox root.xml
[C/C++]
C/C++ Syntax
HRESULT insertBefore(
IXMLDOMNode *newChild,
VARIANT refChild,
IXMLDOMNode **outNewChild);
以上是VB和JAVA的例子,我不知道在VC下如何使用。
...全文
90 6 点赞 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xuefl66 2002-11-06
学习!!!
  • 打赏
  • 举报
回复
冰霜icefrost 2002-11-01
node->QueryInterface(IID_IXMLDOMNode,(void**)&pNode);
ParentNode->insertBefore(Newnode, pNode);

这样就可以了
  • 打赏
  • 举报
回复
xiao_xiao_xiao 2002-10-01
问题依旧,有没有人做过,给点提示
谢谢
  • 打赏
  • 举报
回复
xiao_xiao_xiao 2002-10-01
问题依旧,有没有人做过,给点提示
谢谢
  • 打赏
  • 举报
回复
xiao_xiao_xiao 2002-10-01
问题依旧,有没有人做过,给点提示
谢谢
  • 打赏
  • 举报
回复
ljhhome 2002-09-30
gz
  • 打赏
  • 举报
回复
相关推荐
发帖
HTML/XML
创建于2007-09-28

3054

社区成员

VC/MFC HTML/XML
申请成为版主
帖子事件
创建了帖子
2002-09-13 08:03
社区公告
暂无公告