C# xml read, show error

Posted by gloris on Stack Overflow See other posts from Stack Overflow or by gloris
Published on 2010-05-18T18:44:46Z Indexed on 2010/05/18 18:50 UTC
Read the original article Hit count: 184

Filed under:
|

Whats wrong with my code?

        XmlTextReader textReader = new XmlTextReader(@"D:\xml_file.xml");
        textReader.Read();

        // If the node has value

        while (textReader.Read())
        {
            // Move to fist element

            textReader.MoveToElement();
            Console.WriteLine("XmlTextReader Properties Test");
            Console.WriteLine("===================");
            // Read this element's properties and display them on console
            Console.WriteLine("id:" + textReader.id.ToString());
            Console.WriteLine("name:" + textReader.name.ToString());
            Console.WriteLine("time:" + textReader.time.ToString());
        }
        Console.ReadLine()

show erron on: id, name, time

My XML file:

<students>
 <student>
  <id>1</id>
  <name>Rikko Nora</name>
  <time>2010-03-12</time>
 </student>
 <student>
  <id>2</id>
  <name>Rikko Nora2</name>
  <time>2010-05-15</time>
 </student>
</students>

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml