New test.
[mono.git] / mcs / tools / mono-xmltool / xmltool.cs
index 479a90651643a576caaea21fcedc49f61bef351b..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;
@@ -41,10 +41,11 @@ options:
        --validate-rnc relax-ng-compact-grammar-file [instances]
        --validate-nvdl nvdl-script-xml [instances]
        --validate-xsd xml-schema [instances]
-       --transform stylesheet instance-xml
+       --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) {
@@ -169,25 +173,40 @@ environment variable that affects on the behavior:
                        }
                }
 
+               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;