Previous Up Next


p:validate-with-relax-ng

p:validate-with-relax-ng — Validates a document using a RELAX NG grammar.

Synopsis

<p:declare-step type="p:validate-with-relax-ng">
     <p:input port="source" primary="true"/>
     <p:input port="schema"/>
     <p:output port="result"/>
     <p:option name="dtd-attribute-values" select="'false'"/>      <!-- boolean -->
     <p:option name="dtd-id-idref-warnings" select="'false'"/>     <!-- boolean -->
     <p:option name="assert-valid" select="'true'"/>               <!-- boolean -->
</p:declare-step>

Description

The p:validate-with-relax-ng step applies [RELAX NG] validation to its input document. If assert-valid is true, the step fails if the document is invalid, otherwise a copy of the input appears on the output.

While there's no technical reason that the output couldn't be decorated with type assignments, in practice there aren't any RELAX NG validators that do that at this time.

If the dtd-attribute-values option is true, then the attribute value defaulting conventions of [RELAX NG DTD Compatibility] are also applied. In practice, there aren't any RELAX NG validators that do that at this time either.

If the dtd-id-idref-warnings option is true, then the validator should treat a schema that is incompatible with the ID/IDREF/IDREFs feature of [RELAX NG DTD Compatibility] as if the document was invalid. In other words, this option enables ID/IDREF checking.

If the root element of the schema is c:data or has a c:content-type attribute that specifies a text content type or a media type that the implementation recognizes, then the step should treat the text node descendants of the element as a [RELAX NG Compact Syntax] document for validation. Support for this feature is implementation defined.

Errors

Error Description
err:C0053 Occurs if the assert-valid option is true and the input document is not valid.

Examples

The simplest use of p:validate-with-relax-ng simply validates a document.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc" name="main"
                version="1.0">
    
      <p:identity>
  5     <p:input port="source">
          <p:inline>
            <grammar xmlns="http://relaxng.org/ns/structure/1.0">
              <start>
                <ref name="doc"/>
 10           </start>
              <define name="doc">
                <element name="doc">
                  <optional>
                    <ref name="title"/>
 15               </optional>
                  <zeroOrMore>
                    <ref name="p"/>
                  </zeroOrMore>
                </element>
 20           </define>
              <define name="title">
                <element name="title">
                  <text/>
                </element>
 25           </define>
              <define name="p">
                <element name="p">
                  <text/>
                </element>
 30           </define>
            </grammar>
          </p:inline>
        </p:input>
      </p:identity>
 35 
      <p:validate-with-relax-ng>
        <p:input port="source">
          <p:pipe step="main" port="source"/>
        </p:input>
 40     <p:input port="schema"/>
      </p:validate-with-relax-ng>
    </p:pipeline>
Input Output
1 <doc>
<title>Title</title>
<p>Some paragraph.</p>
</doc>
 
1 <doc>
<title>Title</title>
<p>Some paragraph.</p>
</doc>

In practice, the grammar is rarely “inlined” in the pipeline. In this, and future examples, we'll simply load it from the filesystem.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:validate-with-relax-ng>
  5     <p:input port="schema">
          <p:document href="../docs/grammar.rng"/>
        </p:input>
      </p:validate-with-relax-ng>
    </p:pipeline>
Input Output
1 <doc>
<title>Title</title>
<p>Some paragraph.</p>
</doc>
 
1 <doc>
<title>Title</title>
<p>Some paragraph.</p>
</doc>

If you load a compact syntax schema with p:data (instead of p:document) then XML Calabash will validate with that.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:validate-with-relax-ng>
  5     <p:input port="schema">
          <p:data href="../docs/grammar.rnc"/>
        </p:input>
      </p:validate-with-relax-ng>
    </p:pipeline>
Input Output
1 <doc>
<title>Title</title>
<p>Some paragraph.</p>
</doc>
 
1 <doc>
<title>Title</title>
<p>Some paragraph.</p>
</doc>

Validity errors will cause the step to fail if assert-valid is true.

  1 <p:pipeline xmlns:p="http://www.w3.org/ns/xproc"
                version="1.0">
    
      <p:try>
  5     <p:group>
          <p:validate-with-relax-ng assert-valid="true">
            <p:input port="schema">
              <p:data href="../docs/grammar.rnc"/>
            </p:input>
 10       </p:validate-with-relax-ng>
        </p:group>
        <p:catch>
          <p:identity>
            <p:input port="source">
 15           <p:inline>
                <failed/>
              </p:inline>
            </p:input>
          </p:identity>
 20     </p:catch>
      </p:try>
    </p:pipeline>
Input Output
1 <doc>
<title>Title</title>
<not-valid/>
</doc>
 
1 <failed/>