RelaxngValidatingReader is an implementation to validate XML with RELAX NG\r
grammar. You can use full standard grammar components with it.\r
\r
- Currently it supports only grammar xml syntax (in the future it will \r
- support compact syntax).\r
+ Currently it supports both xml syntax and compact syntax.\r
\r
It supports RELAX NG predefined datatypes and XML Schema datatypes (its\r
DatatypeLibrary is http://www.w3.org/2001/XMLSchema-datatypes ).\r
\r
+ All classes which is expected to use are in namespace Commons.Xml.Relaxng,\r
+ except for Commons.Xml.Relaxng.Rnc.RncParser class (which is used to parse\r
+ compact syntax).\r
+ There is another namespace Commons.Xml.Relaxng.Derivative which is not\r
+ expected to be used in users custom classes, though the classes are public\r
+ as yet.\r
+\r
+\r
+** Grammar Object Model\r
+\r
+ RELAX NG grammar structure is represented in abstract RelaxngPattern class\r
+ and its derivations. The easiest way to get this instance is to use\r
+ static Read() method of RelaxngPattern class:\r
+\r
+ RelaxngPattern pattern = RelaxngPattern.Read (\r
+ new XmlTextReader ("relaxng.rng");\r
+\r
+ You can also use RelaxngPattern class to reuse grammar instance, as\r
+ already described (see Grammar Object Model).\r
+\r
+ And also, RelaxngGrammar and its contents can be created with managed code\r
+ like System.Xml.Schema.XmlSchema.\r
+\r
+\r
+** Compact Syntax Support\r
+\r
+ Commons.Xml.Relaxng.dll also supports RELAX NG Compact Syntax. To parse\r
+ compact syntax file, use Commons.Xml.Relaxng.Rnc.RncParser class:\r
+\r
+ RncParser parser = new RncParser (new NameTable ());\r
+ TextReader source = new StreamReader ("relaxng.rnc");\r
+ RelaxngGrammar grammar = parser.Parse (source);\r
+\r
+\r
+** Validating Reader usage\r
+\r
+ RelaxngValidatingReader is used to validate XML document with RELAX NG\r
+ grammar. The usage is simple:\r
+\r
+ XmlReader instance = new XmlTextReader ("instance.xml");\r
+ XmlReader grammar = new XmlTextReader ("my.rng");\r
+ RelaxngValidatingReader reader = \r
+ new RelaxngValidatingReader (instance, grammar);\r
+\r
+ Then Read() method (and other reading methods such as ReadElementString())\r
+ reads the instance, validating with the supplied grammar.\r
+\r
+\r
+** Datatype support\r
+\r
+ Commons.Xml.Relaxng now supports custom datatype library. There are two \r
+ classes from which you have to write classes derived.\r
+\r
+ <ul>\r
+ * RelaxngDatatype: it represents the actual data type\r
+\r
+ * RelaxngDatatypeProvider: it provides the way to get RelaxngDatatype from QName and parameters\r
+ </ul>\r
+\r
+ RelaxngDatatype class has Parse() method which is used for validation.\r
+ Basically RelaxngValidatingReader is only aware of that if the typed\r
+ elements or attributes are parsable (you can override IsValid() method\r
+ to change this behavior) using Parse() method for each datatype.\r
+\r
+ To enable custom datatype support, first you have to implement concrete\r
+ RelaxngDatatype implementations (it only requires to override Parse(), \r
+ Name and NamespaceURI) and then RelaxngDatatypeProvider implementations\r
+ (only GetDatatype() is required) to return the datatypes you implemented\r
+ as above.\r
+\r
+ Basically RelaxngDatatypeProvider is designed to allow to contain \r
+ datatypes in different namespaces (e.g. supporting both XML schema\r
+ datatypes and default namespace types). You can also use \r
+ RelaxngMergedProvider class to combine existing two or more datatype\r
+ providers. However, for ease of datatype search, it is indexed by the\r
+ namespace URI (if you want to mix namespace-overrapped providers, you can\r
+ implement your own merging provider). \r
+\r
\r
** Known bugs\r
\r
not handle the same name define components properly.\r
- Name class analysis and constraint check is not implemented (part\r
of spec 7).\r
- - Empty string won't be validated properly.\r
+ - Empty string might not be validated properly.\r
\r