XPathNavigator.InsertAfter Yöntem

Tanım

Seçili durumdaki düğümden sonra yeni bir eşdüzey düğüm oluşturur.

Aşırı Yüklemeler

InsertAfter(XPathNavigator)

Belirtilen nesnedeki düğümleri kullanarak seçili durumdaki düğümden sonra yeni bir eşdüzey düğüm XPathNavigator oluşturur.

InsertAfter(XmlReader)

Belirtilen nesnenin XML içeriğini XmlReader kullanarak seçili durumdaki düğümden sonra yeni bir eşdüzey düğüm oluşturur.

InsertAfter()

XmlWriter Seçili durumdaki düğümden sonra yeni bir eşdüzey düğüm oluşturmak için kullanılan nesneyi döndürür.

InsertAfter(String)

Belirtilen XML dizesini kullanarak seçili durumdaki düğümden sonra yeni bir eşdüzey düğüm oluşturur.

InsertAfter(XPathNavigator)

Belirtilen nesnedeki düğümleri kullanarak seçili durumdaki düğümden sonra yeni bir eşdüzey düğüm XPathNavigator oluşturur.

public:
 virtual void InsertAfter(System::Xml::XPath::XPathNavigator ^ newSibling);
public virtual void InsertAfter (System.Xml.XPath.XPathNavigator newSibling);
abstract member InsertAfter : System.Xml.XPath.XPathNavigator -> unit
override this.InsertAfter : System.Xml.XPath.XPathNavigator -> unit
Public Overridable Sub InsertAfter (newSibling As XPathNavigator)

Parametreler

newSibling
XPathNavigator

XPathNavigator Yeni eşdüzey düğüm olarak eklenecek düğümde konumlandırılmış bir nesne.

Özel durumlar

XPathNavigator nesne parametresidirnull.

konumu XPathNavigator , geçerli düğümden sonra yeni bir eşdüzey düğümün eklenmesine izin vermez.

düzenlemeyi XPathNavigator desteklemez.

Örnekler

Aşağıdaki örnekte, belirtilen nesnede price bulunan XPathNavigator düğüm kullanılarak dosyadaki contosoBooks.xml ilk book öğenin alt öğesinden sonra yeni pages bir öğe eklenir. Yeni http://www.contoso.com/books eşdüzey öğenin XML belgesiyle aynı ad alanı kullanılarak eklenmesi için ad alanı belirtilir.

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");

XmlDocument^ childNodes = gcnew XmlDocument();
childNodes->Load(gcnew StringReader("<pages xmlns=\"http://www.contoso.com/books\">100</pages>"));
XPathNavigator^ childNodesNavigator = childNodes->CreateNavigator();

navigator->InsertAfter(childNodesNavigator);

navigator->MoveToParent();
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");

XmlDocument childNodes = new XmlDocument();
childNodes.Load(new StringReader("<pages xmlns=\"http://www.contoso.com/books\">100</pages>"));
XPathNavigator childNodesNavigator = childNodes.CreateNavigator();

navigator.InsertAfter(childNodesNavigator);

navigator.MoveToParent();
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")

Dim childNodes As XmlDocument = New XmlDocument()
childNodes.Load(New StringReader("<pages xmlns='http://www.contoso.com/books'>100</pages>"))
Dim childNodesNavigator As XPathNavigator = childNodes.CreateNavigator()

navigator.InsertAfter(childNodesNavigator)

navigator.MoveToParent()
Console.WriteLine(navigator.OuterXml)

Örnek, dosyayı giriş olarak alır contosoBooks.xml .

<?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>  

Açıklamalar

Yöntemi kullanılırken InsertAfter dikkate alınması gereken önemli notlar aşağıdadır.

  • XmlReader Nesne bir XML düğümleri dizisi üzerine konumlandırılırsa, dizideki tüm düğümler eklenir.

  • InsertAfter yöntemi yalnızca öğesi, metin, işleme yönergesi veya açıklama düğümünde konumlandırıldığında XPathNavigator geçerlidir.

  • InsertAfter yöntemi, konumunu XPathNavigatoretkilemez.

Şunlara uygulanır

InsertAfter(XmlReader)

Belirtilen nesnenin XML içeriğini XmlReader kullanarak seçili durumdaki düğümden sonra yeni bir eşdüzey düğüm oluşturur.

public:
 virtual void InsertAfter(System::Xml::XmlReader ^ newSibling);
public virtual void InsertAfter (System.Xml.XmlReader newSibling);
abstract member InsertAfter : System.Xml.XmlReader -> unit
override this.InsertAfter : System.Xml.XmlReader -> unit
Public Overridable Sub InsertAfter (newSibling As XmlReader)

Parametreler

newSibling
XmlReader

XmlReader Yeni eşdüzey düğüm için XML verilerine konumlandırılmış bir nesne.

Özel durumlar

Nesne XmlReader bir hata durumunda veya kapalı.

XmlReader nesne parametresidirnull.

konumu XPathNavigator , geçerli düğümden sonra yeni bir eşdüzey düğümün eklenmesine izin vermez.

düzenlemeyi XPathNavigator desteklemez.

Nesne parametresinin XmlReader XML içeriği iyi biçimlendirilmemiş.

Örnekler

Aşağıdaki örnekte, belirtilen nesne kullanılarak dosyadaki price ilk book öğenin alt öğesinden sonra yeni pages bir öğe contosoBooks.xml eklenir.XmlReader Yeni http://www.contoso.com/books eşdüzey öğenin XML belgesiyle aynı ad alanı kullanılarak eklenmesi için ad alanı belirtilir.

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");

XmlReader^ pages = XmlReader::Create(gcnew StringReader("<pages xmlns=\"http://www.contoso.com/books\">100</pages>"));

navigator->InsertAfter(pages);

navigator->MoveToParent();
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");

XmlReader pages = XmlReader.Create(new StringReader("<pages xmlns=\"http://www.contoso.com/books\">100</pages>"));

navigator.InsertAfter(pages);

navigator.MoveToParent();
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")

Dim pages As XmlReader = XmlReader.Create(New StringReader("<pages xmlns='http://www.contoso.com/books'>100</pages>"))

navigator.InsertAfter(pages)

navigator.MoveToParent()
Console.WriteLine(navigator.OuterXml)

Örnek, dosyayı giriş olarak alır contosoBooks.xml .

<?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>  

Açıklamalar

Yöntemi kullanılırken InsertAfter dikkate alınması gereken önemli notlar aşağıdadır.

  • XmlReader Nesne bir XML düğümleri dizisi üzerine konumlandırılırsa, dizideki tüm düğümler eklenir.

  • InsertAfter yöntemi yalnızca öğesi, metin, işleme yönergesi veya açıklama düğümünde konumlandırıldığında XPathNavigator geçerlidir.

  • InsertAfter yöntemi, konumunu XPathNavigatoretkilemez.

Şunlara uygulanır

InsertAfter()

XmlWriter Seçili durumdaki düğümden sonra yeni bir eşdüzey düğüm oluşturmak için kullanılan nesneyi döndürür.

public:
 virtual System::Xml::XmlWriter ^ InsertAfter();
public virtual System.Xml.XmlWriter InsertAfter ();
abstract member InsertAfter : unit -> System.Xml.XmlWriter
override this.InsertAfter : unit -> System.Xml.XmlWriter
Public Overridable Function InsertAfter () As XmlWriter

Döndürülenler

XmlWriter

XmlWriter Seçili durumdaki düğümden sonra yeni bir eşdüzey düğüm oluşturmak için kullanılan nesne.

Özel durumlar

konumu XPathNavigator , geçerli düğümden sonra yeni bir eşdüzey düğümün eklenmesine izin vermez.

düzenlemeyi XPathNavigator desteklemez.

Örnekler

Aşağıdaki örnekte, yöntemi tarafından InsertAfter döndürülen nesnesi kullanılarak XmlWriter dosyadaki contosoBooks.xml ilk book öğenin alt öğesinden sonra price yeni pages bir öğe eklenir.

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");

XmlWriter^ pages = navigator->InsertAfter();
pages->WriteElementString("pages", "100");
pages->Close();

navigator->MoveToParent();
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");

XmlWriter pages = navigator.InsertAfter();
pages.WriteElementString("pages", "100");
pages.Close();

navigator.MoveToParent();
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")

Dim pages As XmlWriter = navigator.InsertAfter()
pages.WriteElementString("pages", "100")
pages.Close()

navigator.MoveToParent()
Console.WriteLine(navigator.OuterXml)

Örnek, dosyayı giriş olarak alır contosoBooks.xml .

<?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>  

Açıklamalar

Yöntemi kullanılırken InsertAfter dikkate alınması gereken önemli notlar aşağıdadır.

Şunlara uygulanır

InsertAfter(String)

Belirtilen XML dizesini kullanarak seçili durumdaki düğümden sonra yeni bir eşdüzey düğüm oluşturur.

public:
 virtual void InsertAfter(System::String ^ newSibling);
public virtual void InsertAfter (string newSibling);
abstract member InsertAfter : string -> unit
override this.InsertAfter : string -> unit
Public Overridable Sub InsertAfter (newSibling As String)

Parametreler

newSibling
String

Yeni eşdüzey düğüm için XML veri dizesi.

Özel durumlar

XML dizesi parametresidir null.

konumu XPathNavigator , geçerli düğümden sonra yeni bir eşdüzey düğümün eklenmesine izin vermez.

düzenlemeyi XPathNavigator desteklemez.

XML dize parametresi iyi biçimlendirilmemiş.

Örnekler

Aşağıdaki örnekte, dosyadaki price ilk book öğenin alt öğesinden sonra yeni pages bir öğe contosoBooks.xml eklenir.

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->InsertAfter("<pages>100</pages>");

navigator->MoveToParent();
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.InsertAfter("<pages>100</pages>");

navigator.MoveToParent();
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.InsertAfter("<pages>100</pages>")

navigator.MoveToParent()
Console.WriteLine(navigator.OuterXml)

Örnek, dosyayı giriş olarak alır contosoBooks.xml .

<?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>  

Açıklamalar

Yeni bir öğe düğümü oluşturmak için, XML dizesi parametresine tüm XML söz dizimini ekleyin. Yeni book düğümün dizesi şeklindedir InsertAfter("<book/>"). Geçerli düğümün metin düğümünden sonra "book" metnini ekleme dizesi şeklindedir InsertAfter("book"). XML dizesi birden çok düğüm içeriyorsa, tüm düğümler eklenir.

Yöntemi kullanılırken InsertAfter dikkate alınması gereken önemli notlar aşağıdadır.

Şunlara uygulanır