clone Method

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

clone Method

Clones a copy of the current IXMLDOMSelection, with the same position and context.

[Script]

Script Syntax

var NewObjXMLDOMSelection = objXMLDOMSelection.clone();

Example

//Create a DOMDocument2 object and load some XML:
xmldoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
xmldoc.loadXML("<root><elem1>foo</elem1><elem2>bar</elem2></root>");
if (xmlDoc.parseError.errorCode <> 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   //Create an XMLDOMSelection object from selected nodes:
   xpath = xmldoc.selectNodes("root/elem1");
   //Cache the XPath expression and context:
   xpath.expr = "root/elem1";
   xpath.context = xmldoc;

   //Clone the XMLDOMSelection object
   xpath2 = xpath.clone();
   temp1 = xpath.peekNode();  // temp1 == <elem1/>
   temp2 = xpath2.peekNode();  // temp2 == <elem1/> Note the position and
   // context are maintained.
}
[Visual Basic]

Visual Basic Syntax

Set NewObjXMLDOMSelection = objXMLDOMSelection.clone

Example

Dim xmlDoc As New Msxml2.DOMDocument50
Dim xpath As IXMLDOMSelection
Dim xpath2 As IXMLDOMSelection
Dim temp1 As IXMLDOMNode
Dim temp2 As IXMLDOMNode
xmlDoc.loadXML ("<root><elem1>foo</elem1><elem2>bar</elem2></root>")
If (xmlDoc.parseError.errorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox("You have error " & myErr.reason)
Else
   ' Create an XMLDOMSelection object from selected nodes:
   Set xpath = xmlDoc.selectNodes("root/elem1")
   ' Cache the XPath expression and context:
   xpath.expr = "root/elem1"
   Set xpath.context = xmlDoc
   ' Clone the XMLDOMSelection object.
   Set xpath2 = xpath.Clone()
   Set temp1 = xpath.peekNode()    ' temp1 == <elem1/>
   Set temp2 = xpath2.peekNode()   ' temp2 == <elem1/> Note the
                                   ' position and
   ' context are maintained.
End If
[C/C++]

C/C++ Syntax

HRESULT clone(IXMLDOMSelection ** ppNode);

Parameters

ppNode [out, retval]
The returned copy of the IXMLDOMSelection object.

C/C++ Return Values

S_OK
The value returned if the cloning is successful.
E_INVALIDARG
The value returned if the input argument is Null.

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Applies to: IXMLDOMSelection