XPathNavigator.InsertBefore 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 avant le nœud actuellement sélectionné.
Surcharges
| Nom | Description |
|---|---|
| InsertBefore() |
Retourne un XmlWriter objet utilisé pour créer un nœud frère avant le nœud actuellement sélectionné. |
| InsertBefore(String) |
Crée un nœud frère avant le nœud actuellement sélectionné à l’aide de la chaîne XML spécifiée. |
| InsertBefore(XmlReader) |
Crée un nœud frère avant le nœud actuellement sélectionné à l’aide du contenu XML de l’objet XmlReader spécifié. |
| InsertBefore(XPathNavigator) |
Crée un nœud frère avant le nœud actuellement sélectionné à l’aide des nœuds dans le XPathNavigator fichier spécifié. |
InsertBefore()
- 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 avant le nœud actuellement sélectionné.
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
Retours
Objet XmlWriter utilisé pour créer un nœud frère avant 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 avant 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é avant l’élément price enfant du premier book élément du contosoBooks.xml fichier à l’aide de l’objet XmlWriter retourné par la InsertBefore 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.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)
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 InsertBefore 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 InsertBefore 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 InsertBefore méthode n’affecte pas la position du XPathNavigator.
S’applique à
InsertBefore(String)
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
Crée un nœud frère avant le nœud actuellement sélectionné à l’aide de la chaîne XML spécifiée.
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)
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 avant 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é avant 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.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)
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 InsertBefore("<book/>"). Chaîne permettant d’insérer le texte « book » avant que le nœud de texte du nœud actuel soit InsertBefore("book"). 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 InsertBefore méthode.
La InsertBefore 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 InsertBefore méthode n’affecte pas la position du XPathNavigator.
S’applique à
InsertBefore(XmlReader)
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
Crée un nœud frère avant le nœud actuellement sélectionné à l’aide du contenu XML de l’objet XmlReader spécifié.
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)
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 avant 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é avant l’élément price enfant du premier book élément du contosoBooks.xml fichier à l’aide 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.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)
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 InsertBefore 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 InsertBefore 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 InsertBefore méthode n’affecte pas la position du XPathNavigator.
S’applique à
InsertBefore(XPathNavigator)
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
Crée un nœud frère avant le nœud actuellement sélectionné à l’aide des nœuds dans le XPathNavigator fichier spécifié.
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)
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 avant 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é avant 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.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)
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 InsertBefore méthode.
Si l’objet XPathNavigator est positionné sur une séquence de nœuds XML, tous les nœuds de la séquence sont ajoutés.
La InsertBefore 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 InsertBefore méthode n’affecte pas la position du XPathNavigator.