Re: p:validate-with-xml-schema

Well, first, thank you for giving me something to work with.  I appreciate
that, and I'll try and get that running today.

Second, I think you're right, that's clumsy.  If a lot of people need the
pvsi on the output, great, I'm glad XProc gives it to them.  But a lot of
people use XML Schema to find out if an XML is valid or not.  It's my
opinion that the validation result needs to be really simple to access.
Would it be reasonable to add a second output port to
p:validate-with-xml-schema?  Something like this:

    <p:output port="valid" primary="false"/>

If the document validates, then the output would be similar to the output of
p:compare:

   <c:result>true</c:result>

or 

  <c:result>false</c:result>

Alternatively, you could do this:

  <p:output port="result" primary="false"/>      <-- true/false c:result
here 
  <p:output port="pvsi" primary="false"/>        <-- pvsi here

I assume that I'm not the first person to think of this.  If so, why hasn't
this been done already?  If not, is there someplace that I should go to make
this an official suggestion to the WG?

James Garriss
http://garriss.blogspot.com




From: Norman Walsh <ndw@nwalsh.com>
Date: Fri, 26 Sep 2008 08:32:07 -0400
To: XProc Dev <xproc-dev@w3.org>
Subject: Re: p:validate-with-xml-schema
Resent-From: XProc Dev <xproc-dev@w3.org>
Resent-Date: Fri, 26 Sep 2008 12:32:55 +0000

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 15:32:12 UTC