XPathNavigator.PrependChild メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
現在のノードの子ノードの一覧の先頭に新しい子ノードを作成します。
オーバーロード
| 名前 | 説明 |
|---|---|
| PrependChild() |
現在のノードの子ノードの一覧の先頭に新しい子ノードを作成するために使用する XmlWriter オブジェクトを返します。 |
| PrependChild(String) |
指定された XML 文字列を使用して、現在のノードの子ノードの一覧の先頭に新しい子ノードを作成します。 |
| PrependChild(XmlReader) |
指定した XmlReader オブジェクトの XML コンテンツを使用して、現在のノードの子ノードの一覧の先頭に新しい子ノードを作成します。 |
| PrependChild(XPathNavigator) |
指定した XPathNavigator オブジェクトのノードを使用して、現在のノードの子ノードの一覧の先頭に新しい子ノードを作成します。 |
PrependChild()
現在のノードの子ノードの一覧の先頭に新しい子ノードを作成するために使用する XmlWriter オブジェクトを返します。
public:
virtual System::Xml::XmlWriter ^ PrependChild();
public virtual System.Xml.XmlWriter PrependChild();
abstract member PrependChild : unit -> System.Xml.XmlWriter
override this.PrependChild : unit -> System.Xml.XmlWriter
Public Overridable Function PrependChild () As XmlWriter
返品
現在のノードの子ノードの一覧の先頭に新しい子ノードを作成するために使用される XmlWriter オブジェクト。
例外
XPathNavigatorが配置されている現在のノードでは、新しい子ノードの先頭に追加できません。
XPathNavigatorは編集をサポートしていません。
例
次の例では、新しいpages子要素が、PrependChild メソッドから返されたXmlWriter オブジェクトを使用して、contosoBooks.xml ファイル内の最初のbook要素の子要素の一覧の先頭に付加されます。
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.PrependChild();
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.PrependChild()
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 つの子ノードが存在する場合、先頭に追加されたノードが最初の子ノードになります。 子ノードが存在しない場合は、新しい子ノードが作成されます。
PrependChildメソッドを使用する際に考慮すべき重要な注意事項を次に示します。
PrependChild メソッドは、XPathNavigatorが要素ノードに配置されている場合にのみ有効です。
PrependChildメソッドは、XPathNavigatorの位置には影響しません。
適用対象
PrependChild(String)
指定された XML 文字列を使用して、現在のノードの子ノードの一覧の先頭に新しい子ノードを作成します。
public:
virtual void PrependChild(System::String ^ newChild);
public virtual void PrependChild(string newChild);
abstract member PrependChild : string -> unit
override this.PrependChild : string -> unit
Public Overridable Sub PrependChild (newChild As String)
パラメーター
- newChild
- String
新しい子ノードの XML データ文字列。
例外
XML 文字列パラメーターが null。
XPathNavigatorが配置されている現在のノードでは、新しい子ノードの先頭に追加できません。
XPathNavigatorは編集をサポートしていません。
XML 文字列パラメーターは整形式ではありません。
例
次の例では、新しいpages子要素が、contosoBooks.xml ファイル内の最初のbook要素の子要素の一覧の先頭に付加されます。
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.PrependChild("<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.PrependChild("<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 つの子ノードが存在する場合、先頭に追加されたノードが最初の子ノードになります。 子ノードが存在しない場合は、新しい子ノードが作成されます。
新しい要素ノードを作成するには、XML 文字列パラメーターにすべての XML 構文を含めます。 新しい book ノードの文字列が PrependChild("<book/>")。 現在のノードのテキスト ノードにテキスト "book" を追加するための文字列が PrependChild("book")。 XML 文字列に複数のノードが含まれている場合は、すべてのノードが追加されます。
PrependChildメソッドを使用する際に考慮すべき重要な注意事項を次に示します。
PrependChild メソッドは、XPathNavigatorが要素ノードに配置されている場合にのみ有効です。
PrependChildメソッドは、XPathNavigatorの位置には影響しません。
適用対象
PrependChild(XmlReader)
指定した XmlReader オブジェクトの XML コンテンツを使用して、現在のノードの子ノードの一覧の先頭に新しい子ノードを作成します。
public:
virtual void PrependChild(System::Xml::XmlReader ^ newChild);
public virtual void PrependChild(System.Xml.XmlReader newChild);
abstract member PrependChild : System.Xml.XmlReader -> unit
override this.PrependChild : System.Xml.XmlReader -> unit
Public Overridable Sub PrependChild (newChild As XmlReader)
パラメーター
例外
XmlReader オブジェクトがエラー状態であるか、閉じられています。
XmlReader オブジェクト パラメーターはnull。
XPathNavigatorが配置されている現在のノードでは、新しい子ノードの先頭に追加できません。
XPathNavigatorは編集をサポートしていません。
XmlReader オブジェクト パラメーターの XML コンテンツが整形式ではありません。
例
次の例では、指定されたXmlReader オブジェクトを使用して、contosoBooks.xml ファイル内の最初のbook要素の子要素のリストの先頭に新しいpages子要素が付加されます。
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.PrependChild(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.PrependChild(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 つの子ノードが存在する場合、先頭に追加されたノードが最初の子ノードになります。 子ノードが存在しない場合は、新しい子ノードが作成されます。
PrependChildメソッドを使用する際に考慮すべき重要な注意事項を次に示します。
XmlReader オブジェクトが一連の XML ノード上に配置されている場合、シーケンス内のすべてのノードが追加されます。
PrependChild メソッドは、XPathNavigatorが要素ノードに配置されている場合にのみ有効です。
PrependChildメソッドは、XPathNavigatorの位置には影響しません。
適用対象
PrependChild(XPathNavigator)
指定した XPathNavigator オブジェクトのノードを使用して、現在のノードの子ノードの一覧の先頭に新しい子ノードを作成します。
public:
virtual void PrependChild(System::Xml::XPath::XPathNavigator ^ newChild);
public virtual void PrependChild(System.Xml.XPath.XPathNavigator newChild);
abstract member PrependChild : System.Xml.XPath.XPathNavigator -> unit
override this.PrependChild : System.Xml.XPath.XPathNavigator -> unit
Public Overridable Sub PrependChild (newChild As XPathNavigator)
パラメーター
- newChild
- XPathNavigator
新しい子ノードとして追加するノード上に配置された XPathNavigator オブジェクト。
例外
XPathNavigator オブジェクト パラメーターはnull。
XPathNavigatorが配置されている現在のノードでは、新しい子ノードの先頭に追加できません。
XPathNavigatorは編集をサポートしていません。
例
次の例では、新しいpages子要素が、指定されたXPathNavigator オブジェクトに含まれるノードを使用して、contosoBooks.xml ファイル内の最初のbook要素の子要素の一覧の先頭に付加されます。
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();
navigator.PrependChild(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()
navigator.PrependChild(childNodesNavigator)
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 つの子ノードが存在する場合、先頭に追加されたノードが最初の子ノードになります。 子ノードが存在しない場合は、新しい子ノードが作成されます。
PrependChildメソッドを使用する際に考慮すべき重要な注意事項を次に示します。
XPathNavigator オブジェクトが一連の XML ノード上に配置されている場合、シーケンス内のすべてのノードが追加されます。
PrependChild メソッドは、XPathNavigatorが要素ノードに配置されている場合にのみ有効です。
PrependChildメソッドは、XPathNavigatorの位置には影響しません。