Page 1 of 1

Saxon XQuery - using catalogs

Posted: Wed Jan 27, 2010 8:21 pm
by sanderson
I depend on catalogs for resolving DTDs in my XML files. When I use Saxon for xquery at the command-line, I include a -x and a -r option (-r:org.apache.xml.resolver.tools.CatalogResolver
-x:org.apache.xml.resolver.tools.ResolvingXMLReader). I found that I can specify the -r option in the Saxon advanced preferences in Oxygen and I can specify the XMLReader in my query. Sadly things still aren't working. The specific error I get is this:

SystemID: /xquery/find_topicrefs_w_href_w_child_topicref.xquery
Engine name: Saxon-PE XQuery 9.2.0.3
Severity: error
Description: /sanderson_dev/dev/doc/164/patch/core/en/xmlsource/map.dtd (No such file or directory)

I suspect this error is because the transform isn't finding my CatalogManager.properties file

I've specified the catalog I want to use in the preferences for XML Catalog. It works for XSLT, just not for XQuery.

Grasping, I have added the path to my CatalogManager.properties file to the classpath for the Document Type (DITA), but that doesn't seem to make any difference.

Do I have to specify the path to that file as a parameter or extension to the xquery scenario I'm using? Or, is there some other way to specify which CatalogManager.properties file gets picked up for XQuery transforms?

Re: Saxon XQuery - using catalogs

Posted: Thu Jan 28, 2010 2:05 am
by sanderson
Rephrasing, for clarity

I depend on catalogs for resolving DTDs in my XML files. I've specified the catalog I want to use in the preferences for XML Catalog. It works for XSLT, just not for XQuery.

The specific error I get is this:

SystemID: /xquery/find_topicrefs_w_href_w_child_topicref.xquery
Engine name: Saxon-PE XQuery 9.2.0.3
Severity: error
Description: /sanderson_dev/dev/doc/164/patch/core/en/xmlsource/map.dtd (No such file or directory)

Any ideas?

Steve

Re: Saxon XQuery - using catalogs

Posted: Thu Jan 28, 2010 1:54 pm
by stefan
You only need to create an XML catalog (ex: topicRefCat.xml) and add it to the "Preferences->XML->XML Catalog" Catalogs list

The XML catalog should contain something like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<system systemId="file:/sanderson_dev/dev/doc/164/patch/core/en/xmlsource/map.dtd" uri="file:/pathto/resolved_map.dtd"/>
</catalog>

Re: Saxon XQuery - using catalogs

Posted: Thu Jan 28, 2010 8:05 pm
by sanderson
sanderson wrote:...I've specified the catalog I want to use in the preferences for XML Catalog. It works for XSLT, just not for XQuery.
In my case, the catalog entry is like this:

Code: Select all


<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="public">
<group xml:base="dtd/">
...
<public publicId="-//OASIS//DTD DITA Map//EN" uri="map.dtd"></public>
...
As I said, it works for XSLT scenarios, just not the XQuery scenarios.

Does xquery require system identifiers?

Re: Saxon XQuery - using catalogs

Posted: Fri Jan 29, 2010 12:14 pm
by stefan
First, if you are using a custom URI resolver class, please make sure that you set it both for XSLT and XQuery, see Preferences:
XML / XSLT-FO-XQuery / XSLT / Saxon / Saxon-HE/PE/EE / Advanced
XML / XSLT-FO-XQuery / XQuery / Saxon-HE/PE/EE / Advanced

If your resolver does not resolve the reference, then the Oxygen catalog resolver will be used.

If you like to resolve the references using Oxygen catalog resolver (that is without the help of your custom URI resolver) then your above catalog entry is correct and should work both for XSLT and XQuery. We would like you to send us (if possible) a sample of your test files to support@oxygenxml.com, as we were not able to reproduce your problem.

Re: Saxon XQuery - using catalogs

Posted: Mon Feb 01, 2010 3:44 pm
by sorin_ristache
Hello,

Thank you for sending the files. That helped us find the problem.
sanderson wrote:I depend on catalogs for resolving DTDs in my XML files. When I use Saxon for xquery at the command-line, I include a -x and a -r option (-r:org.apache.xml.resolver.tools.CatalogResolver
-x:org.apache.xml.resolver.tools.ResolvingXMLReader). I found that I can specify the -r option in the Saxon advanced preferences in Oxygen and I can specify the XMLReader in my query. Sadly things still aren't working. The specific error I get is this:

SystemID: /xquery/find_topicrefs_w_href_w_child_topicref.xquery
Engine name: Saxon-PE XQuery 9.2.0.3
Severity: error
Description: /sanderson_dev/dev/doc/164/patch/core/en/xmlsource/map.dtd (No such file or directory)
You don't have to specify the catalog resolver class of the -r option in the Saxon advanced preferences because the Oxygen catalog resolver that uses the XML catalogs added in Preferences -> XML -> XML Catalog is already set as URI resolver to the Saxon 9 XQuery processor included in Oxygen.

In your case you need a catalog resolver for the collection() function. Just pass the parameter parser=ro.sync.xml.parser.CatalogEnabledXMLReader as specified in the User Manual which will use the XML catalogs that you added in Preferences -> XML -> XML Catalog also for mapping the URIs searched by the Saxon collection() function. That way you don't have to worry about CatalogManager.properties, the location of catalog files, etc.


Regards,
Sorin

Re: Saxon XQuery - using catalogs

Posted: Mon Feb 01, 2010 9:22 pm
by sanderson
If I use that resolver, though, I lose the ability to run the parser in other environments, such as from the command-line.

Do I have any other options?

Re: Saxon XQuery - using catalogs

Posted: Tue Feb 02, 2010 10:33 am
by sorin_ristache
In that case you can use the class org.apache.xml.resolver.tools.ResolvingXMLReader but you have to add the jar file that contains the class and the file CatalogManager.properties to the classpath of the transformation, that is add them as extension in the XQuery transformation scenario.


Regards,
Sorin

Re: Saxon XQuery - using catalogs

Posted: Wed Feb 03, 2010 10:40 pm
by sanderson
I created a new jar file. It contains all the files that are in Apache's resolver.jar plus my CatalogManager.properties.

I added the new jar file as an extension to my query.

I reran the query.

Same error.

Just to verify, I changed the parser= setting in my collection to parser=ro.sync.xml.parser.CatalogEnabledXMLReader and the query worked with that.

Re: Saxon XQuery - using catalogs

Posted: Thu Feb 04, 2010 6:56 pm
by sorin_ristache
sanderson wrote:I created a new jar file. It contains all the files that are in Apache's resolver.jar plus my CatalogManager.properties.

I added the new jar file as an extension to my query.

I reran the query.

Same error.
Sorry, the classes of the org.apache.xml resolver must come in the classpath before the Oxygen resolver classes. Please copy your jar file with the org.apache.xml resolver that you want to use in the folder [Oxygen-folder]/lib/endorsed. The folder endorsed does not exist by default when you install Oxygen.

You have to restart Oxygen after placing your jar file in the endorsed folder and before running the XQuery transformation that uses that catalog resolver.


Regards,
Sorin

Re: Saxon XQuery - using catalogs

Posted: Thu Feb 04, 2010 8:53 pm
by sanderson
Now that's a great solution.

Here's what I did.
  • Copied Apache's resolver.jar into lib/endorsed
  • Copied my CatalogManager.properties into lib/endorsed and updated it to match the new path
  • Added those two files to my XQuery scenario's extensions
And it worked! Now I have an environment that allows me to debug my command-line xquery without having to change anything in the xquery file itself. I do still need to maintain two CatalogManager.properties files, but that's not a big concern for me.

Thank you Sorin for sticking with me on this.

Your user guide is great at calling out things like this. Might I suggest you add this procedure there?