XPathNavigator.Clone 메서드

정의

파생 클래스에서 재정의할 때 이 XPathNavigator와 같은 노드에 새 XPathNavigator를 만듭니다.When overridden in a derived class, creates a new XPathNavigator positioned at the same node as this XPathNavigator.

public:
 abstract System::Xml::XPath::XPathNavigator ^ Clone();
public abstract System.Xml.XPath.XPathNavigator Clone ();
abstract member Clone : unit -> System.Xml.XPath.XPathNavigator
Public MustOverride Function Clone () As XPathNavigator

반환

XPathNavigator와 같은 노드에 있는 새 XPathNavigator입니다.A new XPathNavigator positioned at the same node as this XPathNavigator.

예제

다음 예제에서는 Herman Melville가 작성 한 모든 책 제목을 가져옵니다.The following example gets all book titles authored by Herman Melville.

XPathDocument^ document = gcnew XPathDocument("books.xml");
XPathNavigator^ navigator = document->CreateNavigator();

// Select all books authored by Melville.
XPathNodeIterator^ nodes = navigator->Select("descendant::book[author/last-name='Melville']");

while (nodes->MoveNext())
{
    // Clone the navigator returned by the Current property. 
    // Use the cloned navigator to get the title element.
    XPathNavigator^ clone = nodes->Current->Clone();
    clone->MoveToFirstChild();
    Console::WriteLine("Book title: {0}", clone->Value);
}
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();

// Select all books authored by Melville.
XPathNodeIterator nodes = navigator.Select("descendant::book[author/last-name='Melville']");

while (nodes.MoveNext())
{
    // Clone the navigator returned by the Current property. 
    // Use the cloned navigator to get the title element.
    XPathNavigator clone = nodes.Current.Clone();
    clone.MoveToFirstChild();
    Console.WriteLine("Book title: {0}", clone.Value);
}
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

' Select all books authored by Melville.
Dim nodes As XPathNodeIterator = navigator.Select("descendant::book[author/last-name='Melville']")

While nodes.MoveNext()
    ' Clone the navigator returned by the Current property. 
    ' Use the cloned navigator to get the title element.
    Dim clone As XPathNavigator = nodes.Current.Clone()
    clone.MoveToFirstChild()
    Console.WriteLine("Book title: {0}", clone.Value)
End While

이 예제에서는 books.xml 파일을 입력으로 사용합니다.The example takes the books.xml file as an input.

<?xml version="1.0" encoding="utf-8" ?>   
<bookstore>  
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">  
        <title>The Autobiography of Benjamin Franklin</title>  
        <author>  
            <first-name>Benjamin</first-name>  
            <last-name>Franklin</last-name>  
        </author>  
        <price>8.99</price>  
    </book>  
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">  
        <title>The Confidence Man</title>  
        <author>  
            <first-name>Herman</first-name>  
            <last-name>Melville</last-name>  
        </author>  
        <price>11.99</price>  
    </book>  
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">  
        <title>The Gorgias</title>  
        <author>  
            <name>Plato</name>  
        </author>  
        <price>9.99</price>  
    </book>  
</bookstore>  
  

설명

합니다 Clone 메서드는 함께에서 특히 유용 합니다 XPathNodeIterator합니다.The Clone method is especially useful in conjunction with the XPathNodeIterator. XPathNodeIterator 개와 선택한 노드 집합을 반복 하는 데는 Current 반환 하는 속성을 XPathNavigator 의 컨텍스트 노드에 XPathNodeIterator.An XPathNodeIterator is used to iterate over a selected node set, and contains a Current property which returns an XPathNavigator positioned on the context node of the XPathNodeIterator. 그러나 합니다 XPathNavigator 반환한는 Current 속성을 사용 하 여 노드 집합에서 이동할 수 없습니다.However, the XPathNavigator returned by the Current property cannot be used to move away from the node set. 반환 된 복제 대신 XPathNavigator 복제 탐색기를 사용 하 여 모든 추가 이동 작업을 수행 하 고 있습니다.Instead, you clone the returned XPathNavigator and use the cloned navigator to do any additional moves.

복제 된 XPathNavigator 원래 후속 변경 내용의 영향을 받지 않습니다 XPathNavigator합니다.The cloned XPathNavigator is not affected by subsequent changes to the original XPathNavigator.

적용 대상