xinclude and pathnames

Rob Williscroft rtw at freenet.co.uk
Thu Sep 14 10:32:17 EDT 2006


Tim Arnold wrote in news:eebkgl$u90$1 at foggy.unx.sas.com in
comp.lang.python: 

> "Tim Arnold" <tiarno at sas.com> wrote in message 
> news:ee9231$mpj$1 at foggy.unx.sas.com...
>> I'm using ElementTree to access some xml configuration files, and
>> using the module's xinclude capability. I've got lines like this in
>> the parent xml file (which lives in the same directory as the
>> included xml file): <xi:include 
>> href="/dept/app/doc/current/en/xml/asdf/asdf_syntaxterms.xml"/>
>>
>> When I started the project it was Unix-only; this worked fine. Now I
>> have users who want to use the system on Windows and of course that
>> directory path doesn't exist on Windows, but it is available on the
>> network using a name like
>> \\ladida\current\en\xml\asdf\asdf_syntaxterms.xml 
>>
>> if relative paths worked, I could imagine
>> <xi:include href="asdf_syntaxterms.xml" /> would work.
>> Also,the file can be read via an http server.
>>
>> My question: is there a way to make xinclude work with relative paths
>> or perhaps urls?
>> Any ideas welcome--to me it looks like I'll have to restructure this
>> part of the system since I've basically programmed myself into a
>> corner. 
>>

According to the docs:  http://effbot.org/zone/element-xinclude.htm

The default handler just sees the href value as a filename, so you
should be able to use a relative path if you os.chdir() to the working
directory before processing you xml file.

I just ran a 3 line sample to make sure os.chdir() works with network 
paths, which it did.

Rob.



More information about the Python-list mailing list