Language

XPathNavigator.AppendChild メソッド

定義

現在のノードの子ノードの一覧の末尾に新しい子ノードを作成します。

オーバーロード

名前 説明
AppendChild()

現在のノードの子ノードの一覧の末尾に 1 つ以上の新しい子ノードを作成するために使用する XmlWriter オブジェクトを返します。

AppendChild(String)

指定された XML データ文字列を使用して、現在のノードの子ノードの一覧の末尾に新しい子ノードを作成します。

AppendChild(XmlReader)

指定した XmlReader オブジェクトの XML コンテンツを使用して、現在のノードの子ノードの一覧の末尾に新しい子ノードを作成します。

AppendChild(XPathNavigator)

指定した XPathNavigator のノードを使用して、現在のノードの子ノードの一覧の末尾に新しい子ノードを作成します。

AppendChild()

ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs

現在のノードの子ノードの一覧の末尾に 1 つ以上の新しい子ノードを作成するために使用する XmlWriter オブジェクトを返します。

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

返品

現在のノードの子ノードの一覧の末尾に新しい子ノードを作成するために使用される XmlWriter オブジェクト。

例外

XPathNavigatorが配置されている現在のノードは、ルート ノードまたは要素ノードではありません。

XPathNavigatorは編集をサポートしていません。

例

次の例では、pages メソッドから返されたbook オブジェクトを使用して、contosoBooks.xml ファイル内の最初のXmlWriter要素の子要素の一覧に新しいAppendChild子要素が追加されます。

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)

この例では、 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>

注釈

子ノードを追加すると、現在のノードの子ノードの一覧の末尾に新しいノードが追加されます。 たとえば、要素に対して 3 つの子ノードが存在する場合、最初に追加されたノードが 4 番目の子ノードになります。 子ノードが存在しない場合は、新しい子ノードが作成されます。

AppendChildメソッドを使用する際に考慮すべき重要な注意事項を次に示します。

  • 新しい子ノードは、Close オブジェクトのXmlWriter メソッドが呼び出されるまで挿入されません。

  • AppendChild メソッドは、ルート ノードまたは要素ノードにXPathNavigatorが配置されている場合にのみ有効です。

  • AppendChildメソッドは、XPathNavigatorの位置には影響しません。

ライターには複数のノードを書き込むことができます。 すべてのノードは、現在のノードの子ノードの一覧の末尾に追加されます。

適用対象

AppendChild(String)

ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs

指定された XML データ文字列を使用して、現在のノードの子ノードの一覧の末尾に新しい子ノードを作成します。

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)

パラメーター

newChild
String

新しい子ノードの XML データ文字列。

例外

XML データ文字列パラメーターが null。

XPathNavigatorが配置されている現在のノードは、ルート ノードまたは要素ノードではありません。

XPathNavigatorは編集をサポートしていません。

XML データ文字列パラメーターは整形式ではありません。

例

次の例では、新しいpages子要素が、book ファイル内の最初のcontosoBooks.xml要素の子要素の一覧に追加されます。

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)

この例では、 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>

注釈

子ノードを追加すると、現在のノードの子ノードの一覧の末尾に新しいノードが追加されます。 たとえば、要素に対して 3 つの子ノードが存在する場合、追加されたノードは 4 番目の子ノードになります。 子ノードが存在しない場合は、新しい子ノードが作成されます。

新しい要素ノードを作成するには、XML 文字列パラメーターにすべての XML 構文を含めます。 新しい book ノードの文字列が AppendChild("<book/>")。 現在のノードのテキスト ノードにテキスト "book" を追加するための文字列が AppendChild("book")。 XML 文字列に複数のノードが含まれている場合は、すべてのノードが追加されます。

AppendChildメソッドを使用する際に考慮すべき重要な注意事項を次に示します。

適用対象

AppendChild(XmlReader)

ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs

指定した XmlReader オブジェクトの XML コンテンツを使用して、現在のノードの子ノードの一覧の末尾に新しい子ノードを作成します。

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)

パラメーター

newChild
XmlReader

新しい子ノードの XML データ上に配置された XmlReader オブジェクト。

例外

XmlReader オブジェクトがエラー状態であるか、閉じられています。

XmlReader オブジェクト パラメーターはnull。

XPathNavigatorが配置されている現在のノードは、ルート ノードまたは要素ノードではありません。

XPathNavigatorは編集をサポートしていません。

XmlReader オブジェクト パラメーターの XML コンテンツが整形式ではありません。

例

次の例では、指定されたpages オブジェクトを使用して、book ファイル内の最初のcontosoBooks.xml要素の子要素の一覧に新しいXmlReader子要素が追加されます。 http://www.contoso.com/books名前空間を指定して、XML ドキュメントと同じ名前空間を使用して新しい子要素を追加します。

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)

この例では、 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>

注釈

子ノードを追加すると、現在のノードの子ノードの一覧の末尾に新しいノードが追加されます。 たとえば、要素に対して 3 つの子ノードが存在する場合、追加されたノードは 4 番目の子ノードになります。 子ノードが存在しない場合は、新しい子ノードが作成されます。

AppendChildメソッドを使用する際に考慮すべき重要な注意事項を次に示します。

  • XmlReader オブジェクトが一連の XML ノード上に配置されている場合、シーケンス内のすべてのノードが追加されます。

  • AppendChild メソッドは、ルート ノードまたは要素ノードにXPathNavigatorが配置されている場合にのみ有効です。

  • AppendChildメソッドは、XPathNavigatorの位置には影響しません。

適用対象

AppendChild(XPathNavigator)

ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs
ソース:
XPathNavigator.cs

指定した XPathNavigator のノードを使用して、現在のノードの子ノードの一覧の末尾に新しい子ノードを作成します。

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)

パラメーター

newChild
XPathNavigator

新しい子ノードとして追加するノード上に配置された XPathNavigator オブジェクト。

例外

XPathNavigator オブジェクト パラメーターはnull。

XPathNavigatorが配置されている現在のノードは、ルート ノードまたは要素ノードではありません。

XPathNavigatorは編集をサポートしていません。

例

次の例では、新しいpages子要素が、指定されたbookに含まれるノードを使用して、contosoBooks.xml ファイル内の最初のXPathNavigator要素の子要素の一覧に追加されます。 http://www.contoso.com/books名前空間を指定して、XML ドキュメントと同じ名前空間を使用して新しい子要素を追加します。

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)

この例では、 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>

注釈

子ノードを追加すると、現在のノードの子ノードの一覧の末尾に新しいノードが追加されます。 たとえば、要素に対して 3 つの子ノードが存在する場合、追加されたノードは 4 番目の子ノードになります。 子ノードが存在しない場合は、新しい子ノードが作成されます。

AppendChildメソッドを使用する際に考慮すべき重要な注意事項を次に示します。

  • XPathNavigator オブジェクトが一連の XML ノード上に配置されている場合、シーケンス内のすべてのノードが追加されます。

  • AppendChild メソッドは、ルート ノードまたは要素ノードにXPathNavigatorが配置されている場合にのみ有効です。

  • AppendChildメソッドは、XPathNavigatorの位置には影響しません。

適用対象