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.
- 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.
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.
If the namespace prefix specified is null or string.Empty, then the prefix for the namespace URI of the new element is obtained from the current namespaces in-scope. If there is no namespace prefix assigned to the specified namespace URI at the current scope, then a namespace prefix is automatically generated.
The XPathNavigator.AppendChildElement(string, string, string, string) method is valid only when the System.Xml.XPath.XPathNavigator is positioned on the root node or an element node.
The XPathNavigator.AppendChildElement(string, string, string, string) method does not affect the position of the System.Xml.XPath.XPathNavigator.