XPathNavigator.InsertAfter Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Crée un nœud frère après le nœud actuellement sélectionné.
Surcharges
| Nom | Description |
|---|---|
| InsertAfter(XPathNavigator) |
Crée un nœud frère après le nœud actuellement sélectionné à l’aide des nœuds de l’objet XPathNavigator spécifié. |
| InsertAfter(XmlReader) |
Crée un nœud frère après le nœud actuellement sélectionné à l’aide du contenu XML de l’objet XmlReader spécifié. |
| InsertAfter() |
Retourne un XmlWriter objet utilisé pour créer un nœud frère après le nœud actuellement sélectionné. |
| InsertAfter(String) |
Crée un nœud frère après le nœud actuellement sélectionné à l’aide de la chaîne XML spécifiée. |
InsertAfter(XPathNavigator)
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
Crée un nœud frère après le nœud actuellement sélectionné à l’aide des nœuds de l’objet XPathNavigator spécifié.
public:
virtual void InsertAfter(System::Xml::XPath::XPathNavigator ^ newSibling);
public virtual void InsertAfter(System.Xml.XPath.XPathNavigator newSibling);
abstract member InsertAfter : System.Xml.XPath.XPathNavigator -> unit
override this.InsertAfter : System.Xml.XPath.XPathNavigator -> unit
Public Overridable Sub InsertAfter (newSibling As XPathNavigator)
Paramètres
- newSibling
- XPathNavigator
Objet XPathNavigator positionné sur le nœud à ajouter en tant que nouveau nœud frère.
Exceptions
Le XPathNavigator paramètre d’objet est null.
La position du XPathNavigator nœud n’autorise pas l’insertion d’un nouveau nœud frère après le nœud actuel.
La XPathNavigator modification ne prend pas en charge la modification.
Exemples
Dans l’exemple suivant, un nouvel pages élément est inséré après l’élément price enfant du premier book élément du contosoBooks.xml fichier à l’aide du nœud contenu dans l’objet XPathNavigator spécifié. L’espace http://www.contoso.com/books de noms est spécifié afin que le nouvel élément frère soit inséré à l’aide du même espace de noms que le document 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.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.InsertAfter(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.InsertAfter(childNodesNavigator)
navigator.MoveToParent()
Console.WriteLine(navigator.OuterXml)
L’exemple prend le contosoBooks.xml fichier en tant qu’entrée.
<?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>
Remarques
Les remarques suivantes sont importantes à prendre en compte lors de l’utilisation de la InsertAfter méthode.
Si l’objet XmlReader est positionné sur une séquence de nœuds XML, tous les nœuds de la séquence sont ajoutés.
La InsertAfter méthode n’est valide que lorsque l’élément, le texte, l’instruction XPathNavigator de traitement ou le nœud de commentaire sont positionnés.
La InsertAfter méthode n’affecte pas la position du XPathNavigator.
S’applique à
InsertAfter(XmlReader)
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
Crée un nœud frère après le nœud actuellement sélectionné à l’aide du contenu XML de l’objet XmlReader spécifié.
public:
virtual void InsertAfter(System::Xml::XmlReader ^ newSibling);
public virtual void InsertAfter(System.Xml.XmlReader newSibling);
abstract member InsertAfter : System.Xml.XmlReader -> unit
override this.InsertAfter : System.Xml.XmlReader -> unit
Public Overridable Sub InsertAfter (newSibling As XmlReader)
Paramètres
Exceptions
L’objet XmlReader est dans un état d’erreur ou fermé.
Le XmlReader paramètre d’objet est null.
La position du XPathNavigator nœud n’autorise pas l’insertion d’un nouveau nœud frère après le nœud actuel.
La XPathNavigator modification ne prend pas en charge la modification.
Le contenu XML du XmlReader paramètre objet n’est pas bien formé.
Exemples
Dans l’exemple suivant, un nouvel pages élément est inséré après l’élément price enfant du premier book élément du fichier à l’aide contosoBooks.xml de l’objet XmlReader spécifié. L’espace http://www.contoso.com/books de noms est spécifié afin que le nouvel élément frère soit inséré à l’aide du même espace de noms que le document 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.MoveToChild("price", "http://www.contoso.com/books");
XmlReader pages = XmlReader.Create(new StringReader("<pages xmlns=\"http://www.contoso.com/books\">100</pages>"));
navigator.InsertAfter(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.InsertAfter(pages)
navigator.MoveToParent()
Console.WriteLine(navigator.OuterXml)
L’exemple prend le contosoBooks.xml fichier en tant qu’entrée.
<?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>
Remarques
Les remarques suivantes sont importantes à prendre en compte lors de l’utilisation de la InsertAfter méthode.
Si l’objet XmlReader est positionné sur une séquence de nœuds XML, tous les nœuds de la séquence sont ajoutés.
La InsertAfter méthode n’est valide que lorsque l’élément, le texte, l’instruction XPathNavigator de traitement ou le nœud de commentaire sont positionnés.
La InsertAfter méthode n’affecte pas la position du XPathNavigator.
S’applique à
InsertAfter()
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
Retourne un XmlWriter objet utilisé pour créer un nœud frère après le nœud actuellement sélectionné.
public:
virtual System::Xml::XmlWriter ^ InsertAfter();
public virtual System.Xml.XmlWriter InsertAfter();
abstract member InsertAfter : unit -> System.Xml.XmlWriter
override this.InsertAfter : unit -> System.Xml.XmlWriter
Public Overridable Function InsertAfter () As XmlWriter
Retours
Objet XmlWriter utilisé pour créer un nœud frère après le nœud actuellement sélectionné.
Exceptions
La position du XPathNavigator nœud n’autorise pas l’insertion d’un nouveau nœud frère après le nœud actuel.
La XPathNavigator modification ne prend pas en charge la modification.
Exemples
Dans l’exemple suivant, un nouvel pages élément est inséré après l’élément price enfant du premier book élément du contosoBooks.xml fichier à l’aide de l’objet XmlWriter retourné par la InsertAfter méthode.
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.InsertAfter();
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.InsertAfter()
pages.WriteElementString("pages", "100")
pages.Close()
navigator.MoveToParent()
Console.WriteLine(navigator.OuterXml)
L’exemple prend le contosoBooks.xml fichier en tant qu’entrée.
<?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>
Remarques
Les remarques suivantes sont importantes à prendre en compte lors de l’utilisation de la InsertAfter méthode.
Le nouveau nœud frère n’est pas inséré tant que la Close méthode de l’objet XmlWriter n’est pas appelée.
La InsertAfter méthode n’est valide que lorsque l’élément, le texte, l’instruction XPathNavigator de traitement ou le nœud de commentaire sont positionnés.
La InsertAfter méthode n’affecte pas la position du XPathNavigator.
S’applique à
InsertAfter(String)
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
Crée un nœud frère après le nœud actuellement sélectionné à l’aide de la chaîne XML spécifiée.
public:
virtual void InsertAfter(System::String ^ newSibling);
public virtual void InsertAfter(string newSibling);
abstract member InsertAfter : string -> unit
override this.InsertAfter : string -> unit
Public Overridable Sub InsertAfter (newSibling As String)
Paramètres
- newSibling
- String
Chaîne de données XML pour le nouveau nœud frère.
Exceptions
Le paramètre de chaîne XML est null.
La position du XPathNavigator nœud n’autorise pas l’insertion d’un nouveau nœud frère après le nœud actuel.
La XPathNavigator modification ne prend pas en charge la modification.
Le paramètre de chaîne XML n’est pas bien formé.
Exemples
Dans l’exemple suivant, un nouvel pages élément est inséré après l’élément price enfant du premier book élément du contosoBooks.xml fichier.
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.InsertAfter("<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.InsertAfter("<pages>100</pages>")
navigator.MoveToParent()
Console.WriteLine(navigator.OuterXml)
L’exemple prend le contosoBooks.xml fichier en tant qu’entrée.
<?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>
Remarques
Pour créer un nœud d’élément, incluez toutes les syntaxes XML dans le paramètre de chaîne XML. La chaîne d’un nouveau book nœud est InsertAfter("<book/>"). Chaîne d’insertion du texte « book » après le nœud de texte du nœud InsertAfter("book")actuel . Si la chaîne XML contient plusieurs nœuds, tous les nœuds sont ajoutés.
Les remarques suivantes sont importantes à prendre en compte lors de l’utilisation de la InsertAfter méthode.
La InsertAfter méthode n’est valide que lorsque l’élément, le texte, l’instruction XPathNavigator de traitement ou le nœud de commentaire sont positionnés.
La InsertAfter méthode n’affecte pas la position du XPathNavigator.