System.Xml.XmlWriter.WriteAttributes Method

When overridden in a derived class, writes out all the attributes found at the current position in the System.Xml.XmlReader.

Syntax

public virtual void WriteAttributes (XmlReader reader, bool defattr)

Parameters

reader
The XmlReader from which to copy the attributes.
defattr
true to copy the default attributes from the XmlReader; otherwise, false.

Exceptions

TypeReason
ArgumentNullException reader is null.
InvalidOperationExceptionThe XmlWriter.WriteState is WriteState.Closed.
System.Xml.XmlException reader is not positioned on a node of System.Xml.XmlNodeTypeAttribute, Element, or XmlDeclaration.

Remarks

If the reader is positioned on an element node WriteAttributes copies all the contained attributes. If the reader is positioned on an attribute node, this method writes the current attribute, then the rest of the attributes until the element closing tag. If the reader is positioned on an XmlDeclaration node, this method writes all the attributes in the declaration. If the reader is positioned on any other node type this method throws an System.Xml.XmlException.

If this method is called using System.Xml.XmlValidatingReader, to ensure well-formed XML any content (which has been expanded from the entities) that could result in an invalid document is replaced when written. For example, if an attribute includes an > entity that has been expanded, to ensure a well-formed document the expanded > is replaced when written out with >.

For the asynchronous version of this method, see XmlWriter.WriteAttributesAsync(XmlReader, bool).

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