Hello,
I've just discovered BaseX and decided to make some experiments. One of them is, suppose I have several documents (data + schemas), something like this:
sys/core.xsd
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:SYS-CORE" targetNamespace="urn:SYS-CORE"> <xs:attribute name="category" type="xs:normalizedString"/> </xs:schema>
lib/album.xsd
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:SYS-CORE ../sys/core.xsd" xmlns:sys="urn:SYS-CORE" xmlns="urn:LIB-ALBUM" targetNamespace="urn:LIB-ALBUM"> <xs:import namespace="urn:SYS-CORE"/> <xs:element name="album"> <xs:complexType> <xs:sequence> <xs:element ref="title" minOccurs="1" maxOccurs="1"/> </xs:sequence> <xs:attribute ref="sys:category" use="required"/> </xs:complexType> </xs:element> <xs:element name="title" type="xs:normalizedString"/> </xs:schema>
usr/albums/album1.xml
<?xml version="1.0"?> <album xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:LIB-ALBUM ../../lib/album.xsd" xmlns:sys="urn:SYS-CORE" sys:category="albums" xmlns="urn:LIB-ALBUM"> <title>Album #1</title> </album>
I'm uploading these documents using a Python script (I'm using BaseXClient) preserving the file system hierarchy structure I defined above. If I open the documents in IntelliJ IDEA, I can be sure that the documents are valid (I mean, I don't see XSD validation errors), therefore I'm assuming they are valid by fact. However, if I'm trying to validate the XML documents on the BaseX side
session.execute('XQUERY for $doc in collection("%s") where fn:ends-with(fn:base-uri($doc), ".xml") return validate:xsd($doc)' % database)
I'm getting the following error
[bxerr:BXVA0001] Validation failed: 1:186: schema_reference.4: Failed to read schema document '../../lib/album.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
I'm wondering, what am I doing wrong trying to validate documents directly in BaseX? Can BaseX resolve absolute/relative paths in this case?
Thanks in advance!
P.S. Apologies if I made something wrong (wrong subject, mailing list, non text/plain email, etc), this is my first time sending an email to a mailing list. P.P.S. This email may contain an ad footer since I use this free email service. If possible, please trim the ad away before it's sent/archived. Thanks!
-- реклама ----------------------------------------------------------- http://FREEhost.UA - Купи хостинг или домен и получи сертификат Google AdWords номиналом 900 грн.в подарок! - http://goo.gl/EcgF4I
Hello,
As far as I have understood it, it all depends on how you start basex. If you open it using the command line from the same folder where your relative paths are rooted, it should work fine.
Best regards, Kristian K
15.01.2018 14:09 Aleksandr Shapovaov kirjutas:
Hello,
I've just discovered BaseX and decided to make some experiments. One of them is, suppose I have several documents (data + schemas), something like this:
sys/core.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:SYS-CORE" targetNamespace="urn:SYS-CORE"> <xs:attribute name="category" type="xs:normalizedString"/> </xs:schema>
lib/album.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:SYS-CORE ../sys/core.xsd" xmlns:sys="urn:SYS-CORE" xmlns="urn:LIB-ALBUM" targetNamespace="urn:LIB-ALBUM"> <xs:import namespace="urn:SYS-CORE"/> <xs:element name="album"> xs:complexType xs:sequence <xs:element ref="title" minOccurs="1" maxOccurs="1"/> </xs:sequence> <xs:attribute ref="sys:category" use="required"/> </xs:complexType> </xs:element> <xs:element name="title" type="xs:normalizedString"/> </xs:schema>
usr/albums/album1.xml
<?xml version="1.0"?>
<album xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:LIB-ALBUM ../../lib/album.xsd" xmlns:sys="urn:SYS-CORE" sys:category="albums" xmlns="urn:LIB-ALBUM">
<title>Album #1</title> </album>
I'm uploading these documents using a Python script (I'm using BaseXClient) preserving the file system hierarchy structure I defined above. If I open the documents in IntelliJ IDEA, I can be sure that the documents are valid (I mean, I don't see XSD validation errors), therefore I'm assuming they are valid by fact. However, if I'm trying to validate the XML documents on the BaseX side
session.execute('XQUERY for $doc in collection("%s") where fn:ends-with(fn:base-uri($doc), ".xml") return validate:xsd($doc)' % database)
I'm getting the following error
[bxerr:BXVA0001] Validation failed: 1:186: schema_reference.4: Failed to read schema document '../../lib/album.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not xsd:schema.
I'm wondering, what am I doing wrong trying to validate documents directly in BaseX? Can BaseX resolve absolute/relative paths in this case?
Thanks in advance!
P.S. Apologies if I made something wrong (wrong subject, mailing list, non text/plain email, etc), this is my first time sending an email to a mailing list. P.P.S. This email may contain an ad footer since I use this free email service. If possible, please trim the ad away before it's sent/archived. Thanks!
-- реклама ----------------------------------------------------------- http://FREEhost.UA - Купи хостинг или домен и получи сертификат Google AdWords номиналом 900 грн.в подарок! - http://goo.gl/EcgF4I
Hello again,
You could look at the functions defined in the File module [1] and try to rewrite the relative path given in your @xsi:schemaLocation to an absolute path.
If the file:resolve-path function doesn't work, the for example file:parent(static-base-uri()) gives you the absolute path to the directory of the current XQuery module.
Best regards, Kristian K
[1]: http://docs.basex.org/wiki/File_Module#file:list
15.01.2018 14:55 Kristian Kankainen kirjutas:
Hello,
As far as I have understood it, it all depends on how you start basex. If you open it using the command line from the same folder where your relative paths are rooted, it should work fine.
Best regards, Kristian K
15.01.2018 14:09 Aleksandr Shapovaov kirjutas:
Hello,
I've just discovered BaseX and decided to make some experiments. One of them is, suppose I have several documents (data + schemas), something like this:
sys/core.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:SYS-CORE" targetNamespace="urn:SYS-CORE"> <xs:attribute name="category" type="xs:normalizedString"/> </xs:schema>
lib/album.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:SYS-CORE ../sys/core.xsd" xmlns:sys="urn:SYS-CORE" xmlns="urn:LIB-ALBUM" targetNamespace="urn:LIB-ALBUM"> <xs:import namespace="urn:SYS-CORE"/> <xs:element name="album"> xs:complexType xs:sequence <xs:element ref="title" minOccurs="1" maxOccurs="1"/> </xs:sequence> <xs:attribute ref="sys:category" use="required"/> </xs:complexType> </xs:element> <xs:element name="title" type="xs:normalizedString"/> </xs:schema>
usr/albums/album1.xml
<?xml version="1.0"?>
<album xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:LIB-ALBUM ../../lib/album.xsd" xmlns:sys="urn:SYS-CORE" sys:category="albums" xmlns="urn:LIB-ALBUM">
<title>Album #1</title> </album>
I'm uploading these documents using a Python script (I'm using BaseXClient) preserving the file system hierarchy structure I defined above. If I open the documents in IntelliJ IDEA, I can be sure that the documents are valid (I mean, I don't see XSD validation errors), therefore I'm assuming they are valid by fact. However, if I'm trying to validate the XML documents on the BaseX side
session.execute('XQUERY for $doc in collection("%s") where fn:ends-with(fn:base-uri($doc), ".xml") return validate:xsd($doc)' % database)
I'm getting the following error
[bxerr:BXVA0001] Validation failed: 1:186: schema_reference.4: Failed to read schema document '../../lib/album.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not xsd:schema.
I'm wondering, what am I doing wrong trying to validate documents directly in BaseX? Can BaseX resolve absolute/relative paths in this case?
Thanks in advance!
P.S. Apologies if I made something wrong (wrong subject, mailing list, non text/plain email, etc), this is my first time sending an email to a mailing list. P.P.S. This email may contain an ad footer since I use this free email service. If possible, please trim the ad away before it's sent/archived. Thanks!
-- реклама ----------------------------------------------------------- http://FREEhost.UA - Купи хостинг или домен и получи сертификат Google AdWords номиналом 900 грн.в подарок! - http://goo.gl/EcgF4I
Hello Kristian,
Thank you for two replies!
I'm afraid I was totally unclear asking the question. If I understand how BaseX works, my initial
I'm uploading these documents using a Python script (I'm using BaseXClient) preserving the file system hierarchy structure I defined above.
should be interpreted as "I used ADD TO to store my XML documents in a database/collection giving the document names according to their relative paths on my real file system." Let's say, if I have documents on a file system ./lib/schema.xsd and ./usr/doc1.xml where the latter refers the schema as `../lib/schema.xsd`, I store the documents to the database with names lib/schema.xds and usr/doc1.xml respectively. That's why I thought that ../lib/schema.xsd might be resolved to absolute lib/schema.xsd directly in the database when I called the documents validation function.
Why I still think like that? The documentation says, the ADD syntax is `ADD (TO [path]) [input]` -- I identified the path as something that is an equivalent to a file system path. Am I wrong about this and I totally misinterpret it?
Thanks!
16.01.2018 17:03, Kristian Kankainen <kristian@keeleleek.ee>
Hello again, You could look at the functions defined in the File module [1] and try to rewrite the relative path given in your @xsi:schemaLocation to an absolute path. If the file:resolve-path function doesn't work, the for example file:parent(static-base-uri()) gives you the absolute path to the directory of the current XQuery module. Best regards, Kristian K [1]: http://docs.basex.org/wiki/File_Module#file:list 15.01.2018 14:55 Kristian Kankainen kirjutas:
Hello, As far as I have understood it, it all depends on how you start basex. If you open it using the command line from the same folder where your relative paths are rooted, it should work fine. Best regards, Kristian K 15.01.2018 14:09 Aleksandr Shapovaov kirjutas:
Hello,
I've just discovered BaseX and decided to make some experiments. One of them is, suppose I have several documents (data + schemas), something like this:
sys/core.xsd
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:SYS-CORE" targetNamespace="urn:SYS-CORE"> <xs:attribute name="category" type="xs:normalizedString"/> </xs:schema>
lib/album.xsd
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:SYS-CORE ../sys/core.xsd" xmlns:sys="urn:SYS-CORE" xmlns="urn:LIB-ALBUM" targetNamespace="urn:LIB-ALBUM"> <xs:import namespace="urn:SYS-CORE"/> <xs:element name="album"> <xs:complexType> <xs:sequence> <xs:element ref="title" minOccurs="1" maxOccurs="1"/> </xs:sequence> <xs:attribute ref="sys:category" use="required"/> </xs:complexType> </xs:element> <xs:element name="title" type="xs:normalizedString"/> </xs:schema>
usr/albums/album1.xml
<?xml version="1.0"?> <album xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:LIB-ALBUM ../../lib/album.xsd" xmlns:sys="urn:SYS-CORE" sys:category="albums" xmlns="urn:LIB-ALBUM"> <title>Album #1</title> </album>
I'm uploading these documents using a Python script (I'm using BaseXClient) preserving the file system hierarchy structure I defined above. If I open the documents in IntelliJ IDEA, I can be sure that the documents are valid (I mean, I don't see XSD validation errors), therefore I'm assuming they are valid by fact. However, if I'm trying to validate the XML documents on the BaseX side
session.execute('XQUERY for $doc in collection("%s") where fn:ends-with(fn:base-uri($doc), ".xml") return validate:xsd($doc)' % database)
I'm getting the following error
[bxerr:BXVA0001] Validation failed: 1:186: schema_reference.4: Failed to read schema document '../../lib/album.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
I'm wondering, what am I doing wrong trying to validate documents directly in BaseX? Can BaseX resolve absolute/relative paths in this case?
Thanks in advance!
P.S. Apologies if I made something wrong (wrong subject, mailing list, non text/plain email, etc), this is my first time sending an email to a mailing list. P.P.S. This email may contain an ad footer since I use this free email service. If possible, please trim the ad away before it's sent/archived. Thanks!
-- реклама ----------------------------------------------------------- http://FREEhost.UA - Купи хостинг или домен и получи сертификат Google AdWords номиналом 900 грн.в подарок! - http://goo.gl/EcgF4I
basex-talk@mailman.uni-konstanz.de