xrdump.cs 1.7 KB

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