472,791 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

XPATH document-function doesn't support absolute filepaths

Hallo!

When using the XPATH document() function to load a new XML document, we
are coming across problems, because XALAN seems to have problems with
absolute paths. XALAN always assumes that the path is relative to the
current directory. So if we e.g. are in "c:\xslt_scripts" and are trying
to load an XML file from "c:\xml_files\test.xml" it ist trying to open a
file with the following absolute path:
"c:\xslt_scripts\c:\xml_files\test.xml".
The weird thing however is that in some cases it works. Actually we
configure which XML file is to be used in a Java-Bean config-file. When
we just paste the full path to the current location of the XML file into
the config file, it works, but when we construct the path using a
place-holder (@xmlDir) which is further replaced with the actual
Dir-path, it doesn't work, although the path to the XML file - displayed
in the log of our application - is still the same.

Has someone experienced this strange behaviour too?
Any help appreciated!
Vitali Gontsharuk
Aug 17 '05 #1
4 5981


Vitali Gontsharuk wrote:

When using the XPATH document() function to load a new XML document,
XPath 1.0 has no function named document, only XSLT 1.0 knows that function.
we
are coming across problems, because XALAN seems to have problems with
absolute paths. XALAN always assumes that the path is relative to the
current directory. So if we e.g. are in "c:\xslt_scripts" and are trying
to load an XML file from "c:\xml_files\test.xml" it ist trying to open a
file with the following absolute path:
"c:\xslt_scripts\c:\xml_files\test.xml".


I don't know what Xalan does but usually the argument is treated as a
URI reference and "c:\xml_files\test.xml" is not a URI so you would at
least need
file:///C:/xml_files/test.xml
if you want to load from the file system.

As for resolving relative URIs, the base URI used depends on the second
argument to the document function, here is what the spec says about
that: "The URI reference may be relative. The base URI (see [3.2 Base
URI]) of the node in the second argument node-set that is first in
document order is used as the base URI for resolving the relative URI
into an absolute URI. If the second argument is omitted, then it
defaults to the node in the stylesheet that contains the expression that
includes the call to the document function."
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 17 '05 #2
Martin Honnen wrote:


Vitali Gontsharuk wrote:

When using the XPATH document() function to load a new XML document,

XPath 1.0 has no function named document, only XSLT 1.0 knows that
function.
we

are coming across problems, because XALAN seems to have problems with
absolute paths. XALAN always assumes that the path is relative to the
current directory. So if we e.g. are in "c:\xslt_scripts" and are
trying to load an XML file from "c:\xml_files\test.xml" it ist trying
to open a file with the following absolute path:
"c:\xslt_scripts\c:\xml_files\test.xml".

I don't know what Xalan does but usually the argument is treated as a
URI reference and "c:\xml_files\test.xml" is not a URI so you would at
least need
file:///C:/xml_files/test.xml
if you want to load from the file system.

As for resolving relative URIs, the base URI used depends on the
second argument to the document function, here is what the spec says
about that: "The URI reference may be relative. The base URI (see [3.2
Base URI]) of the node in the second argument node-set that is first
in document order is used as the base URI for resolving the relative
URI into an absolute URI. If the second argument is omitted, then it
defaults to the node in the stylesheet that contains the expression
that includes the call to the document function."

OK, now I've tried it in any combinations and it still doesn't work!!!
Actually I still have some problems understanding, how the function
should be called if i need to load a document whose absolute path name
is e.g. "C:\xml_files\test.xml":
- document('file://c:/xml_files/test.xml')?
- document('file://c:\xml_files\test.xml')?
- document('file:///c:/xml_files/test.xml')?
- document('file:///c:\xml_files\test.xml')?

or with two parameters (according to the spec, this shouldn't be the
case, but I still tried this...):
- document('test.xml','file://c:\xml_files')?
- document('test.xml','file://c:\xml_files\')?
- document('test.xml','file://c:/xml_files')?
- document('test.xml','file://c:/xml_files/')?
- document('file://test.xml','file://c:/xml_files/')?
etc...
Could anyone make that function work with absolute paths???

Thanks,
Vitali

Aug 19 '05 #3
In article <de**********@wsc10.lrz-muenchen.de>,
Vitali Gontsharuk <go******@in.tum.de> wrote:
Actually I still have some problems understanding, how the function
should be called if i need to load a document whose absolute path name
is e.g. "C:\xml_files\test.xml":
This one:
- document('file:///c:/xml_files/test.xml')?


-- Richard
Aug 19 '05 #4
Richard Tobin wrote:
In article <de**********@wsc10.lrz-muenchen.de>,
Vitali Gontsharuk <go******@in.tum.de> wrote:
Actually I still have some problems understanding, how the function
should be called if i need to load a document whose absolute path name
is e.g. "C:\xml_files\test.xml":


This one:
- document('file:///c:/xml_files/test.xml')?


-- Richard

Now I figured out what the problem was: within Java Xalan had been
explicitly preconfigured with a specific directory as basepath - that's
why even absolute file paths were considered as relative.
But thanks for your answers!
Aug 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joshua Beall | last post by:
Hi All, I have a task that should be very simple but I'm running into trouble. All I want to do is query a document using XPath, and save the resulting XML in a string. Here's that I am trying...
0
by: bdinmstig | last post by:
I am building various framework components for my team to use in development, and one of those components is a Facade for reading/writing user preferences. The idea is that preference settings...
3
by: Johannes Koch | last post by:
Hi there, I'd like to apply an xpath to both HTML and XHTML documents. First I create a DOM document with a Java DOM parser, then apply the xpath with Xalan's XPathAPI class. The problem is that...
4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a...
1
by: Hollywood | last post by:
I have the following XSD created in VS.NET 2003: <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="ReferralSchama" targetNamespace="http://test.org/Referral"...
8
by: Joe Pannone | last post by:
Does anyone have an example on using an XPath statement (in VB.NET) where the source XML document is NOT a file, but a 'text' value from SQL Server?
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
3
by: SD | last post by:
Hi, How can i get all the nodes with attribute Name = "Publisher" or Name="Administrator" using XPath query and C# for this xml doc? <GetRoleCollectionFromUser...
14
by: Mikhail Teterin | last post by:
Hello! What's would be the syntax for a query, which would allow me to get only the elements with non-empty text-nodes? For example, from: <a><b></b></a> <c/> <d><e>meow</e></d>
3
by: Arndt Jonasson | last post by:
Let's say we have a schema (maybe expressed in XML Schema, but not necessarily so), that allows this instance document: <top> <txt>This is text</txt> <books> <book>Tarzan</book> <book>Harry...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.