Clones a copy of the current IXMLDOMSelection
, with the same position and context.
var NewObjXMLDOMSelection = objXMLDOMSelection.clone();
//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. }
Set NewObjXMLDOMSelection = objXMLDOMSelection.clone
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
HRESULT clone(IXMLDOMSelection ** ppNode);
IXMLDOMSelection
object.To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button in the upper-left corner of the page.
Applies to: IXMLDOMSelection