FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Dobbs M-Dev
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
July 01, 2003

Parsing XML Files in .NET Using C#

(Page 10 of 16)
Parsing XML Files in .NET Using C#

Listing 3 Parsing XML using XmlTextReader


using System;
using System.Xml;
using CommonLib;

namespace Run
{
  class Class1
  {
    [STAThread]
    static void Main(string[] args)
    {
      CommonLib.Suite s = new CommonLib.Suite();
            
      XmlTextReader xtr = new XmlTextReader("..\\..\\..\\..\\testCases.xml");
      xtr.WhitespaceHandling = WhitespaceHandling.None;
      xtr.Read(); // read the XML declaration node, advance to <suite> tag

      while (!xtr.EOF) //load loop
      {
        if (xtr.Name == "suite" && !xtr.IsStartElement()) break;

        while (xtr.Name != "testcase" || !xtr.IsStartElement() ) 
          xtr.Read(); // advance to <testcase> tag

        CommonLib.TestCase tc = new CommonLib.TestCase();
        tc.id = xtr.GetAttribute("id");
        tc.kind = xtr.GetAttribute("kind");
        xtr.Read(); // advance to <inputs> tag
        xtr.Read(); // advance to <arg1> tag
        tc.arg1 = xtr.ReadElementString("arg1"); // consumes the </arg1> tag
        tc.arg2 = xtr.ReadElementString("arg2"); // consumes the </arg2> tag
        xtr.Read(); // advance to <expected> tag
        tc.expected = xtr.ReadElementString("expected"); // consumes the </expected> tag
        // we are now at an </testcase> tag
        s.items.Add(tc);
        xtr.Read(); // and now either at <testcase> tag or </suite> tag
      } // load loop

      xtr.Close();
      s.Display(); // show the suite of TestCases

    } // Main()
  } // class Class1
 } // ns Run

Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK