Re: [xml-bindings]Difficulties with Python bindings



On Sun, 5 May 2002, Daniel Veillard wrote:

> On Sat, May 04, 2002 at 11:42:14PM +0100, Gary Benson wrote:
> 
> > Firstly, I'm trying to write something which works a little like a
> > webserver; all content starts as XML files which have xml-stylesheet
> > PIs to locate the stylesheets (with relative paths).
> > 
> > Some of the documents are served as static files, loaded via
> > libxml2.parseFile. When I load the stylesheet, with
> > libxslt.loadStylesheetPI, the relative path gets resolved relative to
> > wherever the original document was loaded from, which is what I
> > wanted.
> > 
> > Some of the documents, however, are generated (with libxml2.newDoc,
> > etc)  and these have no filename, so the stylesheet's location gets
> > resolved relative to the current directory, which breaks stuff. Is
> > there any way I can 'set the filename' of a generated document? I can
> > get around it by changing directory, but that strikes me as a bit of a
> > hack.
> 
>   Hum, if it wasn't for a stylesheet PI found before the root element
> then doing a setBase() on the document root element would do it.
>   In that case the only way is to find a accessors for the URL field of
> the xmlDoc structure.
> 
>   I see only 2 ways to do this:
>    1/ change the behaviour of libxml2 xmlNodeSetBase() to change the
>       URL field when the argument is a DOCUMENT

>    2/ add r/w accessors to the URL fileds aocciated to the underlying
>       structure. actually doc.name returns the value of that URL already
> 
> patch for 1/ enclosed

Daniel thanks, that works a treat.

> > Another problem is that I can't find an equivalent of
> > xmlDocDumpMemory(),
> 
>   In recent versions doc.serialize() will do this, check serialize.py
> in recent versions

Oh cool, I missed that one. I was searching for functions with similar 
names to the C ones.

> > so the only way to serialise a document is to save it to a file. I'm
> > currently hacking around it by redirecting stdout to a temporary file,
> > saving the document to it and then reading it back in, which is icky.
> 
> I recognize there is still a problem w.r.t. reusing the Python file
> layer when they are not FILE * based. I would need to fix the I/O layer
> to accept any kind of python file (probably by using callbacks to the
> python level triggered by the C routine to be sure it works in all
> cases).

Yeah, I guessed that it would be a major task.

Thanks again for your help,
Gary

[ gary inauspicious org ][ GnuPG 85A8F78B ][ http://inauspicious.org/ ]




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]