// Read this properties of element and display them on console Console.WriteLine(Name: + reader.Name); Console.WriteLine(Base URI: + reader.BaseURI); Console.WriteLine(Local Name: + reader.LocalName); Console.WriteLine(Attribute Count: + reader.AttributeCount.ToString()); Console.WriteLine(Depth: + reader.Depth.ToString()); Console.WriteLine(Line Number: + reader.LineNumber.ToString()); Console.WriteLine(Node Type: + reader.NodeType.ToString()); Console.WriteLine(Attribute Count: + reader.Value.ToString()); } } } 二十四、写XML文件: using System; using System.Xml; public class TestWriteXMLFile { public static int Main(string[] args) { try { // Creates an XML file is not exist XmlTextWriter writer = new XmlTextWriter(C:\\temp\\xmltest.xml, null); // Starts a new document writer.WriteStartDocument(); //Write comments writer.WriteComment(Commentss: XmlWriter Test Program); writer.WriteProcessingInstruction(Instruction,Person Record); // Add elements to the file writer.WriteStartElement(p, person, urn:person); writer.WriteStartElement(LastName,); writer.WriteString(Chand); writer.WriteEndElement(); writer.WriteStartElement(FirstName,); writer.WriteString(Mahesh); writer.WriteEndElement(); writer.WriteElementInt16(age,, 25); // Ends the document writer.WriteEndDocument(); } catch (Exception e) { Console.WriteLine (Exception: {0}, e.ToString()); } return 0; } } |