// 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) using System; using System.IO; using System.Xml; namespace E { public class Program { public static void Main(string[] args) { using(StreamWriter sw = new StreamWriter(@"\work\out.xml")) using(StreamReader sr = new StreamReader(@"\work\in.xml")) { XmlWriterSettings xws = new XmlWriterSettings(); xws.Indent = true; XmlWriter xw = XmlWriter.Create(sw, xws); xw.WriteStartDocument(); XmlReader xr = new XmlTextReader(sr); while(xr.Read()) { switch(xr.NodeType) { case XmlNodeType.Element: xw.WriteStartElement(xr.Name); if(xr.MoveToFirstAttribute()) { do { xw.WriteAttributeString(xr.Name, xr.Value); } while(xr.MoveToNextAttribute()); } break; case XmlNodeType.EndElement: xw.WriteEndElement(); break; case XmlNodeType.Text: xw.WriteString(xr.Value); break; } } xr.Close(); xw.WriteEndDocument(); xw.Close(); } } } }