Reading from an XML file. : XML Read : XML C# Source Code


Custom Search

C# Source Code » XML » XML Read »

 

Reading from an XML file.








    


using System;
using System.Xml;

public class MainClass {
    public static void Main(string[] args) {
        XmlTextReader reader = new XmlTextReader(args[0]);

        while (reader.Read()) {
            switch (reader.NodeType) {
                case XmlNodeType.Element: // The node is an Element
                    Console.WriteLine("Element: " + reader.Name);
                    while (reader.MoveToNextAttribute()) // Read attributes
                        Console.WriteLine("  Attribute: [" +
                         reader.Name + "] = '"
                           + reader.Value + "'");
                    break;
                case XmlNodeType.DocumentType: // The node is a DocumentType
                    Console.WriteLine("Document: " + reader.Value);
                    break;
                case XmlNodeType.Comment:
                    Console.WriteLine("Comment: " + reader.Value);
                    break;
            }
        }

        reader.Close();
    }
}
           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo XML
» XML Read