using System.Xml.Schema;
using System.Xml.Xsl;
using System.Xml.XPath;
-#if !TARGET_JVM
+#if !MSNET
using Commons.Xml.Nvdl;
using Commons.Xml.Relaxng;
using Commons.Xml.Relaxng.Rnc;
{
try {
Run (args);
- Console.Error.WriteLine ("done.");
} catch (Exception ex) {
if (Environment.GetEnvironmentVariable ("MONO_XMLTOOL_ERROR_DETAILS") == "yes")
Console.Error.WriteLine (ex);
--validate-rnc relax-ng-compact-grammar-file [instances]
--validate-nvdl nvdl-script-xml [instances]
--validate-xsd xml-schema [instances]
- --transform stylesheet instance-xml
+ --validate-xsd2 xml-schema [instances] (in .NET 2.0 validator)
+ --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.
");
case "--help":
Usage ();
return;
-#if !TARGET_JVM
+#if !MSNET
case "--validate":
ValidateAuto (args);
return;
ValidateNvdl (args);
return;
#endif
+ case "--validate-xsd2":
+ ValidateXsd2 (args);
+ return;
case "--validate-xsd":
ValidateXsd (args);
return;
+ case "--validate-dtd":
+ ValidateDtd (args);
+ return;
case "--transform":
Transform (args);
return;
}
}
-#if !TARGET_JVM
+#if !MSNET
static void ValidateAuto (string [] args)
{
if (args.Length < 1) {
static void ValidateRelaxngCompact (string [] args)
{
StreamReader sr = new StreamReader (args [1]);
- RelaxngPattern p = RncParser.ParseRnc (sr);
+ RelaxngPattern p = RncParser.ParseRnc (sr, null, Path.GetFullPath (args [1]));
sr.Close ();
ValidateRelaxng (p, args);
}
static void ValidateRelaxng (RelaxngPattern p, string [] args)
{
+ p.Compile ();
+
if (args.Length < 2)
return;
new RelaxngValidatingReader (xtr, p);
if (Environment.GetEnvironmentVariable ("MONO_XMLTOOL_ERROR_DETAILS") == "yes")
vr.ReportDetails = true;
+ else
+ vr.InvalidNodeFound += delegate (XmlReader source, string message) {
+ IXmlLineInfo li = source as IXmlLineInfo;
+ Console.WriteLine ("ERROR: {0} (at {1} line {2} column {3})",
+ message,
+ source.BaseURI,
+ li != null && li.HasLineInfo () ? li.LineNumber : 0,
+ li != null && li.HasLineInfo () ? li.LinePosition : 0);
+ return true;
+ };
while (!vr.EOF)
vr.Read ();
XmlTextReader schemaxml = new XmlTextReader (args [1]);
XSchema xsd = XSchema.Read (schemaxml, null);
schemaxml.Close ();
+ xsd.Compile (null);
for (int i = 2; i < args.Length; i++) {
XmlTextReader xtr = new XmlTextReader (args [i]);
XmlValidatingReader xvr = new XmlValidatingReader (xtr);
}
}
+ static void ValidateXsd2 (string [] args)
+ {
+ XmlReaderSettings s = new XmlReaderSettings ();
+ s.ValidationType = ValidationType.Schema;
+ s.Schemas.Add (null, args [1]);
+ for (int i = 2; i < args.Length; i++) {
+ XmlReader xr = XmlReader.Create (args [i], s);
+ while (!xr.EOF)
+ xr.Read ();
+ xr.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)
+ if (args.Length > 2)
w = new XmlTextWriter (args [2], Encoding.UTF8);
else
w = new XmlTextWriter (Console.Out);