Author: atsushi
Date: 2006-01-30 00:53:58 -0500 (Mon, 30 Jan 2006)
New Revision: 56234
Added:
trunk/mcs/tools/mono-xmltool/
trunk/mcs/tools/mono-xmltool/ChangeLog
trunk/mcs/tools/mono-xmltool/Makefile
trunk/mcs/tools/mono-xmltool/mono-xmltool.exe.sources
trunk/mcs/tools/mono-xmltool/xmltool.cs
Log:
2006-01-30 Atsushi Enomoto <[EMAIL PROTECTED]>
* xmltool.cs, Makefile, mono-xmltool.exe.sources : new files.
Added: trunk/mcs/tools/mono-xmltool/ChangeLog
===================================================================
--- trunk/mcs/tools/mono-xmltool/ChangeLog 2006-01-29 23:58:00 UTC (rev
56233)
+++ trunk/mcs/tools/mono-xmltool/ChangeLog 2006-01-30 05:53:58 UTC (rev
56234)
@@ -0,0 +1,3 @@
+2006-01-30 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * xmltool.cs, Makefile, mono-xmltool.exe.sources : new files.
Property changes on: trunk/mcs/tools/mono-xmltool/ChangeLog
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/mcs/tools/mono-xmltool/Makefile
===================================================================
--- trunk/mcs/tools/mono-xmltool/Makefile 2006-01-29 23:58:00 UTC (rev
56233)
+++ trunk/mcs/tools/mono-xmltool/Makefile 2006-01-30 05:53:58 UTC (rev
56234)
@@ -0,0 +1,8 @@
+thisdir = tools/mono-xmltool
+SUBDIRS =
+include ../../build/rules.make
+
+LOCAL_MCS_FLAGS = -r:System.Xml.dll -r:Commons.Xml.Relaxng.dll
+PROGRAM = mono-xmltool.exe
+
+include ../../build/executable.make
Property changes on: trunk/mcs/tools/mono-xmltool/Makefile
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/mcs/tools/mono-xmltool/mono-xmltool.exe.sources
===================================================================
--- trunk/mcs/tools/mono-xmltool/mono-xmltool.exe.sources 2006-01-29
23:58:00 UTC (rev 56233)
+++ trunk/mcs/tools/mono-xmltool/mono-xmltool.exe.sources 2006-01-30
05:53:58 UTC (rev 56234)
@@ -0,0 +1,2 @@
+xmltool.cs
+
Property changes on: trunk/mcs/tools/mono-xmltool/mono-xmltool.exe.sources
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/mcs/tools/mono-xmltool/xmltool.cs
===================================================================
--- trunk/mcs/tools/mono-xmltool/xmltool.cs 2006-01-29 23:58:00 UTC (rev
56233)
+++ trunk/mcs/tools/mono-xmltool/xmltool.cs 2006-01-30 05:53:58 UTC (rev
56234)
@@ -0,0 +1,162 @@
+using System;
+using System.IO;
+using System.Text;
+using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Xsl;
+using System.Xml.XPath;
+using Commons.Xml.Nvdl;
+using Commons.Xml.Relaxng;
+using Commons.Xml.Relaxng.Rnc;
+
+using XSchema = System.Xml.Schema.XmlSchema;
+
+namespace Commons.Xml.Relaxng
+{
+ public class Driver
+ {
+ public static void Main (string [] args)
+ {
+ try {
+ Run (args);
+ } catch (Exception ex) {
+ if (Environment.GetEnvironmentVariable
("MONO_XMLTOOL_ERROR_DETAILS") == "yes")
+ Console.WriteLine (ex);
+ else
+ Console.WriteLine (ex.Message);
+ }
+ }
+
+ static void Usage ()
+ {
+ Console.WriteLine (@"
+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
+
+environment variable that affects on the behavior:
+
+ MONO_XMLTOOL_ERROR_DETAILS = yes : to get exception details.
+");
+ }
+
+ static void Run (string [] args)
+ {
+ if (args.Length == 0) {
+ Usage ();
+ return;
+ }
+
+ switch (args [0]) {
+ default:
+ case "--help":
+ Usage ();
+ return;
+ case "--validate-rnc":
+ ValidateRelaxngCompact (args);
+ return;
+ case "--validate-rng":
+ ValidateRelaxngXml (args);
+ return;
+ case "--validate-nvdl":
+ ValidateNvdl (args);
+ return;
+ case "--validate-xsd":
+ ValidateXsd (args);
+ return;
+ case "--validate":
+ ValidateAuto (args);
+ return;
+ case "--transform":
+ Transform (args);
+ return;
+ }
+ }
+
+ static void ValidateAuto (string [] args)
+ {
+ if (args.Length < 1) {
+ Usage ();
+ return;
+ }
+
+ if (args [1].EndsWith ("rng"))
+ ValidateRelaxngXml (args);
+ else if (args [1].EndsWith ("rnc"))
+ ValidateRelaxngCompact (args);
+ else if (args [1].EndsWith ("nvdl"))
+ ValidateNvdl (args);
+ else if (args [1].EndsWith ("xsd"))
+ ValidateXsd (args);
+ }
+
+ static void ValidateRelaxngXml (string [] args)
+ {
+ XmlReader xr = new XmlTextReader (args [1]);
+ RelaxngPattern p = RelaxngPattern.Read (xr);
+ xr.Close ();
+ ValidateRelaxng (p, args);
+ }
+
+ static void ValidateRelaxngCompact (string [] args)
+ {
+ StreamReader sr = new StreamReader (args [1]);
+ RelaxngPattern p = RncParser.ParseRnc (sr);
+ sr.Close ();
+ ValidateRelaxng (p, args);
+ }
+
+ static void ValidateRelaxng (RelaxngPattern p, string [] args)
+ {
+ XmlTextReader xtr = new XmlTextReader (args [2]);
+ RelaxngValidatingReader vr =
+ new RelaxngValidatingReader (xtr, p);
+ vr.ReportDetails = true;
+
+ while (!vr.EOF)
+ vr.Read ();
+ }
+
+ static void ValidateNvdl (string [] args)
+ {
+ 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 ();
+ }
+
+ static void ValidateXsd (string [] args)
+ {
+ 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 ();
+ }
+
+ 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);
+ }
+ }
+}
+
Property changes on: trunk/mcs/tools/mono-xmltool/xmltool.cs
___________________________________________________________________
Name: svn:eol-style
+ native
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches