URLs for BaseX Documents and resolve-uri()
Friday, 17 April 2015 · 5 messages
CG
Hi Eliot,
Quoted text · Eliot Kimber · 3 lines
> This fails under BaseX: > > [FORG0002] Base URI is not absolute: "dfst^dfst-sample-project^develo....
I think it also fails if the base URI starts with a slash. Try this for example:
resolve-uri('abc.xml', '/path/def.xml')What result you would expect from this query, given that it did not raise an error?
Using string operations could be an alternative...
"replace($baseURI, '/[^*]+$', $topicResourcePart)
...but I am not sure if this fulfills all needs.
Christian
Quoted text · Eliot Kimber · 14 lines
> Obviously, this way of representing document URIs internally is not > something that could be easily changed but it is definitely a problem in > terms of the expectations of URI handling by built-in XQuery functions. > > Thanks, > > Eliot > ————— > Eliot Kimber, Owner > Contrext, LLC > http://contrext.com > > >
EK
Eliot Kimber17 Apr 2015 19:51 #
I'm migrating XSLT functions for working with DITA documents to XQuery. As part of this function package I have functions that resolve URI references from one document to another. This involves creating absolute URLs from relative URLs using a document or element as the base URI context.
The problem I'm running into is that the URLs used within BaseX are not absolute (that is, they don't start with "/".
For example, document-uri(root($node)) returns:
dfst^dfst-sample-project^develop/docs/tests/complex_map/complex_map.ditamap
not
/dfst^dfst-sample-project^develop/docs/tests/complex_map/complex_map.ditama p
This causes a problem for resolve-uri(), used like this:
resolve-uri($topicResourcePart, base-uri($topicref))
This fails under BaseX:
[FORG0002] Base URI is not absolute: "dfst^dfst-sample-project^develo....
These libraries are intended to be generic XQuery so I'm trying to avoid having any BaseX-specific logic in these functions.
Is there workaround or other solution to this?
Obviously, this way of representing document URIs internally is not something that could be easily changed but it is definitely a problem in terms of the expectations of URI handling by built-in XQuery functions.
Thanks,
Eliot
—————
Eliot Kimber, Owner
Contrext, LLC
http://contrext.com
EK
Eliot Kimber17 Apr 2015 20:25 #
Related question: is there a preferred way to determine from within an XQuery function that the current XQuery engine is BaseX?
I know I could look to see if a particular BaseX-specific function exists but I was looking for something either more obvious or more general from an XQuery standpoint.
Cheers,
Eliot
—————
Eliot Kimber, Owner
Contrext, LLC
http://contrext.com
Quoted text · Eliot Kimber · 51 lines
On 4/17/15, 10:51 AM, "Eliot Kimber" <ekimber at contrext.com> wrote: >I'm migrating XSLT functions for working with DITA documents to XQuery. As >part of this function package I have functions that resolve URI references >from one document to another. This involves creating absolute URLs from >relative URLs using a document or element as the base URI context. > >The problem I'm running into is that the URLs used within BaseX are not >absolute (that is, they don't start with "/". > >For example, document-uri(root($node)) returns: > >dfst^dfst-sample-project^develop/docs/tests/complex_map/complex_map.ditama >p > > >not > >/dfst^dfst-sample-project^develop/docs/tests/complex_map/complex_map.ditam >a >p > >This causes a problem for resolve-uri(), used like this: > >resolve-uri($topicResourcePart, base-uri($topicref)) > > >This fails under BaseX: > >[FORG0002] Base URI is not absolute: "dfst^dfst-sample-project^develo.... > > >These libraries are intended to be generic XQuery so I'm trying to avoid >having any BaseX-specific logic in these functions. > >Is there workaround or other solution to this? > >Obviously, this way of representing document URIs internally is not >something that could be easily changed but it is definitely a problem in >terms of the expectations of URI handling by built-in XQuery functions. > >Thanks, > >Eliot >————— >Eliot Kimber, Owner >Contrext, LLC >http://contrext.com > > > >
EK
Yes, resolve-uri('foo', '/bar') also fails.
If I do base-uri('/foo') I get "file:/foo", which is a bit unexpected since I'm in the context of the BaseX system and not in the context of the file system (at least that's why my head thinks: BaseX itself may have different ideas).
I think what I expect is either that BaseX interprets all URIs not prefixed with "file:/" as relative to the BaseX repository, so rather than "dbname/path/to/doc" the URL format would be"/dbname/path/to/doc" or there is a BaseX-specific scheme that is used with all absolute URIs, e.g. "basex:/dbname/path/to/doc". That would remove any potential ambiguity about the intent of a given URL.
Thus, document-uri(root($node)) would return either "/foo/bar" or "basex:/foo/bar", but not "foo/bar".
Cheers,
E.
—————
Eliot Kimber, Owner
Contrext, LLC
http://contrext.com
Quoted text · Christian Grün · 41 lines
On 4/17/15, 12:07 PM, "Christian Grün" <christian.gruen at gmail.com> wrote: >Hi Eliot, > >> This fails under BaseX: >> >> [FORG0002] Base URI is not absolute: >>"dfst^dfst-sample-project^develo.... > >I think it also fails if the base URI starts with a slash. Try this for >example: > > resolve-uri('abc.xml', '/path/def.xml') > >What result you would expect from this query, given that it did not >raise an error? > >Using string operations could be an alternative... > > "replace($baseURI, '/[^*]+$', $topicResourcePart) > >...but I am not sure if this fulfills all needs. > >Christian > > > >> Obviously, this way of representing document URIs internally is not >> something that could be easily changed but it is definitely a problem in >> terms of the expectations of URI handling by built-in XQuery functions. >> >> Thanks, >> >> Eliot >> ————— >> Eliot Kimber, Owner >> Contrext, LLC >> http://contrext.com >> >> >> >
EK
BTW, my workaround for now is to check to see if base-uri() returned an absolute URL and if it did not, I use my existing code for constructing URLs to simply combine the relative URL with the parent of the result of base-uri(), otherwise I use resolve-uri(). That's a sufficiently-general solution that is not explicitly BaseX specific.
Cheers,
E.
—————
Eliot Kimber, Owner
Contrext, LLC
http://contrext.com
Quoted text · Christian Grün · 41 lines
On 4/17/15, 12:07 PM, "Christian Grün" <christian.gruen at gmail.com> wrote: >Hi Eliot, > >> This fails under BaseX: >> >> [FORG0002] Base URI is not absolute: >>"dfst^dfst-sample-project^develo.... > >I think it also fails if the base URI starts with a slash. Try this for >example: > > resolve-uri('abc.xml', '/path/def.xml') > >What result you would expect from this query, given that it did not >raise an error? > >Using string operations could be an alternative... > > "replace($baseURI, '/[^*]+$', $topicResourcePart) > >...but I am not sure if this fulfills all needs. > >Christian > > > >> Obviously, this way of representing document URIs internally is not >> something that could be easily changed but it is definitely a problem in >> terms of the expectations of URI handling by built-in XQuery functions. >> >> Thanks, >> >> Eliot >> ————— >> Eliot Kimber, Owner >> Contrext, LLC >> http://contrext.com >> >> >> >
Written for BaseX 8.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery