4 using Commons
.Xml
.Relaxng
;
5 using Commons
.Xml
.Relaxng
.Derivative
;
9 static char SEP
= Path
.DirectorySeparatorChar
;
11 public static void Main ()
13 Console
.WriteLine ("Started: " + DateTime
.Now
.ToString ("yyyy-MM-dd HH:mm:ss.fff"));
15 Console
.WriteLine ("Finished: " + DateTime
.Now
.ToString ("yyyy-MM-dd HH:mm:ss.fff"));
18 static void RunTest ()
20 foreach (DirectoryInfo di
in
21 new DirectoryInfo (@"relax-ng").GetDirectories ()) {
24 if (di.Name == "056") // baseURI
26 if (di.Name == "102") // invalid URI fragment
28 if (di.Name == "208") // infinite loop!!
30 if (di.Name == "210") // infinite loop!!
34 XmlTextReader xtr
= null;
35 FileInfo fi
= new FileInfo (di
.FullName
+ "/i.rng");
36 // Invalid grammar case:
38 xtr
= new XmlTextReader (fi
.FullName
);
40 RelaxngPattern
.Read (xtr
).Compile ();
41 Console
.WriteLine ("Expected error: " + di
.Name
);
42 } catch (RelaxngException ex
) {
43 } catch (XmlException ex
) {
44 } catch (ArgumentNullException ex
) {
45 } catch (UriFormatException ex
) {
46 } catch (Exception ex
) {
47 Console
.WriteLine ("Unexpected error type : " + di
.Name
+ " : " + ex
.Message
);
54 // Valid grammar case:
55 xtr
= new XmlTextReader (di
.FullName
+ "/c.rng");
56 RelaxngPattern p
= null;
58 p
= RelaxngPattern
.Read (xtr
);
60 } catch (Exception ex
) {
61 Console
.WriteLine ("Invalidated grammar: " + di
.Name
+ " : " + ex
.Message
);
68 // Instance validation
69 foreach (FileInfo inst
in di
.GetFiles ("*.xml")) {
71 RelaxngValidatingReader vr
= new RelaxngValidatingReader (new XmlTextReader (inst
.FullName
), p
);
74 if (inst
.Name
.IndexOf ("i.") >= 0)
75 Console
.WriteLine ("Incorrectly validated instance: " + di
.Name
+ "/" + inst
.Name
);
76 } catch (RelaxngException ex
) {
77 if (inst
.Name
.IndexOf ("i.") >= 0)
79 Console
.WriteLine ("Invalidated instance: " + di
.Name
+ "/" + inst
.Name
+ " : " + ex
.Message
);