System.Xml.XPath.XPathNavigator.PrependChildElement Method

Creates a new child element at the beginning of the list of child nodes of the current node using the namespace prefix, local name, and namespace URI specified with the value specified.

Syntax

public virtual void PrependChildElement (string prefix, string localName, string namespaceURI, string value)

Parameters

prefix
The namespace prefix of the new child element (if any).
localName
The local name of the new child element (if any).
namespaceURI
The namespace URI of the new child element (if any). string.Empty and null are equivalent.
value
The value of the new child element. If string.Empty or null are passed, an empty element is created.

Remarks

Prepending a child node adds the new node to the beginning of the list of child nodes for the current node. For example, when three child nodes exist for an element, the prepended node becomes the first child node. If no child nodes exist, then a new child node is created.

Namespace prefix and URI values can be obtained by using the XPathNavigator.LookupPrefix(string) or XPathNavigator.LookupNamespace(string) method. For example, the following syntax prepends a child element by using the in-scope namespace xmlns:bk="http://www.contoso.com/books":

Example

navigator.PrependChildElement(navigator.Prefix, "pages", LookupNamespaceURI(navigator.Prefix), String.Empty)

This creates the new child <bk:pages/> element.

The following are important notes to consider when using the XPathNavigator.PrependChildElement(string, string, string, string) method.

Requirements

Namespace: System.Xml.XPath
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0