N. America: 800 876 3101 | World: 44 (0) 1753 218 930

Why does my relative path fail even if I set the base-uri property?

My XQuery looks like this:

declare base-uri "file:///C:/mydocuments/xml";
doc("items.xml")//ITEM[@id='145']

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/";
doc("items.xml")//ITEM[@id='145']

 


Next Question!

Is there a way to number records extracted from a database?

Submit Your DataDirect XQuery Tip or Trick

Tell us your XQuery Tip or Trick – if it gets published on our site, you’ll receive a

$10.00 Amazon.com
Gift Certificate!

Submit your tip or trick today.