473,795 Members | 3,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_script s" and are trying
to load an XML file from "c:\xml_files\t est.xml" it ist trying to open a
file with the following absolute path:
"c:\xslt_script s\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 6096


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_script s" and are trying
to load an XML file from "c:\xml_files\t est.xml" it ist trying to open a
file with the following absolute path:
"c:\xslt_script s\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\t est.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_script s" and are
trying to load an XML file from "c:\xml_files\t est.xml" it ist trying
to open a file with the following absolute path:
"c:\xslt_script s\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\t est.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\t est.xml":
- document('file://c:/xml_files/test.xml')?
- document('file://c:\xml_files\te st.xml')?
- document('file:///c:/xml_files/test.xml')?
- document('file:///c:\xml_files\te st.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**********@w sc10.lrz-muenchen.de>,
Vitali Gontsharuk <go******@in.tu m.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\t est.xml":
This one:
- document('file:///c:/xml_files/test.xml')?


-- Richard
Aug 19 '05 #4
Richard Tobin wrote:
In article <de**********@w sc10.lrz-muenchen.de>,
Vitali Gontsharuk <go******@in.tu m.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\t est.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
2590
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 (PHP5): // $xml has the entire XML document in it; I included it for reference at the end of the document $dom = new DOMDocument(); $dom->loadXML($xml);
0
1823
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 are stored in a free-format XML document (in memory for the life of the session) and persisted to a database (as free text) on exit. I have taught my developers the basics of XPath, however I don't want to have to review XMLDOM code all over the...
3
5068
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 in HTML DOM element names are all upper-case, whereas in Core DOM (used for the XHTML documents) element names are lower-case. When I use a lower-case xpath, e.g. /head
4
21210
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 native English speaker, it's quite hard to make the problem clear. Please see the following example.
1
3039
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" elementFormDefault="unqualified" xmlns="http://test.org/Referral" xmlns:mstns="http://test.org/Referral" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:complexType name="ReferralType"> <xs:sequence>
8
6236
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
7739
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); System.out.println(xp.evaluate(new InputSource(new FileInputStream("a.xml"))));
3
3318
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 xmlns=\"http://schemas.microsoft.com/sharepoint/soap/directory/\"> <Roles> <Role ID=\"1073741826\" Name=\"Reader\" Description=\"....\" Type=\"2\" />
14
17203
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
3094
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 Potter</book> </books> </top>
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.