System.Xml.XmlWriter.WriteAttributeString Method

When overridden in a derived class, writes out the attribute with the specified prefix, local name, namespace URI, and value.

Syntax

public void WriteAttributeString (string prefix, string localName, string ns, string value)

Parameters

localName
The local name of the attribute.
ns
The namespace URI of the attribute.
value
The value of the attribute.
prefix
The namespace prefix of the attribute.
localName
The local name of the attribute.
ns
The namespace URI of the attribute.
value
The value of the attribute.

Exceptions

TypeReason
ArgumentException localName is null or string.Empty .
InvalidOperationExceptionThe XmlWriter.WriteState is not WriteState.Element.

Remarks

This method writes out the attribute with a user defined namespace prefix and associates it with the given namespace. If the prefix is "xmlns" then this method also treats this as a namespace declaration and associates the declared prefix with the namespace URI provided in the given attribute value. In this case the ns argument can be null.

WriteAttributeString does the following:

  • If the attribute value includes double or single quotes, they are replaced with " and ' respectively.

  • If writing an xml:space attribute, the writer verifies the attribute value is valid. (Valid values are preserve or default.)

  • If writing an xml:lang attribute, the writer does not verify that the attribute value is valid according to the W3C XML 1.0 recommendation.

For the asynchronous version of this method, see XmlWriter.WriteAttributeStringAsync(string, string, string, string).

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0