System.Xml.XPath.XPathNavigator.InsertElementBefore Method

Creates a new sibling element before the current node using the namespace prefix, local name, and namespace URI specified, with the value specified.

Syntax

public virtual void InsertElementBefore (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

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

Example

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

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

The following are important notes to consider when using the XPathNavigator.InsertElementBefore(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