NvdlValidatingReader

| No Comments | No TrackBacks

Recently I put another XML validator in Mono - NvdlValidatingReader. It implements NVDL, ISO DSDL part 4 Namespace-based Validation Dispatching Language.

It is in our Commons.Xml.Relaxng.dll. I temporarily put autogenerated ndoc documents (no descriptive documents there). It will be included in the next release of Mono. For now, I haven't prepared independent archive, so get the sources from mono SVN repositry. Compiled binary should be in the latest monocharge.

Well, for those who want instant dll, you can get it from here:Commons.Xml.Relaxng.dll.

There is also a set of example code which demonstrates validation: nvdltests.zip

I'm too lazy to write something new, so here am mostly copying the description below from mcs/class/Commons.Xml.Relaxng/README.

NVDL

NvdlValidatingReader is an implementation of ISO DSDL Part 4 Namespace-based Validation Dispatching Language (NVDL). Note that the development is still ongoing, and NVDL specification itself is also still not in standard status as yet.

NOTE: It is "just started" implementation and may have limitations and problems.

By default, NvdlValidatingReader supports RELAX NG, RELAX NG Compact syntax, W3C XML Schema and built-in NVDL validations, however without "PlanAtt" support.

Usage

Using built-in RELAX NG support.

NvdlRules rules = NvdlReader.Read ( new XmlTextReader ("xhtml2-xforms.nvdl")); XmlReader vr = new NvdlValidatingReader ( new XmlTextReader ("index.html"), rules);

static NvdlReader.Read() method reads argument XmlReader and return NvdlRules instance.

NvdlValidatingReader is instantiated from a) XmlReader to be validated, and b) NvdlRules as validating NVDL script.

Custom validation support

NvdlConfig config = new NvdlConfig (); config.AddProvider (myOwnSchematronProvider); // [*1] config.AddProvider (myOwnExamplotronProvider); NvdlRules rules = NvdlReader.Read ( new XmlTextReader ("myscript.nvdl")); XmlReader vr = new NvdlValidatingReader ( new XmlTextReader ("myinstance.xml"), rules, config);

NvdlConfig is here used to support "custom validation provider". In NVDL script, there could be any schema language referenced. I'll describe what validation provider is immediately later.

[*1] Of course Schematron should receive its input as XPathNavigator or IXPathNavigable, but we could still use ReadSubtree() in .NET 2.0. NvdlValidationProvider

NvdlValidationProvider

To support your own validation language, you have to design your own extension to NvdlValidationProdiver type.

Abstract NvdlValidationProvider should implement at least one of the virtual methods below:

  • CreateValidatorGenerator (NvdlValidate validate, string schemaType, NvdlConfig config)
  • CreateValidatorGenerator (XmlReader schema, NvdlConfig config)

Each of them returns NvdlValidatorGenerator implementation (will describe later).

The first one receives MIME type (schemaType) and "validate" NVDL element. If you don't override it, it treats only "*/*-xml" and thus creates XmlReader from either schema attribute or schema element and passes it to another CreateValidatorGenerator() overload.

If this (possibly overriden) method returns null, then this validation

provider does not support the MIME type or the schema document.

The second one is a shorthand method to handle "*/*-xml". By default it just returns null.

Most of validation providers will only have to override the second overload. Few providers such as RELAX NG Compact Syntax support will have to overide the first overload.

NvdlValidatorGenerator

Abstract NvdlValidatorGenerator.CreateValidator() method is designed to create XmlReader from input XmlReader.

For example, we have NvdlXsdValidatorGenerator class. It internally uses XmlValidatingReader which takes XmlReader as its constructor parameter.

An instance of NvdlValidatorGenerator will be created for each "validate" element in the NVDL script. When the validate element applies (for a PlanElem), it creates validator XmlReader.

No TrackBacks

TrackBack URL: http://veritas-vos-liberabit.com/monogatari/mt-tb.cgi/35

Leave a comment