Validate module and catalogs

Wednesday, 2 September 2015 · 4 messages · last reply 15 Sep 2015
LV
Lizzi, Vincent2 Sep 2015 03:18 #
It appears that the Validate module is not using catalogs. I'm working with XML that contains a DTD DOCTYPE declaration with a public identifier and a system identifier that contains the filename of the DTD, and I have set up a catalog that provides the DTD location. Here is a rough example:
declare option db:chop 'false';
declare option db:dtd 'true';
declare option db:catfile 'schemas/catalog.xml';

let $xmlFile := 'path/to/file.xml'
let $parsed := doc($xmlFile)
let $report := validate:dtd-report($xmlFile)
return ($report, $parsed)
This fails on the validate:dtd-report line. The error report indicates that BaseX is trying to find the DTD in the same folder as the XML file. I know the catalog is working because the doc() call is parsing the XML and populating default attributes, and if I remove the db:catfile option declaration the doc() call fails. If I add a path to the DTD in the second parameter in validate:dtd-report($xmlFile, 'path/to/dtd.dtd') the validation works. I'm not sure why this is needed because the XML contains a DOCTYPE and the catalog should be resolving the DTD location. Is this intentional? There are use cases to require that validation is done using a specific DTD and not simply any DTD that the XML happens to declare. In other cases however it is easier to validate using the DTD that is already identified in the DOCTYPE of the XML file. Is this a bug? Thanks, Vincent
AH
Alexander Holupirek2 Sep 2015 10:31 #
Hi Vincent, i'm trying to reproduce your problem. This is what I did.
$ wget http://files.basex.org/releases/latest/BaseX83-20150825.081504.zip
$ unzip BaseX83-20150825.081504.zip
$ ./bin/basexgui
GUI:
declare option db:chop 'false';
declare option db:dtd 'true';
declare option db:catfile 'etc/catalog.xml';

let $xmlFile := 'etc/factbook.xml'
let $parsed := doc($xmlFile)
let $report := validate:dtd-report($xmlFile)
return ($report, $parsed)
Result
<report>
  <status>invalid</status>
  <message level="Error" line="2" column="10" url="file:/Users/holu/code/test/basex/etc/factbook.xml">Document root element "mondial", must match DOCTYPE root "null".</message>
  <message level="Error" line="2" column="10" url="file:/Users/holu/code/test/basex/etc/factbook.xml">Document is invalid: no grammar found.</message>
</report>
<mondial>
  <continent id="f0_119" name="Europe"/>
  <continent id="f0_123" name="Asia"/>
  <continent id="f0_126" name="America"/>
  <continent id="f0_129" name="Australia/Oceania"/>
  ...
Can we try to 'model' your problem using data that is available in the public? Thanks A. Holupirek
Quoted text · Vincent · 23 lines
> On 02.09.2015, at 03:18, Lizzi, Vincent <Vincent.Lizzi at taylorandfrancis.com> wrote: > > It appears that the Validate module is not using catalogs. I’m working with XML that contains a DTD DOCTYPE declaration with a public identifier and a system identifier that contains the filename of the DTD, and I have set up a catalog that provides the DTD location. Here is a rough example: > > declare option db:chop 'false'; > declare option db:dtd 'true'; > declare option db:catfile 'schemas/catalog.xml'; > > let $xmlFile := ‘path/to/file.xml’ > let $parsed := doc($xmlFile) > let $report := validate:dtd-report($xmlFile) > return ($report, $parsed) > > This fails on the validate:dtd-report line. The error report indicates that BaseX is trying to find the DTD in the same folder as the XML file. > > I know the catalog is working because the doc() call is parsing the XML and populating default attributes, and if I remove the db:catfile option declaration the doc() call fails. > > If I add a path to the DTD in the second parameter in validate:dtd-report($xmlFile, ‘path/to/dtd.dtd’) the validation works. I’m not sure why this is needed because the XML contains a DOCTYPE and the catalog should be resolving the DTD location. > > Is this intentional? There are use cases to require that validation is done using a specific DTD and not simply any DTD that the XML happens to declare. In other cases however it is easier to validate using the DTD that is already identified in the DOCTYPE of the XML file. Is this a bug? > > Thanks, > Vincent
CG
Christian Grünin reply to Lizzi, Vincent, 2 Sep 2015, 03:1814 Sep 2015 12:40 #
Hi Vincent, As you already found out, the catalog option is currently not applied when validating resources. Currently, it's only applied when parsing and importing XML documents [1]. As you have recently worked on Schematron validation (thanks again), maybe you already know how this is done in Java? If yes, I invite you to send me some Java code, and I will include it in our XQuery DTD (and maybe XSD) functions [2]. Thanks, Christian [1] https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/build/xml/SAXWrapper.java#L70-L71 [2] https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/query/func/validate/
Quoted text · Vincent · 57 lines
On Wed, Sep 2, 2015 at 3:18 AM, Lizzi, Vincent <Vincent.Lizzi at taylorandfrancis.com> wrote: > It appears that the Validate module is not using catalogs. I’m working with > XML that contains a DTD DOCTYPE declaration with a public identifier and a > system identifier that contains the filename of the DTD, and I have set up a > catalog that provides the DTD location. Here is a rough example: > > > > declare option db:chop 'false'; > > declare option db:dtd 'true'; > > declare option db:catfile 'schemas/catalog.xml'; > > > > let $xmlFile := ‘path/to/file.xml’ > > let $parsed := doc($xmlFile) > > let $report := validate:dtd-report($xmlFile) > > return ($report, $parsed) > > > > This fails on the validate:dtd-report line. The error report indicates that > BaseX is trying to find the DTD in the same folder as the XML file. > > > > I know the catalog is working because the doc() call is parsing the XML and > populating default attributes, and if I remove the db:catfile option > declaration the doc() call fails. > > > > If I add a path to the DTD in the second parameter in > validate:dtd-report($xmlFile, ‘path/to/dtd.dtd’) the validation works. I’m > not sure why this is needed because the XML contains a DOCTYPE and the > catalog should be resolving the DTD location. > > > > Is this intentional? There are use cases to require that validation is done > using a specific DTD and not simply any DTD that the XML happens to declare. > In other cases however it is easier to validate using the DTD that is > already identified in the DOCTYPE of the XML file. Is this a bug? > > > > Thanks, > > Vincent > >
LV
Lizzi, Vincent15 Sep 2015 01:46 #
Hi Christian, Yes, I will give it a try. This will also help in a current project for my work. Thanks for the links to the relevant sections of code. Thanks for adding the link to my Schematron XQuery module! Vincent
Quoted text · Christian Grün · 69 lines
-----Original Message----- From: Christian Grün [mailto:christian.gruen at gmail.com] Sent: Monday, September 14, 2015 6:41 AM To: Lizzi, Vincent <Vincent.Lizzi at taylorandfrancis.com> Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Validate module and catalogs Hi Vincent, As you already found out, the catalog option is currently not applied when validating resources. Currently, it's only applied when parsing and importing XML documents [1]. As you have recently worked on Schematron validation (thanks again), maybe you already know how this is done in Java? If yes, I invite you to send me some Java code, and I will include it in our XQuery DTD (and maybe XSD) functions [2]. Thanks, Christian [1] https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/build/xml/SAXWrapper.java#L70-L71 [2] https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/query/func/validate/ On Wed, Sep 2, 2015 at 3:18 AM, Lizzi, Vincent <Vincent.Lizzi at taylorandfrancis.com> wrote: > It appears that the Validate module is not using catalogs. I’m working > with XML that contains a DTD DOCTYPE declaration with a public > identifier and a system identifier that contains the filename of the > DTD, and I have set up a catalog that provides the DTD location. Here is a rough example: > > > > declare option db:chop 'false'; > > declare option db:dtd 'true'; > > declare option db:catfile 'schemas/catalog.xml'; > > > > let $xmlFile := ‘path/to/file.xml’ > > let $parsed := doc($xmlFile) > > let $report := validate:dtd-report($xmlFile) > > return ($report, $parsed) > > > > This fails on the validate:dtd-report line. The error report indicates > that BaseX is trying to find the DTD in the same folder as the XML file. > > > > I know the catalog is working because the doc() call is parsing the > XML and populating default attributes, and if I remove the db:catfile > option declaration the doc() call fails. > > > > If I add a path to the DTD in the second parameter in > validate:dtd-report($xmlFile, ‘path/to/dtd.dtd’) the validation works. > I’m not sure why this is needed because the XML contains a DOCTYPE and > the catalog should be resolving the DTD location. > > > > Is this intentional? There are use cases to require that validation is > done using a specific DTD and not simply any DTD that the XML happens to declare. > In other cases however it is easier to validate using the DTD that is > already identified in the DOCTYPE of the XML file. Is this a bug? > > > > Thanks, > > Vincent > >

⚡Generated with XQuery