Copied remotely
[mono.git] / mcs / class / System.XML / Test / System.Xml / standalone_tests / xrdump.cs
1 using System;
2 using System.IO;
3 using System.Xml;
4
5 public class XmlReaderDumper
6 {
7         public static void Main ()
8         {
9                 new XmlReaderDumper ().TestOASIS ();
10         }
11
12         public void TestOASIS ()
13         {
14                 XmlDocument doc = new XmlDocument ();
15                 foreach (FileInfo fi in
16                         new DirectoryInfo (@"xml-test-suite/xmlconf/oasis").GetFiles ("*.xml")) {
17                         try {
18                                 if (fi.Name.IndexOf ("fail") >= 0)
19                                         continue;
20
21                                 Console.WriteLine (fi.Name);
22
23                                 XmlTextReader xtr = new XmlTextReader (fi.FullName);
24                                 while (!xtr.EOF) {
25                                         DumpReader (xtr, false);
26                                         xtr.Read ();
27                                 }
28
29                         } catch (XmlException ex) {
30                                 if (fi.Name.IndexOf ("pass") >= 0)
31                                         Console.WriteLine ("Incorrectly invalid: " + fi.FullName + "\n" + ex.Message);
32                         }
33                 }
34         }
35
36         public void DumpReader (XmlReader xr, bool attValue)
37         {
38                 Console.WriteLine ("NodeType: " + xr.NodeType);
39                 Console.WriteLine ("Prefix: " + xr.Prefix);
40                 Console.WriteLine ("Name: " + xr.Name);
41                 Console.WriteLine ("LocalName: " + xr.LocalName);
42                 Console.WriteLine ("NamespaceURI: " + xr.NamespaceURI);
43                 Console.WriteLine ("Value: " + xr.Value);
44                 Console.WriteLine ("Depth: " + xr.Depth);
45                 Console.WriteLine ("IsEmptyElement: " + xr.IsEmptyElement);
46
47                 if (xr.NodeType == XmlNodeType.Attribute) {
48                         Console.WriteLine ("Attribute Values::::");
49                         while (xr.ReadAttributeValue ())
50                                 DumpReader (xr, true);
51                         Console.WriteLine (":::Attribute Values End");
52                 } else if (!attValue) {
53                         Console.WriteLine ("Attributes::::");
54                         Console.Write (xr.AttributeCount);
55                         if (xr.MoveToFirstAttribute ()) {
56                                 do {
57                                         DumpReader (xr, false);
58                                 } while (xr.MoveToNextAttribute ());
59                                 xr.MoveToElement ();
60                         }
61                         Console.WriteLine (":::Attributes End");
62                 }
63         }
64 }