XPathNavigator.InsertBefore メソッド
定義
現在選択されているノードの前に新しい兄弟ノードを作成します。Creates a new sibling node before the currently selected node.
オーバーロード
InsertBefore() |
現在選択されているノードの前に新しい兄弟ノードを作成するために使用する XmlWriter オブジェクトを返します。Returns an XmlWriter object used to create a new sibling node before the currently selected node. |
InsertBefore(String) |
指定された XML 文字列を使用して、現在選択されているノードの前に新しい兄弟ノードを作成します。Creates a new sibling node before the currently selected node using the XML string specified. |
InsertBefore(XmlReader) |
指定された XmlReader オブジェクトの XML の内容を使用して、現在選択されているノードの前に新しい兄弟ノードを作成します。Creates a new sibling node before the currently selected node using the XML contents of the XmlReader object specified. |
InsertBefore(XPathNavigator) |
指定された XPathNavigator のノードを使用して、現在選択されているノードの前に新しい兄弟ノードを作成します。Creates a new sibling node before the currently selected node using the nodes in the XPathNavigator specified. |
InsertBefore()
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
戻り値
現在選択されているノードの前に新しい兄弟ノードを作成するために使用する XmlWriter オブジェクト。An XmlWriter object used to create a new sibling node before the currently selected node.
例外
XPathNavigator の位置には、現在のノードの前に新しい兄弟ノードを挿入できません。The position of the XPathNavigator does not allow a new sibling node to be inserted before the current node.
XPathNavigator では、編集はサポートされていません。The XPathNavigator does not support editing.
例
次の例では、 pages
price
book
contosoBooks.xml
XmlWriter メソッドによって返されたオブジェクトを使用して、ファイル内の最初の要素の子要素の前に新しい要素が挿入されてい InsertBefore ます。In the following example a new pages
element is inserted before the price
child element of the first book
element in the contosoBooks.xml
file using the XmlWriter object returned by the InsertBefore method.
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)
この例は、contosoBooks.xml
ファイルを入力として使用します。The example takes the contosoBooks.xml
file as an input.
<?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>
注釈
ここでは、メソッドを使用する際に考慮する必要がある重要な注意事項について説明し InsertBefore ます。The following are important notes to consider when using the InsertBefore method.
新しい兄弟ノードは、オブジェクトのメソッドが呼び出されるまで挿入されません Close XmlWriter 。The new sibling node is not inserted until the Close method of the XmlWriter object is called.
InsertBeforeメソッドは、 XPathNavigator が要素、テキスト、処理命令、またはコメントノードに配置されている場合にのみ有効です。The InsertBefore method is valid only when the XPathNavigator is positioned on an element, text, processing instruction, or comment node.
InsertBeforeメソッドは、の位置には影響しません XPathNavigator 。The InsertBefore method does not affect the position of the XPathNavigator.
適用対象
InsertBefore(String)
指定された XML 文字列を使用して、現在選択されているノードの前に新しい兄弟ノードを作成します。Creates a new sibling node before the currently selected node using the XML string specified.
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)
パラメーター
- newSibling
- String
新しい兄弟ノード用の XML データ文字列。The XML data string for the new sibling node.
例外
XML 文字列パラメーターは null
です。The XML string parameter is null
.
XPathNavigator の位置には、現在のノードの前に新しい兄弟ノードを挿入できません。The position of the XPathNavigator does not allow a new sibling node to be inserted before the current node.
XPathNavigator では、編集はサポートされていません。The XPathNavigator does not support editing.
XML 文字列パラメーターは整形式ではありません。The XML string parameter is not well-formed.
例
次の例では、新しい pages
要素が price
ファイル内の最初の book
要素の contosoBooks.xml
子要素の前に挿入されます。In the following example a new pages
element is inserted before the price
child element of the first book
element in the contosoBooks.xml
file.
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)
この例は、contosoBooks.xml
ファイルを入力として使用します。The example takes the contosoBooks.xml
file as an input.
<?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>
注釈
新しい要素ノードを作成するには、XML 文字列パラメーターにすべての XML 構文を含めます。To create a new element node, include all XML syntax in the XML string parameter. 新しいノードの文字列 book
は InsertBefore("<book/>")
です。The string for a new book
node is InsertBefore("<book/>")
. 現在のノードのテキストノードの前に "book" というテキストを挿入するための文字列 InsertBefore("book")
。The string for inserting the text "book" before the current node's text node is InsertBefore("book")
. XML 文字列に複数のノードが含まれている場合は、すべてのノードが追加されます。If the XML string contains multiple nodes, all nodes are added.
ここでは、メソッドを使用する際に考慮する必要がある重要な注意事項について説明し InsertBefore ます。The following are important notes to consider when using the InsertBefore method.
InsertBeforeメソッドは、 XPathNavigator が要素、テキスト、処理命令、またはコメントノードに配置されている場合にのみ有効です。The InsertBefore method is valid only when the XPathNavigator is positioned on an element, text, processing instruction, or comment node.
InsertBeforeメソッドは、の位置には影響しません XPathNavigator 。The InsertBefore method does not affect the position of the XPathNavigator.
適用対象
InsertBefore(XmlReader)
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)
パラメーター
- newSibling
- XmlReader
新しい兄弟ノード用の XML データに配置された XmlReader オブジェクト。An XmlReader object positioned on the XML data for the new sibling node.
例外
XPathNavigator の位置には、現在のノードの前に新しい兄弟ノードを挿入できません。The position of the XPathNavigator does not allow a new sibling node to be inserted before the current node.
XPathNavigator では、編集はサポートされていません。The XPathNavigator does not support editing.
XmlReader オブジェクト パラメーターの XML コンテンツは整形式ではありません。The XML contents of the XmlReader object parameter is not well-formed.
例
次の例では、 pages
price
book
contosoBooks.xml
指定されたオブジェクトを使用して、ファイル内の最初の要素の子要素の前に新しい要素が挿入されてい XmlReader ます。In the following example a new pages
element is inserted before the price
child element of the first book
element in the contosoBooks.xml
file using the XmlReader object specified. http://www.contoso.com/books
名前空間は、XML ドキュメントと同じ名前空間を使用して新しい兄弟要素が挿入されるように指定されています。The http://www.contoso.com/books
namespace is specified so that the new sibling element is inserted using the same namespace as the XML document.
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)
この例は、contosoBooks.xml
ファイルを入力として使用します。The example takes the contosoBooks.xml
file as an input.
<?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>
注釈
ここでは、メソッドを使用する際に考慮する必要がある重要な注意事項について説明し InsertBefore ます。The following are important notes to consider when using the InsertBefore method.
オブジェクトが一連の XML ノードの上に配置されている場合は、 XmlReader シーケンス内のすべてのノードが追加されます。If the XmlReader object is positioned over a sequence of XML nodes, all the nodes in the sequence are added.
InsertBeforeメソッドは、 XPathNavigator が要素、テキスト、処理命令、またはコメントノードに配置されている場合にのみ有効です。The InsertBefore method is valid only when the XPathNavigator is positioned on an element, text, processing instruction, or comment node.
InsertBeforeメソッドは、の位置には影響しません XPathNavigator 。The InsertBefore method does not affect the position of the XPathNavigator.
適用対象
InsertBefore(XPathNavigator)
指定された XPathNavigator のノードを使用して、現在選択されているノードの前に新しい兄弟ノードを作成します。Creates a new sibling node before the currently selected node using the nodes in the XPathNavigator specified.
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)
パラメーター
- newSibling
- XPathNavigator
新しい兄弟ノードとして追加するノードに配置されている XPathNavigator オブジェクト。An XPathNavigator object positioned on the node to add as the new sibling node.
例外
XPathNavigator オブジェクトのパラメーターは null
です。The XPathNavigator object parameter is null
.
XPathNavigator の位置には、現在のノードの前に新しい兄弟ノードを挿入できません。The position of the XPathNavigator does not allow a new sibling node to be inserted before the current node.
XPathNavigator では、編集はサポートされていません。The XPathNavigator does not support editing.
例
次の例では、 pages
price
book
指定された contosoBooks.xml
オブジェクトに含まれるノードを使用して、ファイル内の最初の要素の子要素の前に新しい要素が挿入され XPathNavigator ます。In the following example a new pages
element is inserted before the price
child element of the first book
element in the contosoBooks.xml
file using the node contained in the XPathNavigator object specified. http://www.contoso.com/books
名前空間は、XML ドキュメントと同じ名前空間を使用して新しい兄弟要素が挿入されるように指定されています。The http://www.contoso.com/books
namespace is specified so that the new sibling element is inserted using the same namespace as the XML document.
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)
この例は、contosoBooks.xml
ファイルを入力として使用します。The example takes the contosoBooks.xml
file as an input.
<?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>
注釈
ここでは、メソッドを使用する際に考慮する必要がある重要な注意事項について説明し InsertBefore ます。The following are important notes to consider when using the InsertBefore method.
オブジェクトが一連の XML ノードの上に配置されている場合は、 XPathNavigator シーケンス内のすべてのノードが追加されます。If the XPathNavigator object is positioned over a sequence of XML nodes, all the nodes in the sequence are added.
InsertBeforeメソッドは、 XPathNavigator が要素、テキスト、処理命令、またはコメントノードに配置されている場合にのみ有効です。The InsertBefore method is valid only when the XPathNavigator is positioned on an element, text, processing instruction, or comment node.
InsertBeforeメソッドは、の位置には影響しません XPathNavigator 。The InsertBefore method does not affect the position of the XPathNavigator.