using System.Xml.Schema;
using System.Xml.Xsl;
using System.Xml.XPath;
-#if !TARGET_JVM && !MSNET
+#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]
+ --validate-xsd2 xml-schema [instances] (in .NET 2.0 validator)
--validate-dtd instances
--transform stylesheet instance-xml [output-xml]
--prettyprint [source] [result]
case "--help":
Usage ();
return;
-#if !TARGET_JVM && !MSNET
+#if !MSNET
case "--validate":
ValidateAuto (args);
return;
ValidateNvdl (args);
return;
#endif
+ case "--validate-xsd2":
+ ValidateXsd2 (args);
+ return;
case "--validate-xsd":
ValidateXsd (args);
return;
}
}
-#if !TARGET_JVM && !MSNET
+#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++) {
r.WhitespaceHandling = WhitespaceHandling.Significant;
XmlTextWriter w = null;
if (args.Length > 2)
- w = new XmlTextWriter (args [1], Encoding.UTF8);
+ w = new XmlTextWriter (args [2], Encoding.UTF8);
else
w = new XmlTextWriter (Console.Out);
w.Formatting = Formatting.Indented;