【IT168技术文档】
1 XmlReader reader = XmlReader.Create(filename); 2 DataSet ds = new DataSet(); 3 ds.ReadXml(filename); 4 XmlWriterSettings ws = new XmlWriterSettings(); 5 ws.Indent = true; 6 XmlWriter writer = XmlWriter.Create(output, ws); 7 while (reader.Read()) 8 { 9 switch (reader.NodeType) 10 { 11 case XmlNodeType.Element: 12 writer.WriteString(reader.Name); 13 break; 14 case XmlNodeType.Text: 15 writer.WriteString(reader.Value); 16 break; 17 case XmlNodeType.XmlDeclaration: 18 case XmlNodeType.ProcessingInstruction: 19 writer.WriteProcessingInstruction(reader.Name, reader.Value); 20 break; 21 case XmlNodeType.Comment: 22 writer.WriteComment(reader.Value); 23 break; 24 case XmlNodeType.EndElement: 25 writer.WriteFullEndElement(); 26 break; 27 } 28 } 29