请高手指教如何xml中dom操作,如何使用insertBefore,尤其是第二个参数,
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下如何使用。