Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,204 @@
2007-12-27 Atsushi Enomoto <atsushi@ximian.com>
* NvdlRelaxngSupport.cs : pass baseUri to RncParser.
2006-04-19 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs :
Made placeholder element as "empty" i.e. IsEmptyElement = true.
As long as it is at placeholder state, it keeps being placeholder
empty element until DetachPlaceholder() is explicitly called. It
makes this reader simpler.
* NvdlValidator.cs : (NvdlResultInterp) for AttachPlaceHolder it does
not have to do anything other than AttachPlaceholder().
(NvdlValidateInterp) Now that placeholder becomes an empty element
it does not have to validate content anymore at DetachPlaceholder().
2006-04-19 Atsushi Enomoto <atsushi@ximian.com>
* NvdlReader.cs, NvdlFilteredXmlReader.cs :
placeHolder -> placeholder. Also reject unrecognized NVDL elements
in NvdlReader.
2006-04-19 Atsushi Enomoto <atsushi@ximian.com>
* NvdlException.cs : provide BaseURI in such case that argument
IXmlLineInfo is XmlReader.
* NvdlValidator.cs : NvdlDispatcher was incorrectly replacing
current section when an empty element appears (it kept such empty
element section).
2006-04-19 Atsushi Enomoto <atsushi@ximian.com>
* NvdlRelaxngSupport.cs : It seems that the validating grammar for
planAtt should always contain a definition for virtualElement i.e.
it is not something that NVDL validator should provide
automatically. (It makes sense since RELAX NG does not support
attribute-only grammar definition.)
* NvdlFilteredXmlReader.cs : for validating attributes, filter xmlns
attributes out.
2006-04-18 Atsushi Enomoto <atsushi@ximian.com>
* NvdlSimplified.cs, NvdlValidator.cs :
Support for revised "trigger" in FDIS was not enough. The validator
must not trigger such element that has a parent which could be
triggered (the parent does not have to be actually triggered).
Thus, introduced a new class SimpleTrigger which holds own qname
array.
2006-04-18 Atsushi Enomoto <atsushi@ximian.com>
* NvdlSimplified.cs : according to the section 6.4.10 overriden rules
should be filtered out, and rules with cancelNestedAction should be
removed *after* filtering overriden rules out.
2006-04-18 Atsushi Enomoto <atsushi@ximian.com>
* NvdlSimplified.cs, NvdlValidator.cs :
fixed several context path related bugs.
- Path steps must be trimmed.
- MatchPath() always returned false.
- nested mode in context is always ignored.
2006-04-11 Atsushi Enomoto <atsushi@ximian.com>
* NvdlRelaxngSupport.cs : without ReportDetails RELAX NG support
supplied too little information on validation error.
2006-04-11 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs : quick fix for r58557; it caused a big
NVDL validation breakage (nvdl.nvdl does not validate).
Removed unused and insignificant code.
* NvdlCompileContext.cs : removed unused field.
2006-04-03 Atsushi Enomoto <atsushi@ximian.com>
due to the request by Brian Rasumussen to report NVDL error details:
* NvdlFilteredXmlReader.cs : make it as IXmlLineInfo.
* NvdlValidationGenerator.cs :
(NvdlValidationProvider) made validate, schemaType and config as
publicly accessible.
(NvdlValidatorGenerator) added new HandleError() method that can
override error handling.
* NvdlValidator.cs : use it.
* NvdlException.cs : added new type NvdlInstanceValidationException
that is used to "wrap" actual validation errors to provide
NVDL script location information.
* NvdlRelaxngSupport.cs, NvdlXsdSupport.cs :
use those new HandleError() and NvdlInstanceValidationException.
2006-03-23 Atsushi Enomoto <atsushi@ximian.com>
* NvdlXsdSupport.cs : seems like "XmlReaderSettings.ValidationType =
ValidationType.Auto" does not automatically start xsd validation,
so set the property explicitly as ValidationType.Schema.
2006-03-03 Atsushi Enomoto <atsushi@ximian.com>
* NvdlXsdSupport.cs : oops, XmlSchemaValidationFlags.
2006-03-03 Atsushi Enomoto <atsushi@ximian.com>
* NvdlXsdSupport.cs : in NET_2_0 mode, use XmlReader.Create()
with validation support. Now MS.NET users can validate NVDL
that uses XSD.
2006-03-03 Atsushi Enomoto <atsushi@ximian.com>
* NvdlSimplified.cs : (SimpleRules) huh, I made silly change to
access null field.
2005-12-23 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs, NvdlReader.cs, NvdlStructures.cs,
NvdlSimplified.cs, NvdlValidator.cs:
Reflected the latest changes in NVDL Final Draft:
http://www.jtc1sc34.org/repository/0694.pdf
- wildcard -> wildCard
- renamed from "PlaceHolder" to "Placeholder"
- trigger/@name of NCName -> trigger/@nameList of list of NCName
2005-09-30 Atsushi Enomoto <atsushi@ximian.com>
* NvdlConfig.cs : changed mime type due to the suggestion from Makoto
Murata.
2005-09-30 Atsushi Enomoto <atsushi@ximian.com>
* NvdlXsdSupport.cs : related fix to r51030; XmlSchema.Read() now does
not consume EndElement.
2005-09-25 Atsushi Enomoto <atsushi@ximian.com>
* NvdlValidationProvider.cs : GetSchemaXmlStream() should take NVDL
script's base URI into account to compute the actual schema URI.
* NvdlRelaxngSupport.cs : ditto.
2005-09-11 Atsushi Enomoto <atsushi@ximian.com>
* NvdlCompileContext.cs : make this internal.
* NvdlStructures.cs : surpress default constructor.
Make debug stuff internal.
2005-04-11 Atsushi Enomoto <atsushi@ximian.com>
* NvdlRelaxngSupport.cs : added PlanAtt validation support.
2005-04-06 Atsushi Enomoto <atsushi@ximian.com>
* NvdlValidator.cs : fixed warning.
2005-03-07 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs, NvdlStructures.cs, NvdlSimplified.cs :
"PlaceHolderNamespace" is not proper name (for "virtualElement").
2005-03-07 Atsushi Enomoto <atsushi@ximian.com>
* NvdlBuiltInValidationProvider.cs :
When it is "allow", it should not always return false.
* NvdlFilteredXmlReader.cs :
Added support for PlanAtt validation.
* NvdlConfig.cs :
Removed unused code.
* NvdlSimplified.cs :
Attribute default rule is "attach", not "allow". Removed unused
code. Added attribute validation support.
* NvdlValidationProvider.cs :
Extended MIME type check to "*/*-xml" (not only text/xml).
Added CreateAttributeValidator() method for "schema rewriting for
attribute sections" support (FCD spec 8.7.3).
2005-03-06 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs : code refactory.
* NvdlCompileContext.cs, NvdlConfig.cs, NvdlSimplified.cs,
NvdlValidatingReader.cs : Simplified objects are now all internal.
* NvdlValidator.cs : don't output debug.
2005-03-06 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs : New file. Supports createPlaceHolder()
and attBubble[I].
* NvdlValidator.cs : support for attachPlaceHolder.
* NvdlSimplified.cs,
NvdlStructures.cs,
NvdlBuiltInValidationProvider.cs : renamed namespace const.
* NvdlValidationProvider.cs : removed extraneous debug.
2005-03-01 Atsushi Enomoto <atsushi@ximian.com>
* NvdlStructures.cs,
NvdlSimplified.cs,
NvdlReader.cs,
NvdlValidatingReader.cs,
NvdlConfig.cs,
NvdlValidationProvider.cs,
NvdlBuiltInValidationProvider.cs,
NvdlRelaxngSupport.cs,
NvdlXsdSupport.cs,
NvdlException.cs,
NvdlValidator.cs,
NvdlCompileContext.cs : initial checkin.

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using Commons.Xml;
namespace Commons.Xml.Nvdl
{
public class NvdlBuiltInValidationProvider : NvdlValidationProvider
{
public NvdlBuiltInValidationProvider ()
{
}
public override NvdlValidatorGenerator CreateGenerator (
XmlReader reader, NvdlConfig config)
{
reader.MoveToContent ();
if (reader.NodeType != XmlNodeType.Element ||
reader.NamespaceURI != Nvdl.BuiltInValidationNamespace)
return null;
return new NvdlBuiltInValidatorGenerator (reader.LocalName == "allow");
}
}
internal class NvdlBuiltInValidatorGenerator : NvdlValidatorGenerator
{
bool allow;
public NvdlBuiltInValidatorGenerator (bool allow)
{
this.allow = allow;
}
public override XmlReader CreateValidator (XmlReader reader, XmlResolver resolver)
{
return new NvdlBuiltInValidationReader (reader, allow);
}
public override bool AddOption (string name, string arg)
{
return false;
}
}
internal class NvdlBuiltInValidationReader : XmlDefaultReader
{
bool allow;
public NvdlBuiltInValidationReader (XmlReader reader, bool allow)
: base (reader)
{
this.allow = allow;
}
public override bool Read ()
{
if (!Reader.Read ())
return false;
if (!allow)
throw new NvdlValidationException (String.Format ("The NVDL script does not allow an element whose namespace is '{0}'", Reader.NamespaceURI), Reader as IXmlLineInfo);
return true;
}
}
}

View File

@@ -0,0 +1,112 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using Commons.Xml;
namespace Commons.Xml.Nvdl
{
internal class NvdlCompileContext
{
NvdlRules rules;
NvdlConfig config;
XmlResolver resolver;
Hashtable compiledModes = new Hashtable ();
Hashtable modeContexts = new Hashtable ();
Hashtable cancelledRules = new Hashtable ();
Hashtable ruleContexts = new Hashtable ();
public NvdlCompileContext (NvdlRules rules, NvdlConfig config, XmlResolver resolver)
{
this.rules = rules;
this.config = config;
this.resolver = resolver;
}
public NvdlRules Rules {
get { return rules; }
}
public NvdlConfig Config {
get { return config; }
}
internal XmlResolver XmlResolver {
get { return resolver; }
}
internal void AddCompiledMode (string name, SimpleMode m)
{
compiledModes.Add (m.Name, m);
}
internal void AddCompiledMode (NvdlModeUsage u, SimpleMode m)
{
compiledModes.Add (u, m);
}
internal void AddCompiledMode (NvdlContext c, SimpleMode m)
{
compiledModes.Add (c, m);
}
internal SimpleMode GetCompiledMode (string name)
{
return compiledModes [name] as SimpleMode;
}
internal SimpleMode GetCompiledMode (NvdlModeUsage u)
{
return compiledModes [u] as SimpleMode;
}
internal SimpleMode GetCompiledMode (NvdlContext c)
{
return compiledModes [c] as SimpleMode;
}
internal ICollection GetCompiledModes ()
{
return compiledModes.Values;
}
internal NvdlModeCompileContext GetModeContext (SimpleMode m)
{
return modeContexts [m] as NvdlModeCompileContext;
}
internal void AddModeContext (SimpleMode m,
NvdlModeCompileContext mctx)
{
modeContexts.Add (m, mctx);
}
internal NvdlRule GetRuleContext (SimpleRule r)
{
return ruleContexts [r] as NvdlRule;
}
internal void AddRuleContext (SimpleRule r, NvdlRule rctx)
{
ruleContexts.Add (r, rctx);
}
public Hashtable CancelledRules {
get { return cancelledRules; }
}
}
internal class NvdlModeCompileContext
{
ArrayList included;
public NvdlModeCompileContext (NvdlModeBase mode)
{
included = new ArrayList ();
}
public ArrayList Included {
get { return included; }
}
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using Commons.Xml;
namespace Commons.Xml.Nvdl
{
public class NvdlConfig
{
XmlResolver resolver = new XmlUrlResolver ();
ArrayList providers = new ArrayList ();
public NvdlConfig ()
{
providers.Add (new NvdlBuiltInValidationProvider ());
}
public void AddProvider (NvdlValidationProvider provider)
{
providers.Add (provider);
}
internal XmlResolver XmlResolverInternal {
get { return resolver; }
}
public XmlResolver XmlResolver {
set { resolver = value; }
}
public NvdlValidatorGenerator GetGenerator (NvdlValidate validate, string inheritSchemaType)
{
this.resolver = this.XmlResolverInternal;
string schemaType = validate.SchemaType;
if (schemaType == null)
schemaType = inheritSchemaType;
if (schemaType == null)
schemaType = "application/xml";
foreach (NvdlValidationProvider p in providers) {
NvdlValidatorGenerator g =
p.CreateGenerator (validate, schemaType, this);
if (g != null)
return g;
}
throw new NvdlCompileException (String.Format ("Either schema type '{0}' or the target schema document is not supported in this configuration. Add custom provider that supports this schema type.", schemaType), validate);
}
}
}

View File

@@ -0,0 +1,92 @@
using System;
using System.Xml;
namespace Commons.Xml.Nvdl
{
public class NvdlException : Exception
{
public NvdlException (string message)
: base (message)
{
}
public NvdlException (string message, Exception inner)
: base (message ,inner)
{
}
internal static string FormatMessage (string message,
IXmlLineInfo lineInfo)
{
NvdlElementBase source = lineInfo as NvdlElementBase;
XmlReader reader = lineInfo as XmlReader;
if (source != null && source.HasLineInfo ())
return String.Format ("{0}. {1} ({2},{3})",
message, source.SourceUri,
source.LineNumber, source.LinePosition);
else if (lineInfo != null && lineInfo.HasLineInfo ())
return String.Format ("{0}. {3}({1},{2})",
message,
lineInfo.LineNumber,
lineInfo.LinePosition,
reader != null ? reader.BaseURI + ' ' : String.Empty);
else
return message;
}
}
public class NvdlCompileException : NvdlException
{
public NvdlCompileException (string message,
IXmlLineInfo source)
: this (message, null, source)
{
}
public NvdlCompileException (string message, Exception inner,
IXmlLineInfo source)
: base (FormatMessage (message, source), inner)
{
}
}
public class NvdlValidationException : NvdlException
{
public NvdlValidationException (string message,
IXmlLineInfo source)
: this (message, null, source)
{
}
public NvdlValidationException (string message, Exception inner,
IXmlLineInfo source)
: base (FormatMessage (message, source), inner)
{
}
}
public class NvdlInstanceValidationException : NvdlException
{
public NvdlInstanceValidationException (string message,
NvdlValidatorGenerator generator,
string nvdlLocation)
: this (message, null, generator, nvdlLocation)
{
}
public NvdlInstanceValidationException (string message, Exception inner,
NvdlValidatorGenerator generator,
string nvdlLocation)
: base (FormatMessageWithDefinition (message, nvdlLocation), inner)
{
}
// assuming that wrapped exception message usually
// contains the actual instance location info.
static string FormatMessageWithDefinition (string message, string nvdlLocation)
{
return String.Format ("{0}. Related NVDL script: {1}", message, nvdlLocation);
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,95 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Xml;
using Commons.Xml.Relaxng;
using Commons.Xml.Relaxng.Rnc;
namespace Commons.Xml.Nvdl
{
public class NvdlRelaxngValidatorProvider : NvdlValidationProvider
{
public const string RncMimeType = "application/vnd.oasis-open.relax-ng.rnc";
public override NvdlValidatorGenerator CreateGenerator (
NvdlValidate validate, string schemaType, NvdlConfig config)
{
if (schemaType == RncMimeType)
return CreateRncGenerator (validate, config);
return base.CreateGenerator (validate, schemaType, config);
}
private NvdlValidatorGenerator CreateRncGenerator (NvdlValidate validate, NvdlConfig config)
{
XmlResolver resolver = config.XmlResolverInternal;
string schemaUri = GetSchemaUri (validate);
if (schemaUri == null)
return null;
Uri baseUri = resolver.ResolveUri (null, validate.SourceUri);
Uri absUri = resolver.ResolveUri (baseUri, schemaUri);
RelaxngPattern p = RncParser.ParseRnc (
new StreamReader ((Stream) resolver.GetEntity (
absUri,
null,
typeof (Stream))), null, absUri.ToString ());
return new NvdlRelaxngValidatorGenerator (p, config);
}
public override NvdlValidatorGenerator CreateGenerator (
XmlReader reader, NvdlConfig config)
{
if (reader.NamespaceURI != RelaxngGrammar.NamespaceURI)
return null;
return new NvdlRelaxngValidatorGenerator (RelaxngPattern.Read (reader), config);
}
}
internal class NvdlRelaxngValidatorGenerator : NvdlValidatorGenerator
{
RelaxngPattern pattern;
public NvdlRelaxngValidatorGenerator (RelaxngPattern p,
NvdlConfig config)
{
// FIXME: use XmlResolver
pattern = p;
}
public override XmlReader CreateValidator (XmlReader reader,
XmlResolver resolver)
{
// XmlResolver is never used.
RelaxngValidatingReader rvr =
new RelaxngValidatingReader (
reader, pattern);
rvr.ReportDetails = true;
return rvr;
}
public override XmlReader CreateAttributeValidator (
XmlReader reader,
XmlResolver resolver)
{
// XmlResolver is never used.
RelaxngValidatingReader rvr =
new RelaxngValidatingReader (
reader, pattern);
rvr.ReportDetails = true;
return rvr;
}
public override bool AddOption (string name, string arg)
{
return false;
}
public override bool HandleError (Exception ex, XmlReader reader, string nvdlLocation)
{
if (ex is RelaxngException)
throw new NvdlInstanceValidationException (String.Format ("RELAX NG validation error occured as a part of NVDL validation: " + ex.Message), ex, this, nvdlLocation);
return false;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,79 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Threading;
using System.Xml;
using Commons.Xml;
namespace Commons.Xml.Nvdl
{
public class NvdlValidatingReader : XmlDefaultReader
{
NvdlDispatcher dispatcher;
public NvdlValidatingReader (XmlReader reader, NvdlRules rules)
: this (reader, rules, new XmlUrlResolver ())
{
}
public NvdlValidatingReader (XmlReader reader, NvdlRules rules, XmlResolver resolver)
: this (reader, rules, resolver, Nvdl.DefaultConfig)
{
}
public NvdlValidatingReader (XmlReader reader, NvdlRules rules,
XmlResolver resolver, NvdlConfig config)
: base (reader)
{
dispatcher = new NvdlDispatcher (new SimpleRules (
new NvdlCompileContext (
rules, config, resolver)), this);
}
internal NvdlValidatingReader (XmlReader reader, SimpleRules rules)
: base (reader)
{
dispatcher = new NvdlDispatcher (rules, this);
}
public event NvdlMessageEventHandler ActionStarted;
internal void OnMessage (ListDictionary messages)
{
if (messages == null)
return;
string message = messages [Thread.CurrentThread.CurrentCulture.Name] as string;
if (message == null)
message = messages [String.Empty] as string;
if (message == null)
return;
if (ActionStarted != null)
ActionStarted (this, new NvdlMessageEventArgs (message));
}
// validation.
public override bool Read ()
{
if (!Reader.Read ())
return false;
switch (Reader.NodeType) {
case XmlNodeType.Element:
dispatcher.StartElement ();
break;
case XmlNodeType.EndElement:
dispatcher.EndElement ();
break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
case XmlNodeType.SignificantWhitespace:
dispatcher.Text ();
break;
case XmlNodeType.Whitespace:
dispatcher.Whitespace ();
break;
}
return true;
}
}
}

View File

@@ -0,0 +1,121 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Xml;
namespace Commons.Xml.Nvdl
{
public class NvdlValidationProvider
{
NvdlValidate validate;
string schema_type;
NvdlConfig config;
public virtual NvdlValidatorGenerator CreateGenerator (NvdlValidate validate, string schemaType, NvdlConfig config)
{
this.validate = validate;
this.schema_type = schemaType;
this.config = config;
XmlReader schema = null;
// FIXME: we need a bit more strict check.
if (schemaType.Length < 5 ||
!schemaType.EndsWith ("xml") ||
Char.IsLetter (schemaType, schemaType.Length - 4))
return null;
string schemaUri = validate.SchemaUri;
XmlElement schemaBody = validate.SchemaBody;
if (schemaUri != null) {
if (schemaBody != null)
throw new NvdlCompileException ("Both 'schema' attribute and 'schema' element are specified in a 'validate' element.", validate);
schema = GetSchemaXmlStream (schemaUri, config, validate);
}
else if (validate.SchemaBody != null) {
XmlReader r = new XmlNodeReader (schemaBody);
r.MoveToContent ();
r.Read (); // Skip "schema" element
r.MoveToContent ();
if (r.NodeType == XmlNodeType.Element)
schema = r;
else
schema = GetSchemaXmlStream (r.ReadString (), config, validate);
}
if (schema == null)
return null;
return CreateGenerator (schema, config);
}
public NvdlValidate ValidateAction {
get { return validate; }
}
public NvdlConfig Config {
get { return config; }
}
public string SchemaType {
get { return schema_type; }
}
public virtual NvdlValidatorGenerator CreateGenerator (XmlReader schema, NvdlConfig config)
{
return null;
}
public string GetSchemaUri (NvdlValidate validate)
{
if (validate.SchemaUri != null)
return validate.SchemaUri;
if (validate.SchemaBody == null)
return null;
for (XmlNode n = validate.SchemaBody.FirstChild; n != null; n = n.NextSibling)
if (n.NodeType == XmlNodeType.Element)
return null; // not a URI
return validate.SchemaBody.InnerText;
}
private static XmlReader GetSchemaXmlStream (string schemaUri, NvdlConfig config, NvdlValidate validate)
{
XmlResolver r = config.XmlResolverInternal;
if (r == null)
return null;
Uri baseUri = r.ResolveUri (null, validate.SourceUri);
Uri uri = r.ResolveUri (baseUri, validate.SchemaUri);
Stream stream = (Stream) r.GetEntity (
uri, null, typeof (Stream));
if (stream == null)
return null;
XmlTextReader xtr = new XmlTextReader (uri != null ? uri.ToString () : String.Empty, stream);
xtr.XmlResolver = r;
xtr.MoveToContent ();
return xtr;
}
}
public abstract class NvdlValidatorGenerator
{
// creates individual validator with schema
// (which should be provided in derived constructor).
public abstract XmlReader CreateValidator (XmlReader reader,
XmlResolver resolver);
public virtual XmlReader CreateAttributeValidator (
XmlReader reader,
XmlResolver resolver)
{
throw new NotSupportedException ();
}
public abstract bool AddOption (string name, string arg);
public virtual bool HandleError (Exception ex, XmlReader reader, string nvdlLocation)
{
return false;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,75 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.Xml.Schema;
namespace Commons.Xml.Nvdl
{
public class NvdlXsdValidatorProvider : NvdlValidationProvider
{
public override NvdlValidatorGenerator CreateGenerator (
XmlReader reader, NvdlConfig config)
{
if (reader.NamespaceURI != XmlSchema.Namespace)
return null;
ArrayList al = new ArrayList ();
while (!reader.EOF) {
if (reader.NodeType != XmlNodeType.Element) {
reader.Read ();
continue;
}
reader.MoveToContent ();
XmlSchema xs = XmlSchema.Read (reader, null);
xs.Compile (null, config.XmlResolverInternal);
al.Add (xs);
reader.Read ();
}
return new NvdlXsdValidatorGenerator (al.ToArray (typeof (XmlSchema)) as XmlSchema []);
}
}
internal class NvdlXsdValidatorGenerator : NvdlValidatorGenerator
{
XmlSchema [] schemas;
public NvdlXsdValidatorGenerator (XmlSchema [] schemas)
{
this.schemas = schemas;
}
public override XmlReader CreateValidator (XmlReader reader,
XmlResolver resolver)
{
#if NET_2_0
XmlReaderSettings s = new XmlReaderSettings ();
s.ValidationType = ValidationType.Schema;
// do not allow inline schema and schemaLocation.
s.ValidationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
s.XmlResolver = resolver;
foreach (XmlSchema schema in schemas)
s.Schemas.Add (schema);
return XmlReader.Create (reader, s);
#else
XmlValidatingReader xvr =
new XmlValidatingReader (reader);
xvr.XmlResolver = resolver;
foreach (XmlSchema schema in schemas)
xvr.Schemas.Add (schema);
return xvr;
#endif
}
public override bool AddOption (string name, string arg)
{
return false;
}
public override bool HandleError (Exception ex, XmlReader reader, string nvdlLocation)
{
if (ex is XmlSchemaException)
throw new NvdlInstanceValidationException (String.Format ("XML schema validation error occured as a part of NVDL validation."), ex, this, nvdlLocation);
return false;
}
}
}