resolving relative paths for external entities with xml.sax
Uche Ogbuji
uche at ogbuji.net
Fri Aug 22 12:07:00 EDT 2003
Bart <bart_vanhaute_ at hotmail.com> wrote in message news:<pan.2003.08.17.12.42.56.153674 at hotmail.com>...
> 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.
>
> something like:
> from xml.sax import make_parser
> from xml.sax.saxutils import XMLGenerator
> reader = make_parser()
> reader.setContentHandler(XMLGenerator())
> reader.parse('test.xml')
>
> 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'
Ignore my last posting. Silly me: I threw out all the context.
This is a bug. I'll try to make time to look into it (I don't get to
pitch into PyXML enough these days).
> In the meantime, I found a discussion in bugzilla for python.xml about the
> prepare_input_source method in xml.sax.xmlutils (see
> http://sourceforge.net/tracker/index.php?func=detail&aid=616431&group_id=6473&atid=106473)
> but i am not sure it is really relevant.
It's certainly relevant, and I plan to make that a starting point.
Thanks.
--Uche
http://uche.ogbuji.net
More information about the Python-list
mailing list