' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
﻿Imports System
Imports System.IO
Imports System.Xml

Namespace E
    Public Class Program
        Public Shared Sub Main(args As String())
            Using sw As New StreamWriter("\work\out.xml")
                Using sr As New StreamReader("\work\in.xml")
                    Dim xws As New XmlWriterSettings()
                    xws.Indent = True
                    Dim xw As XmlWriter = XmlWriter.Create(sw, xws)
                    xw.WriteStartDocument()
                    Dim xr As XmlReader = New XmlTextReader(sr)
                    While xr.Read()
                        Select Case xr.NodeType
                            Case XmlNodeType.Element
                                xw.WriteStartElement(xr.Name)
                                If xr.MoveToFirstAttribute() Then
                                    Do
                                        xw.WriteAttributeString(xr.Name, xr.Value)
                                    Loop While xr.MoveToNextAttribute()
                                End If
                                Exit Select
                            Case XmlNodeType.EndElement
                                xw.WriteEndElement()
                                Exit Select
                            Case XmlNodeType.Text
                                xw.WriteString(xr.Value)
                                Exit Select
                        End Select
                    End While
                    xr.Close()
                    xw.WriteEndDocument()
                    xw.Close()
                End Using
            End Using
        End Sub
    End Class
End Namespace
