XPathNavigator.AppendChild Yöntem

Tanım

Geçerli düğümün alt düğüm listesinin sonunda yeni bir alt düğüm oluşturur.

Aşırı Yüklemeler

Name Description
AppendChild()

Geçerli düğümün alt düğüm listesinin sonunda bir veya daha fazla yeni alt düğüm oluşturmak için kullanılan bir XmlWriter nesneyi döndürür.

AppendChild(String)

Belirtilen XML veri dizesini kullanarak geçerli düğümün alt düğüm listesinin sonunda yeni bir alt düğüm oluşturur.

AppendChild(XmlReader)

Belirtilen nesnenin XML içeriğini XmlReader kullanarak geçerli düğümün alt düğüm listesinin sonunda yeni bir alt düğüm oluşturur.

AppendChild(XPathNavigator)

Belirtilen düğümlerdeki düğümleri kullanarak geçerli düğümün alt düğümleri listesinin sonunda yeni bir alt düğüm XPathNavigator oluşturur.

AppendChild()

Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs

Geçerli düğümün alt düğüm listesinin sonunda bir veya daha fazla yeni alt düğüm oluşturmak için kullanılan bir XmlWriter nesneyi döndürür.

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

Döndürülenler

XmlWriter Geçerli düğümün alt düğüm listesinin sonunda yeni alt düğümler oluşturmak için kullanılan nesne.

Özel durumlar

konumundaki geçerli düğüm XPathNavigator , kök düğüm veya öğe düğümü değildir.

XPathNavigator düzenlemeyi desteklemiyor.

Örnekler

Aşağıdaki örnekte, yönteminden pages döndürülen nesnesi kullanılarak book dosyadaki contosoBooks.xml ilk XmlWriter öğenin alt öğeleri listesine yeni AppendChild bir alt öğe eklenir.

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

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

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

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

Console.WriteLine(navigator.OuterXml)

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

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

Alt düğümlerin eklenmesi, yeni düğümleri geçerli düğüm için alt düğüm listesinin sonuna ekler. Örneğin, bir öğe için üç alt düğüm olduğunda, eklenen ilk düğüm dördüncü alt düğüm olur. Alt düğüm yoksa yeni bir alt düğüm oluşturulur.

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

Yazıcıya birden fazla düğüm yazabilirsiniz. Tüm düğümler, geçerli düğümün alt düğüm listesinin sonuna eklenir.

Şunlara uygulanır

AppendChild(String)

Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs

Belirtilen XML veri dizesini kullanarak geçerli düğümün alt düğüm listesinin sonunda yeni bir alt düğüm oluşturur.

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

Parametreler

newChild
String

Yeni alt düğümün XML veri dizesi.

Özel durumlar

XML veri dizesi parametresidir null.

konumundaki geçerli düğüm XPathNavigator , kök düğüm veya öğe düğümü değildir.

XPathNavigator düzenlemeyi desteklemiyor.

XML veri dizesi parametresi iyi biçimlendirilmemiş.

Örnekler

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

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

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.AppendChild("<pages>100</pages>")

Console.WriteLine(navigator.OuterXml)

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

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

Alt düğümün eklenmesi, yeni düğümü geçerli düğüm için alt düğüm listesinin sonuna ekler. Örneğin, bir öğe için üç alt düğüm olduğunda, eklenen düğüm dördüncü alt düğüm olur. Alt düğüm yoksa yeni bir alt düğüm oluşturulur.

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 AppendChild("<book/>"). Geçerli düğümün metin düğümüne "book" metnini ekleme dizesidir AppendChild("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 AppendChild .

Şunlara uygulanır

AppendChild(XmlReader)

Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs

Belirtilen nesnenin XML içeriğini XmlReader kullanarak geçerli düğümün alt düğüm listesinin sonunda yeni bir alt düğüm oluşturur.

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

Parametreler

newChild
XmlReader

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

Özel durumlar

XmlReader Nesne bir hata durumunda veya kapatıldı.

XmlReader nesne parametresidirnull.

konumundaki geçerli düğüm XPathNavigator , kök düğüm veya öğe düğümü değildir.

XPathNavigator düzenlemeyi desteklemiyor.

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

Örnekler

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

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

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

navigator.AppendChild(pages);

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

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

navigator.AppendChild(pages)

Console.WriteLine(navigator.OuterXml)

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

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

Alt düğümün eklenmesi, yeni düğümü geçerli düğüm için alt düğüm listesinin sonuna ekler. Örneğin, bir öğe için üç alt düğüm olduğunda, eklenen düğüm dördüncü alt düğüm olur. Alt düğüm yoksa yeni bir alt düğüm oluşturulur.

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

  • XmlReader Nesne bir XML düğümleri dizisinin üzerine yerleştirilirse, dizideki tüm düğümler eklenir.

  • AppendChild yöntemi yalnızca , kök düğümde veya bir öğe düğümünde konumlandırıldığında XPathNavigator geçerlidir.

  • yöntemi, AppendChild konumunu XPathNavigatoretkilemez.

Şunlara uygulanır

AppendChild(XPathNavigator)

Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs
Kaynak:
XPathNavigator.cs

Belirtilen düğümlerdeki düğümleri kullanarak geçerli düğümün alt düğümleri listesinin sonunda yeni bir alt düğüm XPathNavigator oluşturur.

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

Parametreler

newChild
XPathNavigator

XPathNavigator Yeni alt düğüm olarak eklenecek düğümde konumlandırılan nesne.

Özel durumlar

XPathNavigator nesne parametresidirnull.

konumundaki geçerli düğüm XPathNavigator , kök düğüm veya öğe düğümü değildir.

XPathNavigator düzenlemeyi desteklemiyor.

Örnekler

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

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

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

if(childNodesNavigator.MoveToChild("pages", "http://www.contoso.com/books"))
{
    navigator.AppendChild(childNodesNavigator);
}

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

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()

If childNodesNavigator.MoveToChild("pages", "http://www.contoso.com/books") Then
    navigator.AppendChild(childNodesNavigator)
End If

Console.WriteLine(navigator.OuterXml)

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

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

Alt düğümün eklenmesi, yeni düğümü geçerli düğüm için alt düğüm listesinin sonuna ekler. Örneğin, bir öğe için üç alt düğüm olduğunda, eklenen düğüm dördüncü alt düğüm olur. Alt düğüm yoksa yeni bir alt düğüm oluşturulur.

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

Şunlara uygulanır