Re: Import validation

Michael Westbay <[email protected]> Fri, 15 Dec 2023 09:03:55 +0900
Newsgroups gmane.text.xml.exist
Message-ID <CAJ6MVuO5-1GXRNky_UeCBkodR+GyAQ+ObcA_i1EHw9H7_R4Nuw@mail.gmail.com>
Hi Ted,

Let's first break down your program:

xquery version "3.0";
> let $schema :=
> xs:anyURI('/db/apps/HTML_Student/SVG_Ellipse_Webpage_XML_Schema.xsd')
> let $instance :=
> xs:anyURI('/db/apps/HTML_Student/SVG_Ellipse_Webpage_XML.xml')
> return
> (validation:clear-grammar-cache(), validation:validate-report($instance,
> $schema))
>

The two *let* statements assign values to the variables *$schemai and
$instance*. So far, so good.

Then you make two function calls in the *return* statement, these to:

・ *validation:clear-grammar-cache*()
・ *validation:validate-report*(...)

The *validation* namespace is NOT built into XQuery. It needs to be loaded
into your program.

A quick check of the XQuery Function Documentation for "validation" (
https://exist-db.org/exist/apps/fundocs/index.html) shows that the
namespace of *http://exist-db.org/xquery/validation
<http://exist-db.org/xquery/validation>* has the first function, but not
the second. The closest function to the second is the
*validation:jaxp-report/3* function:

validation:jaxp-report

validation:jaxp-report($instance as item(), $enable-grammar-cache as
xs:boolean, $catalogs as item()*) as node()

Validate document by parsing $instance. Optionally grammar caching can be
enabled and an XML catalog can be specified. Supported grammars types are
'.xsd' and '.dtd'. An XML report is returned.
Parameters:
$instance The document referenced as xs:anyURI, a node (element or result
of fn:doc()) or as a Java file object.
$enable-grammar-cache Set the flag to true() to enable grammar caching.
$catalogs* The catalogs referenced as xs:anyURI's.Returns:node() : a
validation report.


To import the *validation* namespace into your program, enter the following
after the XQuery version line:

import module namespace "http://exist-db.org/xquery/validation";


Importing modules is one of the core functionalities of XQuery for code
reuse. I strongly recommend reading this page about creating (and using)
XQuery functions from the XQuery WikiBook:

https://en.wikibooks.org/wiki/XQuery/Creating_XQuery_Functions


That explains how to create your own modules and import them. The example I
provided above (which doesn't have the *at* clause) is for modules built
into eXist.

The XQuery Function Documentation page and XQuery WikiBook are two
resources you should have bookmarked.

Hope this helps.

-- 
Michael Westbay
Writer/System Administrator
http://www.japanesebaseball.com/

_______________________________________________
Exist-open mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/exist-open