New test.
[mono.git] / mcs / tools / mono-xmltool / xmltool.cs
index 1ae6324d95938c2c83fe84d30f7af4dcda0450e7..27cc1fad61792c25057f82515fabb4aa0bbb24fd 100644 (file)
@@ -5,7 +5,7 @@ using System.Xml;
 using System.Xml.Schema;
 using System.Xml.Xsl;
 using System.Xml.XPath;
-#if !TARGET_JVM
+#if !TARGET_JVM && !MSNET
 using Commons.Xml.Nvdl;
 using Commons.Xml.Relaxng;
 using Commons.Xml.Relaxng.Rnc;
@@ -36,15 +36,16 @@ Usage: mono-xmltool [options]
 
 options:
 
-       --validate [*.rng | *.rnc | *.nvdl | *.xsd] [instance]
-       --validate-rng relax-ng-grammar-xml instance-xml
-       --validate-rnc relax-ng-compact-grammar-file instance-xml
-       --validate-nvdl nvdl-script-xml instance-xml
-       --validate-xsd xml-schema instance-xml
-       --transform stylesheet instance-xml
+       --validate [*.rng | *.rnc | *.nvdl | *.xsd] [instances]
+       --validate-rng relax-ng-grammar-xml [instances]
+       --validate-rnc relax-ng-compact-grammar-file [instances]
+       --validate-nvdl nvdl-script-xml [instances]
+       --validate-xsd xml-schema [instances]
+       --validate-dtd instances
+       --transform stylesheet instance-xml [output-xml]
        --prettyprint [source] [result]
 
-environment variable that affects on the behavior:
+environment variable that affects behavior:
 
        MONO_XMLTOOL_ERROR_DETAILS = yes : to get exception details.
 ");
@@ -62,7 +63,7 @@ environment variable that affects on the behavior:
                        case "--help":
                                Usage ();
                                return;
-#if !TARGET_JVM
+#if !TARGET_JVM && !MSNET
                        case "--validate":
                                ValidateAuto (args);
                                return;
@@ -79,6 +80,9 @@ environment variable that affects on the behavior:
                        case "--validate-xsd":
                                ValidateXsd (args);
                                return;
+                       case "--validate-dtd":
+                               ValidateDtd (args);
+                               return;
                        case "--transform":
                                Transform (args);
                                return;
@@ -88,7 +92,7 @@ environment variable that affects on the behavior:
                        }
                }
 
-#if !TARGET_JVM
+#if !TARGET_JVM && !MSNET
                static void ValidateAuto (string [] args)
                {
                        if (args.Length < 1) {
@@ -127,14 +131,16 @@ environment variable that affects on the behavior:
                        if (args.Length < 2)
                                return;
 
-                       XmlTextReader xtr = new XmlTextReader (args [2]);
-                       RelaxngValidatingReader vr = 
-                               new RelaxngValidatingReader (xtr, p);
-                       if (Environment.GetEnvironmentVariable ("MONO_XMLTOOL_ERROR_DETAILS") == "yes")
-                               vr.ReportDetails = true;
+                       for (int i = 2; i < args.Length; i++) {
+                               XmlTextReader xtr = new XmlTextReader (args [i]);
+                               RelaxngValidatingReader vr = 
+                                       new RelaxngValidatingReader (xtr, p);
+                               if (Environment.GetEnvironmentVariable ("MONO_XMLTOOL_ERROR_DETAILS") == "yes")
+                                       vr.ReportDetails = true;
 
-                       while (!vr.EOF)
-                               vr.Read ();
+                               while (!vr.EOF)
+                                       vr.Read ();
+                       }
                }
 
                static void ValidateNvdl (string [] args)
@@ -142,12 +148,13 @@ environment variable that affects on the behavior:
                        XmlTextReader nvdlxtr = new XmlTextReader (args [1]);
                        NvdlRules nvdl = NvdlReader.Read (nvdlxtr);
                        nvdlxtr.Close ();
-                       XmlTextReader xtr = new XmlTextReader (args [2]);
-                       NvdlValidatingReader nvr = new NvdlValidatingReader (
-                               xtr, nvdl);
-                       while (!nvr.EOF)
-                               nvr.Read ();
-                       xtr.Close ();
+                       for (int i = 2; i < args.Length; i++) {
+                               XmlTextReader xtr = new XmlTextReader (args [i]);
+                               NvdlValidatingReader nvr = new NvdlValidatingReader (xtr, nvdl);
+                               while (!nvr.EOF)
+                                       nvr.Read ();
+                               xtr.Close ();
+                       }
                }
 #endif
 
@@ -156,33 +163,50 @@ environment variable that affects on the behavior:
                        XmlTextReader schemaxml = new XmlTextReader (args [1]);
                        XSchema xsd = XSchema.Read (schemaxml, null);
                        schemaxml.Close ();
-                       XmlTextReader xtr = new XmlTextReader (args [2]);
-                       XmlValidatingReader xvr = new XmlValidatingReader (xtr);
-                       xvr.Schemas.Add (xsd);
-                       while (!xvr.EOF)
-                               xvr.Read ();
-                       xvr.Close ();
+                       for (int i = 2; i < args.Length; i++) {
+                               XmlTextReader xtr = new XmlTextReader (args [i]);
+                               XmlValidatingReader xvr = new XmlValidatingReader (xtr);
+                               xvr.Schemas.Add (xsd);
+                               while (!xvr.EOF)
+                                       xvr.Read ();
+                               xvr.Close ();
+                       }
+               }
+
+               static void ValidateDtd (string [] args)
+               {
+                       for (int i = 1; i < args.Length; i++) {
+                               XmlValidatingReader xvr = new XmlValidatingReader (
+                                       new XmlTextReader (args [i]));
+                               xvr.ValidationType = ValidationType.DTD;
+                               xvr.EntityHandling = EntityHandling.ExpandEntities;
+                               while (!xvr.EOF)
+                                       xvr.Read ();
+                               xvr.Close ();
+                       }
                }
 
                static void Transform (string [] args)
                {
                        XslTransform t = new XslTransform ();
                        t.Load (args [1]);
-                       XmlTextWriter xw = new XmlTextWriter (Console.Out);
-                       t.Transform (new XPathDocument (args [2], XmlSpace.Preserve), null, xw, null);
+                       TextWriter output = args.Length > 3 ?
+                               File.CreateText (args [3]) : Console.Out;
+                       t.Transform (new XPathDocument (args [2], XmlSpace.Preserve), null, output, null);
+                       output.Close ();
                }
 
                static void PrettyPrint (string [] args)
                {
                        XmlTextReader r = null;
-                       if (args.Length > 0)
+                       if (args.Length > 1)
                                r = new XmlTextReader (args [1]);
                        else
                                r = new XmlTextReader (Console.In);
                        r.WhitespaceHandling = WhitespaceHandling.Significant;
                        XmlTextWriter w = null;
-                       if (args.Length > 1)
-                               w = new XmlTextWriter (args [2], Encoding.UTF8);
+                       if (args.Length > 2)
+                               w = new XmlTextWriter (args [1], Encoding.UTF8);
                        else
                                w = new XmlTextWriter (Console.Out);
                        w.Formatting = Formatting.Indented;