>Home>Learn XQuery> XQuery Tips and Tricks>Relative Paths
Why does my relative path fail even if I set the
My XQuery looks like this:
declare base-uri "file:///C:/mydocuments/xml";
My items.xml file is indeed in my c:\mydocuments\xml folder, as shown in the base-uri, but when I run the XQuery, I get this error:
[DataDirect][XQuery][err:FODC0005]java.io.FileNotFoundException: C:\mydocuments\items.xml (The system cannot find the file specified)
Why is the XQuery processor looking for items.xml in the c:\mydocuments folder instead of c:\mydocuments\xml as specified in the base-uri property?
As strange as it sounds, the XQuery processor is adhering to what the specifications dictate. Take a look at RFC 2396 - Uniform Resource Identifier (URI): Generic Syntax. Section 5.2. Resolving Relative References to Absolute Form, subsection 6a contains the following:
All but the last segment of the base URI's path component is copied to the buffer. In other words, any characters after the last (right-most) slash character, if any, are excluded.
You can fix your XQuery quite easily, by adding a final slash to the declared base-uri:
declare base-uri "file:///C:/mydocuments/xml/";
Is there a way to number records extracted from a database?