コンテンツへスキップ
ものがたり
戻る

そろそろOKかな

役に立つかなぁ…NVDL実装メモ

http://monkey.workarea.jp/tmp/20050307/nvdl-introduction-ja.html

あとndocでAPIリファレンスも生成

http://monkey.workarea.jp/tmp/20050307/api/

あ、ソースはMonoのSVNから取得できます。

あとは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.
http://www.asahi-net.or.jp/~eb2m-mrt/dsdl/

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

  1. 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.

  1. 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

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:

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.


コメント

村田 — 04/05/2005 10:57:26

やっとC#が使えるようになりました。Subversionでチェックアウトし、Visual C#.netに読み込もうとしましたが、Visual C#.netの
プロジェクトがないようですね。自分でやるといろいろ間違えそうなので、プロジェクトをいただけません?

atsushieno — 04/05/2005 14:02:48

すみません、VSは全く使っておらず2003はインストールもしていないのです…入っているソースを全部ビルド対象にすれば大丈夫だと思います。

村田 — 04/06/2005 11:58:15

*.csをコピーし、NUnitを追加してコンパイルしたところ、エラーは
激減しました。残っているのは、jayで生成しているはずのクラス
(Commons.Xml.Relaxng.Rnc.yyParser.yyInput)に関するものだけです。これは、MS Visual C# .netでも動くので
しょうか?

atsushieno — 04/06/2005 14:28:57

あっ、すみませんそれはjay(しかもmonoに含まれるもの)を使わないと生成できません…こちらにビルド済みのソースを置いておきます
http://monkey.workarea.jp/tmp/20050406/RncParser.cs

atsushieno — 04/06/2005 14:30:04

あ、NUnitテスト用のソースも「入っているソース全部」に含まれてしまいますね…これらは必要ありません。重ね重ねすいません。

村田 — 04/06/2005 18:17:12

今度は、次のエラーメッセージが出ました。

’Commons.Xml.Relaxng.RdpUnresolvedRef.ReduceEmptyAndNotAllowed(ref bool, System.Collections.Hashtable)’ は継承されたメンバ ’Commons.Xml.Relaxng.Derivative.RdpPattern.ReduceEmptyAndNotAllowed(ref bool, System.Collections.Hashtable) を隠します。現在のメンバでそのインプリメンテーションをオーバーライドするには、override キーワードを追加してください。オーバーライドしない場合は、new キーワードを追加してください。

それから、Mainが、anglia-test-runnerとrelaxngtestの二箇所
にあると怒ってます。どちらを残せばいいでしょう?

atsushieno — 04/06/2005 18:30:33

ええと、すみませんがrelaxngtest.csとanglia-test-runner.csはどちらもTestディレクトリ以下にあった単なるテスト用のソースなので、プロジェクトからは消して下さい(プロジェクトのターゲットはライブラリになります)。その他の上記warningはビルドストッパーにはならないと思います。問題といえば問題なのでsvnでは修正しておきます。

村田 — 04/06/2005 20:06:15

コンパイルに成功しました。ありがとうございます。

warningがいくつか出ているので、ここに転記しておきます。

C:¥Documents and Settings¥makoto¥My Documents¥Visual Studio Projects¥NvdlLibrary¥RelaxngPattern.cs(1077,31): warning CS0114: ’Commons.Xml.Relaxng.RdpUnresolvedRef.ReduceEmptyAndNotAllowed(ref bool, System.Collections.Hashtable)’ は継承されたメンバ ’Commons.Xml.Relaxng.Derivative.RdpPattern.ReduceEmptyAndNotAllowed(ref bool, System.Collections.Hashtable) を隠します。現在のメンバでそのインプリメンテーションをオーバーライドするには、override キーワードを追加してください。オーバーライドしない場合は、new キーワードを追加してください。
C:¥Documents and Settings¥makoto¥My Documents¥Visual Studio Projects¥NvdlLibrary¥RdpPatterns.cs(213、31) : (関連場所)
C:¥Documents and Settings¥makoto¥My Documents¥Visual Studio Projects¥NvdlLibrary¥NvdlValidator.cs(170,9): warning CS0253: 予期しない参照比較です。比較値を取得するには型 ’string’ に右辺をキャストしてください。
C:¥Documents and Settings¥makoto¥My Documents¥Visual Studio Projects¥NvdlLibrary¥NvdlSimplified.cs(504,15): warning CS0649: フィールド ’Commons.Xml.Nvdl.SimpleValidate.resolver’ は割り当てられません。常に既定値 null を使用します。
C:¥Documents and Settings¥makoto¥My Documents¥Visual Studio Projects¥NvdlLibrary¥RdpPatterns.cs(602,8): warning CS0649: フィールド ’Commons.Xml.Relaxng.Derivative.RdpAbstractBinary.expanded’ は割り当てられません。常に既定値 false を使用します。
C:¥Documents and Settings¥makoto¥My Documents¥Visual Studio Projects¥NvdlLibrary¥RdpPatterns.cs(965,8): warning CS0649: フィールド ’Commons.Xml.Relaxng.Derivative.RdpAbstractSingleContent.isExpanded’ は割り当てられません。常に既定値 false を使用します。
C:¥Documents and Settings¥makoto¥My Documents¥Visual Studio Projects¥NvdlLibrary¥RelaxngValidatingReader.cs(70,8): warning CS0169: private フィールド ’Commons.Xml.Relaxng.RelaxngValidatingReader.labelsComputed’ が一度も使用されませんでした。
C:¥Documents and Settings¥makoto¥My Documents¥Visual Studio Projects¥NvdlLibrary¥RelaxngValidatingReader.cs(73,8): warning CS0169: private フィールド ’Commons.Xml.Relaxng.RelaxngValidatingReader.isEmptiable’ が一度も使用されませんでした。
c:¥Documents and Settings¥makoto¥My Documents¥Visual Studio Projects¥NvdlLibrary¥commons.xml.relaxng.rnc¥RncParser.jay(60,14): warning CS0649: フィールド ’Commons.Xml.Relaxng.Rnc.RncParser.yacc_verbose_flag’ は割り当てられません。常に既定値 0 を使用します。
C:¥Documents and Settings¥makoto¥My Documents¥Visual Studio Projects¥NvdlLibrary¥RncTokenizer.cs(49,8): warning CS0169: private フィールド ’Commons.Xml.Relaxng.Rnc.RncTokenizer.isLiteralNsUri’ が一度も使用されませんでした。


この記事を共有:

前の記事
SRE
次の記事
Bounties for Gnome's Optimization