Good day, Where is the catalog.xml file stored? I want to validate xml files against XSD, but the xsd is referenced via an urn. thank you very much
Guten Tag, Wo wird die catalog.xml Datei abgelegt? Ich möchte xml-Dateien gegen XSD validieren, aber die XSD wird über einen urn referenziert. Herzlichen Dank
xdomea:Aussonderung.Aussonderung.0503 xmlns:xdomea="urn:xoev-de:xdomea:schema:2.3.0"
tl;dr
– Don’t bother that the namespace is a URN. – Don’t confuse namespaces with schema locations. – Apparently BaseX cannot use a catalog resolver for resolving schema locations. – Use other more or less portable ways for accessing the schemas, for ex. store them in a database or put the base file system paths into an external variable. – There is no default catalog location; you specify the catalog to use with the CATFILE option.
Hi,
You can store an XML catalog file anywhere you like. Then you set the option CATFILE to this file location, or you can do it in the XQuery file like this:
declare option db:catfile "path/relative/to/cwd/catalog.xml";
Of course you can also supply an absolute path.
On 21.10.2019 22:05, SW-Service wrote:
Good day, Where is the catalog.xml file stored? I want to validate xml files against XSD, but the xsd is referenced via an urn. thank you very much
Guten Tag, Wo wird die catalog.xml Datei abgelegt? Ich möchte xml-Dateien gegen XSD validieren, aber die XSD wird über einen urn referenziert. Herzlichen Dank
<xdomea:Aussonderung.Aussonderung.0503 xmlns:xdomea="urn:xoev-de:xdomea:schema:2.3.0">
This line only contains a namespace declaration and no schema association.
Does your document contain an xsi:schemaLocation attribute? Then this can be taken into account for validation, see [1].
Suppose the schema location had the same URN as the namespace, I’d expect a document like this:
<xdomea:Aussonderung.Aussonderung.0503 xmlns:xdomea="urn:xoev-de:xdomea:schema:2.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:xoev-de:xdomea:schema:2.3.0 urn:xoev-de:xdomea:schema:2.3.0"> </xdomea:Aussonderung.Aussonderung.0503>
The xsi:schemaLocation attribute contains first the namespace, then the schema location (accidentally the same URIs). Only the latter is subject to catalog resolution.
Suppose you have a catalog
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> <uri name="urn:xoev-de:xdomea:schema:2.3.0" uri="foobar.xsd"/> </catalog>
and the XSD foobar.xsd (in the same directory as the catalog):
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:xoev-de:xdomea:schema:2.3.0"> <xs:element name="Aussonderung.Aussonderung.0503"/> </xs:schema>
Then oXygen, for example, will honor the catalog’s mapping and validate against foobar.xsl.
But I just found out that BaseX’s XSD validator will not use the catalog in order to resolve the schema location’s URI.
I think BaseX uses catalogs only for two things: When importing files into a database and, recently, for the XSLT processor [2].
It doesn’t seem to use it for doc(), either, so reading doc('urn:xoev-de:xdomea:schema:2.3.0'), which should resolve to foobar.xsd, doesn’t work.
This means if you use BaseX, you need to access the schema in another way. You can put all the XOEV schemas in a database and validate like this:
validate:xsd-report('C:/…/mydoc.xml', db:open('xoev-schema', 'foobar.xsd'))
assuming that xoev-schema is the name of the database and foobar.xsd the relative path of the schema, relative to where you imported it from.
You can also refer to an actual location in the file system, with the base path optionally declared by an external variable, in order not to make it too dependent on the given directory structure.
declare namespace xs = 'http://www.w3.org/2001/XMLSchema'; declare variable $basedir-uri external := file:path-to-uri(Q{org.basex.util.Prop}HOMEDIR()) || 'xoev/xsd/';
validate:xsd-report('C:/cygwin/home/gerrit/XML/basex/2019-10-21_xoev/Untitled14.xml', doc($basedir-uri || 'foobar.xsd'))
This lets users supply a value for $basedir-uri (using the $x button in the GUI) if they don’t have the schemas in the default location, which is the user’s home directory plus 'xoev/xsd/' in this example.
Please let me know where I lost you on the way.
Gerrit
[1] http://docs.basex.org/wiki/Validation_Module#XML_Schema_Validation [2] https://github.com/BaseXdb/basex/issues/1719
On 21.10.2019 22:05, SW-Service wrote:
<xdomea:Aussonderung.Aussonderung.0503 xmlns:xdomea="urn:xoev-de:xdomea:schema:2.3.0">
Somewhat unrelated to your initial question, and it was probably someone else’s idea to put a minor version number in a namespace – but this is considered bad practice.
All processing applications, for example XSLT stylesheets or editing environments, need to be adapted when the namespace changes. This can probably be avoided by matching only local names in XSLT, but why use namespaces at all when you end up ignoring them?
If a schema is likely to undergo significant changes between major versions, it might be acceptable to include the major version in the namespace. In general, it is better to use a version attribute in the document instead so that transformation rules, editor configurations or schema co-occurrence constraints can be customized to reflect specific differences between the versions.
Gerrit
basex-talk@mailman.uni-konstanz.de