System.Xml.XPath.XPathNavigator.AppendChildElement Method

Creates a new child element node at the end 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 AppendChildElement (string prefix, string localName, string namespaceURI, string value)

Parameters

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

Remarks

Appending a child node adds the new node to the end of the list of child nodes for the current node. For example, when three child nodes exist for an element node, the appended node becomes the fourth 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) method or the XPathNavigator.LookupNamespace(string) method. For example, the following syntax appends a child element by using the in-scope namespace xmlns:bk=http://www.contoso.com/books:

Example

navigator.AppendChildElement(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.AppendChildElement(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