Share via


XPathNavigator.InsertBefore Yöntem

Tanım

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

Aşırı Yüklemeler

InsertBefore()

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

InsertBefore(String)

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

InsertBefore(XmlReader)

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

InsertBefore(XPathNavigator)

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

InsertBefore()

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

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

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

Döndürülenler

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

Özel durumlar

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

düzenlemeyi XPathNavigator desteklemiyor.

Örnekler

Aşağıdaki örnekte, yöntemi tarafından InsertBefore döndürülen nesnesi kullanılarak XmlWriter dosyadaki contosoBooks.xml ilk book öğenin alt öğesinden önce 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->InsertBefore();
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.InsertBefore();
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.InsertBefore()
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ırken dikkate alınması gereken önemli notlar aşağıdadır InsertBefore .

Şunlara uygulanır

InsertBefore(String)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

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

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

Parametreler

newSibling
String

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

Özel durumlar

XML dizesi parametresi şeklindedir null.

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

düzenlemeyi XPathNavigator desteklemiyor.

XML dizesi parametresi iyi biçimlendirilmemiş.

Örnekler

Aşağıdaki örnekte, dosyadaki price ilk book öğenin alt öğesinden önce 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->InsertBefore("<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.InsertBefore("<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.InsertBefore("<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 InsertBefore("<book/>"). Geçerli düğümün metin düğümünden önce "book" metnini ekleme dizesi şeklindedir InsertBefore("book"). XML dizesi birden çok düğüm içeriyorsa, tüm düğümler eklenir.

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

Şunlara uygulanır

InsertBefore(XmlReader)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

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

public:
 virtual void InsertBefore(System::Xml::XmlReader ^ newSibling);
public virtual void InsertBefore (System.Xml.XmlReader newSibling);
abstract member InsertBefore : System.Xml.XmlReader -> unit
override this.InsertBefore : System.Xml.XmlReader -> unit
Public Overridable Sub InsertBefore (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 önce yeni bir eşdüzey düğümün eklenmesine izin vermez.

düzenlemeyi XPathNavigator desteklemiyor.

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

Örnekler

Aşağıdaki örnekte, belirtilen nesne kullanılarak XmlReader dosyadaki contosoBooks.xmlprice ilk book öğenin alt öğesinden önce yeni pages bir öğe eklenir. Ad http://www.contoso.com/books alanı, yeni eşdüzey öğenin XML belgesiyle aynı ad alanı kullanılarak eklenmesi için 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->InsertBefore(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.InsertBefore(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.InsertBefore(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ırken dikkate alınması gereken önemli notlar aşağıdadır InsertBefore .

  • XmlReader Nesne bir XML düğümleri dizisinin üzerine konumlandırıldıysa, dizideki tüm düğümler eklenir.

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

  • InsertBefore yöntemi, konumunu XPathNavigatoretkilemez.

Şunlara uygulanır

InsertBefore(XPathNavigator)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

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

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

Parametreler

newSibling
XPathNavigator

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

Özel durumlar

XPathNavigator nesne parametresidirnull.

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

düzenlemeyi XPathNavigator desteklemiyor.

Örnekler

Aşağıdaki örnekte, belirtilen nesnede price bulunan XPathNavigator düğüm kullanılarak dosyadaki contosoBooks.xml ilk book öğenin alt öğesinden önce yeni pages bir öğe eklenir. Ad http://www.contoso.com/books alanı, yeni eşdüzey öğenin XML belgesiyle aynı ad alanı kullanılarak eklenmesi için 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->InsertBefore(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.InsertBefore(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.InsertBefore(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ırken dikkate alınması gereken önemli notlar aşağıdadır InsertBefore .

Şunlara uygulanır