XmlWriter.WriteAttributes Method

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

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

Public Overridable Sub WriteAttributes ( _
	reader As XmlReader, _
	defattr As Boolean _


Type: System.Xml.XmlReader
The XmlReader from which to copy the attributes.
Type: System.Boolean
true to copy the default attributes from the XmlReader; otherwise, false.


reader is Nothing.


The reader is not positioned on an element, attribute or XmlDeclaration node.

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 XmlException.

Dim output As New StringBuilder()

Dim xmlString As String = _
    "<bookstore>" & _
      "<book genre='novel' ISBN='10-861003-324'>" & _
        "<title>The Handmaid's Tale</title>" & _
        "<price>19.95</price>" & _
      "</book>" & _
      "<book genre='novel' ISBN='1-861001-57-5'>" & _
        "<title>Pride And Prejudice</title>" & _
        "<price>24.95</price>" & _
      "</book>" & _

Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))

    Dim settings As New XmlWriterSettings()
    settings.Indent = True
    Using writer As XmlWriter = XmlWriter.Create(output)

        While reader.Read()
            If reader.NodeType = XmlNodeType.Element Then
                writer.WriteAttributes(reader, False)
                If reader.IsEmptyElement Then
                End If
                If reader.NodeType = XmlNodeType.EndElement Then
                End If
            End If
        End While
    End Using
End Using

OutputTextBlock.Text = output.ToString()


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions