System.Xml.XPath.XPathNavigator.CreateAttributes Method

Returns an System.Xml.XmlWriter object used to create new attributes on the current element.

Syntax

public virtual System.Xml.XmlWriter CreateAttributes ()

Returns

An System.Xml.XmlWriter object used to create new attributes on the current element.

Remarks

The following are important notes to consider when using the XPathNavigator.CreateAttributes method.

  • When the System.Xml.XPath.XPathNavigator is positioned on an element, the new attributes created by the System.Xml.XPath.XPathNavigator method are placed at the end of the attribute list of the current element.

  • The new attributes are not inserted until the System.Xml.XmlWriter.Close method of the System.Xml.XmlWriter object is called.

  • If the namespace prefix specified is string.Empty or null, the prefix for the namespace URI of the new attribute is obtained from the current namespaces in-scope. If there is no namespace prefix assigned to the specified namespace URI at the current scope, a namespace prefix is automatically generated. For example to create a new attribute on an element in the default namespace of the contosoBooks.xml file, (xmlns="http://www.contoso.com/books"), you specify null or string.Empty for both the namespace prefix and namespace URI parameters. Specifying http://www.contoso.com/books as the namespace URI parameter will cause the XPathNavigator.CreateAttribute(string, string, string, string) method to auto generate a namespace prefix for the new attribute.

  • If the new attribute created is a namespace node which conflicts with a namespace declaration on the element, either because the namespace prefix chosen is used by another namespace declaration at the same scope, or because the prefix chosen is the same as that of the element but is bound to a different namespace URI, an exception is thrown.

  • The System.Xml.XmlWriter object returned may only be used to create attributes. Calling other System.Xml.XmlWriter object methods that do not create attributes throws an exception.

  • The XPathNavigator.CreateAttributes method does not affect the position of the System.Xml.XPath.XPathNavigator.

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