XPathNavigator.DeleteSelf 메서드

정의

현재 노드와 해당 자식 노드를 삭제합니다.Deletes the current node and its child nodes.

public:
 virtual void DeleteSelf();
public virtual void DeleteSelf ();
abstract member DeleteSelf : unit -> unit
override this.DeleteSelf : unit -> unit
Public Overridable Sub DeleteSelf ()

예외

XPathNavigator가 삭제할 수 없는 노드(예: 루트 노드 또는 네임스페이스 노드)에 있습니다.The XPathNavigator is positioned on a node that cannot be deleted such as the root node or a namespace node.

XPathNavigator에서는 편집을 지원하지 않습니다.The XPathNavigator does not support editing.

예제

다음 예제에서는 price 첫 번째 요소의 book 요소의 contosoBooks.xml 파일을 사용 하 여 삭제를 DeleteSelf 메서드.In the following example the price element of the first book element of the contosoBooks.xml file is deleted using the DeleteSelf method. XPathNavigator 요소를 삭제한 후 price 개체는 부모 book 요소에 배치됩니다.The position of the XPathNavigator object after the price element is deleted is on the parent book element.

XmlDocument^ document = gcnew XmlDocument();
document->Load("contosoBooks.xml");
XPathNavigator^ navigator = document->CreateNavigator();

navigator->MoveToChild("bookstore", "http://www.contoso.com/books");
navigator->MoveToChild("book", "http://www.contoso.com/books");
navigator->MoveToChild("price", "http://www.contoso.com/books");

navigator->DeleteSelf();

Console::WriteLine("Position after delete: {0}", navigator->Name);
Console::WriteLine(navigator->OuterXml);
XmlDocument document = new XmlDocument();
document.Load("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToChild("bookstore", "http://www.contoso.com/books");
navigator.MoveToChild("book", "http://www.contoso.com/books");
navigator.MoveToChild("price", "http://www.contoso.com/books");

navigator.DeleteSelf();

Console.WriteLine("Position after delete: {0}", navigator.Name);
Console.WriteLine(navigator.OuterXml);
Dim document As XmlDocument = New XmlDocument()
document.Load("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToChild("bookstore", "http://www.contoso.com/books")
navigator.MoveToChild("book", "http://www.contoso.com/books")
navigator.MoveToChild("price", "http://www.contoso.com/books")

navigator.DeleteSelf()

Console.WriteLine("Position after delete: {0}", navigator.Name)
Console.WriteLine(navigator.OuterXml)

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

  
<?xml version="1.0" encoding="utf-8" ?>  
<bookstore xmlns="http://www.contoso.com/books">  
    <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>  
  

설명

  • XPathNavigator 성공적으로 삭제 삭제 된 노드의 부모 노드에 배치 됩니다.The XPathNavigator is positioned on the deleted node's parent node on successful deletion.

  • 삭제 된 노드는 단순 형식된 요소 내용의 텍스트 노드의 경우 요소의 형식 정보가 손실 됩니다.If the deleted node is a text node which is the content of a simple typed element, the element loses its type information. 즉, 요소에 배치 합니다 XmlType, ValueType 하 고 TypedValue 속성의 값은 null, StringEmpty 각각.This means that when positioned on the element the XmlType, ValueType and TypedValue properties have the values null, String and Empty respectively.

  • 삭제 된 노드는 여전히 액세스할 XPathNavigator 개체 삭제 하기 전에 위에 배치 합니다.Deleted nodes are still accessible to XPathNavigator objects positioned over them prior to deletion. 그러나에서 삭제 된 하위 트리를 이동 하려고 하는 메서드는 실패 합니다.However methods that attempt to move away from the deleted sub-tree fail. 예를 들어를 MoveToParentMoveToPrevious 메서드가 항상 실패는 XPathNavigator 위쪽 가장 삭제 된 노드 위에 배치 됩니다.For example, the MoveToParent and MoveToPrevious methods always fail when the XPathNavigator is positioned over the top most deleted node. 즉, 삭제 된 노드를 XML 문서에 연결 되어 있지 않습니다.This is because the deleted node is no longer connected to the XML document. 마찬가지로 합니다 MoveToNext 메서드는 경우에 항상 실패는 XPathNavigator 최하위 삭제 된 노드에 배치 됩니다.Similarly the MoveToNext method always fails if the XPathNavigator is positioned on the bottom-most deleted node.

적용 대상