Re: p:validate-with-xml-schema

James Garriss <james@garriss.org> writes:

> I guess I don't know how everyone else uses XML Schema (or RelaxNG or
> Schematron), but when I do schema validation I want to know if my XML is
> valid or not (and if not, why not?).
>
> Two questions, if I may:
>
> 1) Why does this step return a PSVI instead of true/false?  I'd like to
> understand the thinking.

In the case of W3C XML Schema at least, schema validation performs
type assignment and augments the infoset with new information. For
many users, this new type information is at least as important as
validity checking.

> 2) How can I get it to return true/false?

For better or worse, I think the best thing you can do today is define
your own pipeline that returns the result you want:

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
		xmlns:c="http://www.w3.org/ns/xproc-step"
		type="px:is-valid"
		name="is-valid">
<p:input port="source" primary="true"/>
<p:input port="schema" sequence="true"/>
<p:output port="result"/>
<p:option name="mode" select="'strict'"/>

<p:try>
  <p:group>
    <p:validate-with-xml-schema assert-valid="true">
      <p:input port="source">
	<p:pipe step="is-valid" port="source"/>
      </p:input>
      <p:input port="schema">
	<p:pipe step="is-valid" port="schema"/>
      </p:input>
      <p:with-option name="mode" select="$mode"/>
    </p:validate-with-xml-schema>
    <p:choose>
      <p:when test="/*">
	<p:identity>
	  <p:input port="source">
	    <p:inline><c:result>true</c:result></p:inline>
	  </p:input>
	</p:identity>
      </p:when>
      <p:otherwise>
	<!-- this can't happen -->
	<p:identity>
	  <p:input port="source">
	    <p:inline><c:result>false</c:result></p:inline>
	  </p:input>
	</p:identity>
      </p:otherwise>
    </p:choose>
  </p:group>
  <p:catch>
    <p:identity>
      <p:input port="source">
	<p:inline><c:result>false</c:result></p:inline>
      </p:input>
    </p:identity>
  </p:catch>
</p:try>
</p:declare-step>

If you put the preceding declaration in your pipeline, then you can call
it as a step:

<px:is-valid>
  <p:input port="source">
    ...
  </p:input>
  <p:input port="schema">
    ...
  </p:input>
</px:is-valid>

and it will produce <c:result>true|false</c:result> on its primary
output port. *And* Calabash 0.6.2, released this morning, will in fact
run it. :-)

On the one hand, this may seem like a fairly clumsy answer. On the
other, you can stick this pipeline, and other utility pipelines that
you write, in a library, import that library, and then it just becomes
another step you can call.

Support for calling declared pipelines in Calabash is very fragile,
but I'm working on it.

I don't think p:import works yet, but I'm working on that too.

                                        Be seeing you,
                                          norm

-- 
Norman Walsh <ndw@nwalsh.com> | When we are tired, we are attacked by
http://nwalsh.com/            | ideas we conquered long ago.-- Nietzsche

Received on Friday, 26 September 2008 12:32:53 UTC