473,324 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 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 6026


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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.