resolving relative paths for external entities with xml.sax
bart_vanhaute_ at hotmail.com
Sun Aug 17 14:43:21 CEST 2003
On Fri, 15 Aug 2003 06:24:02 -0700, Uche Ogbuji wrote:
>> From what I understand of XML specs, relative paths in external entities
>> are relative to the location of the document *in which they are defined*.
>> However, using xml.sax (which calls expat, I presume), the paths are
>> resolved relative to the current working directory. So the parser can not
>> find the test.inc when the current working directory is e.g. dir1.
> I, for one, need to see your Python code to tell, because if you're
> using the APIs rightly parsing the first file as a URI rather than,
> say, reading it in as a string first), then you should not have the
> problem you report.
from xml.sax import make_parser
from xml.sax.saxutils import XMLGenerator
reader = make_parser()
this is run in the test1 dir.
I also tried using absolute paths, xml.sax.InputSource, 'file:' URLs and
combinations of these.
The result is either:
OSError: [Errno 2] No such file or directory: 'test.inc'
or (when using 'file://tmp/xmltest/test1/test.xml'):
OSError: [Errno 2] No such file or directory: '/tmp/xmltest/test1/test.inc'
or (when using 'file:test.xml'):
OSError: [Errno 2] No such file or directory: '/test.inc'
In the meantime, I found a discussion in bugzilla for python.xml about the
prepare_input_source method in xml.sax.xmlutils (see
but i am not sure it is really relevant.
More information about the Python-list