XPathNavigator.PrependChild Méthode

Définition

Crée un nœud enfant au début de la liste des nœuds enfants du nœud actuel.

Surcharges

Nom Description
PrependChild()

Retourne un XmlWriter objet utilisé pour créer un nœud enfant au début de la liste des nœuds enfants du nœud actuel.

PrependChild(String)

Crée un nœud enfant au début de la liste des nœuds enfants du nœud actuel à l’aide de la chaîne XML spécifiée.

PrependChild(XmlReader)

Crée un nœud enfant au début de la liste des nœuds enfants du nœud actuel à l’aide du contenu XML de l’objet XmlReader spécifié.

PrependChild(XPathNavigator)

Crée un nœud enfant au début de la liste des nœuds enfants du nœud actuel à l’aide des nœuds dans l’objet XPathNavigator spécifié.

PrependChild()

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 enfant au début de la liste des nœuds enfants du nœud actuel.

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

Retours

Objet XmlWriter utilisé pour créer un nœud enfant au début de la liste des nœuds enfants du nœud actuel.

Exceptions

Le nœud actuel sur lequel il XPathNavigator est positionné n’autorise pas l’ajout d’un nouveau nœud enfant.

La XPathNavigator modification ne prend pas en charge la modification.

Exemples

Dans l’exemple suivant, un nouvel pages élément enfant est ajouté au début de la liste des éléments enfants du premier book élément du contosoBooks.xml fichier à l’aide de l’objet XmlWriter retourné par la PrependChild 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");

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)

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

L’ajout préalable d’un nœud enfant au début de la liste des nœuds enfants pour le nœud actuel est ajouté au nouveau nœud. Par exemple, quand trois nœuds enfants existent pour un élément, le nœud prépendé devient le premier nœud enfant. Si aucun nœud enfant n’existe, un nouveau nœud enfant est créé.

Les remarques suivantes sont importantes à prendre en compte lors de l’utilisation de la PrependChild méthode.

S’applique à

PrependChild(String)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

Crée un nœud enfant au début de la liste des nœuds enfants du nœud actuel à l’aide de la chaîne XML spécifiée.

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)

Paramètres

newChild
String

Chaîne de données XML pour le nouveau nœud enfant.

Exceptions

Le paramètre de chaîne XML est null.

Le nœud actuel sur lequel il XPathNavigator est positionné n’autorise pas l’ajout d’un nouveau nœud enfant.

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 enfant est ajouté au début de la liste des éléments enfants 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.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)

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

L’ajout préalable d’un nœud enfant au début de la liste des nœuds enfants pour le nœud actuel est ajouté au nouveau nœud. Par exemple, quand trois nœuds enfants existent pour un élément, le nœud prépendé devient le premier nœud enfant. Si aucun nœud enfant n’existe, un nouveau nœud enfant est créé.

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 PrependChild("<book/>"). La chaîne permettant d’ajouter le texte « book » au nœud de texte du nœud actuel est PrependChild("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 PrependChild méthode.

S’applique à

PrependChild(XmlReader)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

Crée un nœud enfant au début de la liste des nœuds enfants du nœud actuel à l’aide du contenu XML de l’objet XmlReader spécifié.

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)

Paramètres

newChild
XmlReader

Objet XmlReader positionné sur les données XML du nouveau nœud enfant.

Exceptions

L’objet XmlReader est dans un état d’erreur ou fermé.

Le XmlReader paramètre d’objet est null.

Le nœud actuel sur lequel il XPathNavigator est positionné n’autorise pas l’ajout d’un nouveau nœud enfant.

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 enfant est ajouté au début de la liste des éléments enfants 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 enfant soit ajouté à 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");

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)

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

L’ajout préalable d’un nœud enfant au début de la liste des nœuds enfants pour le nœud actuel est ajouté au nouveau nœud. Par exemple, quand trois nœuds enfants existent pour un élément, le nœud prépendé devient le premier nœud enfant. Si aucun nœud enfant n’existe, un nouveau nœud enfant est créé.

Les remarques suivantes sont importantes à prendre en compte lors de l’utilisation de la PrependChild 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 PrependChild méthode est valide uniquement lorsque l’élément XPathNavigator est positionné sur un nœud d’élément.

  • La PrependChild méthode n’affecte pas la position du XPathNavigator.

S’applique à

PrependChild(XPathNavigator)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

Crée un nœud enfant au début de la liste des nœuds enfants du nœud actuel à l’aide des nœuds dans l’objet XPathNavigator spécifié.

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)

Paramètres

newChild
XPathNavigator

Objet XPathNavigator positionné sur le nœud à ajouter en tant que nouveau nœud enfant.

Exceptions

Le XPathNavigator paramètre d’objet est null.

Le nœud actuel sur lequel il XPathNavigator est positionné n’autorise pas l’ajout d’un nouveau nœud enfant.

La XPathNavigator modification ne prend pas en charge la modification.

Exemples

Dans l’exemple suivant, un nouvel pages élément enfant est ajouté au début de la liste des éléments enfants 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 enfant soit ajouté à 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");

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)

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

L’ajout préalable d’un nœud enfant au début de la liste des nœuds enfants pour le nœud actuel est ajouté au nouveau nœud. Par exemple, quand trois nœuds enfants existent pour un élément, le nœud prépendé devient le premier nœud enfant. Si aucun nœud enfant n’existe, un nouveau nœud enfant est créé.

Les remarques suivantes sont importantes à prendre en compte lors de l’utilisation de la PrependChild méthode.

S’applique à