XML Schema or RELAX NG with Embedded Schematron Rules

Schematron rules can be embedded into an XML Schema through annotations (using the appinfo element), or in any element on any level of a RELAX NG Schema (taking into account that the RELAX NG validator ignores all elements that are not in the RELAX NG namespace).

Oxygen XML Editor plugin accepts such documents as Schematron validation schemas and it is able to extract and use the embedded rules.

Validating XML Documents with Relax NG and Embedded Schematron

To validate an XML document with both RELAX NG schema and its embedded Schematron rules, you need to associate the document with both schemas. For example:

<?xml-model href="percent.rng" type="application/xml" 
            schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="percent.rng" type="application/xml" 
            schematypens="http://purl.oclc.org/dsdl/schematron"?>

The second association validates your document with Schematron rules extracted from the RELAX NG Schema.

Validating XML Documents with XML Schema and Embedded Schematron

Similarly, you can specify an XML Schema having the embedded Schematron rules.

<?xml-model href="percent.xsd" type="application/xml" 
            schematypens="http://purl.oclc.org/dsdl/schematron"?>

Note

When you work with XML Schema or Relax NG documents that have embedded Schematron rules Oxygen XML Editor plugin provides two built-in validation scenarios: Validate XML Schema with embedded Schematron for XML schema , and Validate Relax NG with embedded Schematron for Relax NG. You can use one of these scenarios to validate the embedded Schematron rules.

Example: Embedded Schematron in Relax NG Schema

<sch:pattern>
  <sch:rule context="...">
    <sch:assert test="...">Message.</sch:assert>
  </sch:rule>
</sch:pattern>

Example: Embedded Schematron in XML Schema

<xsd:appinfo>
  <sch:pattern>
    <sch:rule context="...">
	<sch:assert test="...">Message.</sch:assert>
    </sch:rule>
  </sch:pattern>
</xsd:appinfo>

Was this helpful?