Creates a new sibling element after 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 (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.
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.InsertElementAfter(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.InsertElementAfter(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.InsertElementAfter(string, string, string, string) method is valid only when the System.Xml.XPath.XPathNavigator is positioned on an element, text, processing instruction, or comment node.
The XPathNavigator.InsertElementAfter(string, string, string, string) method does not affect the position of the System.Xml.XPath.XPathNavigator.