resolving relative paths for external entities with xml.sax

Bart bart_vanhaute_ at hotmail.com
Thu Aug 7 18:10:34 EDT 2003


Dear python XML'ers,

I have a set of XML documents that use external entity definitions for
which I am having problems parsing them using python and xml.sax. The 
problem is with the resolution of relative paths in these. 
An example:

dir1/test.xml:
	<?xml version="1.0"?>
	<!DOCTYPE test SYSTEM " ../dir2/test.dtd">
	<test>&ent;</test>

dir2/test.dtd:
	<!ENTITY ent SYSTEM "test.inc">
	<!ELEMENT test (#PCDATA)>

dir2/test.inc:
	external entity test

>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 do not see how creating an EntityResolver would help here: how do I 
know against what base path I have to resolve the entity? 

(the same thing can be read without problems with other xml parser, for
instance in Java).

Bart.





More information about the Python-list mailing list