XmlWriter.WriteAttributeString Method (String, String, String)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
When overridden in a derived class, writes an attribute with the specified local name, namespace URI, and value.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- localName
- Type: System.String
The local name of the attribute.
- ns
- Type: System.String
The namespace URI to associate with the attribute.
- value
- Type: System.String
The value of the attribute.
| Exception | Condition |
|---|---|
| InvalidOperationException | The state of writer is not WriteState.Element or writer is closed. |
| ArgumentException | The xml:space or xml:lang attribute value is invalid. |
This method writes out the attribute with a user defined namespace prefix and associates it with the given namespace. If localName is "xmlns" then this method also treats this as a namespace declaration. 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.