Re: [xslt] Few questions



On Mon, Sep 08, 2003 at 11:41:54AM +0200, Carlo Contavalli wrote:
> Hi! 
>   I'm almost done writing a module using libxml/libxslt (mainly 
> 2.5.7 and 1.0.30), and I have a few question marks still to answer:  
> 
>   - (libxslt) the module provides some extension tags (registered 
>     with xsltRegisterExtElement). The function handling one of the 
>     extension tags needs to retrieve all the text that would
>     be expanded by the xslt processor in the corresponding ``subtree''. 
>     To do this, I've used:
> 
>     	xsltEvalTemplateString(...)
> 
>     is this correct?

   Maybe maybe not, I don't undertsnad fully what you're looking for
and I don't remember that function in particular.
> If my tag contains a <fallback handler, however,
>     althought working correctly, I keep getting the non-fatal error:
> 
>       xsltApplyOneTemplate: fallback was not compiled
> 
>     is there another function I should use? What can I do to avoid
>     the error (something smarter than removing the fallback node 
>     from the tree)?

   No idea. Use the source, put a breakpoint in your routine and see what's
happen !

>   - (libxml) Some xml documents that get parsed use external entityes 
>     fetched from http urls. I get an uncoherent behavior due to the fact 
>     that if the dtd does not exist on the local file system, I get a sort
>     of warning telling me the dtd does not exist, but parsing goes on. 

   Right the presence of a DTd is not critical for processing.

>     However, when it is fetched from a remote url, the http status of 
>     the request is not checked and if the document does not exist 
>     libxml tryes to parse the error page as if it was the DTD, leading 
>     to a fatal error (it is quite uncommon to have a 404 page
>     containing a valid DTD).

   Well you served some markup. Libxml2 can parse HTML is asked for,
and could parse that URL 
       xmllint --html your_404_url

>     So, if the dtd does not exist on the local file system -> ignorable
>     warning, if it does not exist on a remote url -> parsing stops with
>     an error not always easy to understand (Extra content at the end
>     of the document... but where did it get the document?). Is this
>     an expected behavior? Is there something I can do to avoid the 
>     problem?

   Define you own entity handler, see the documentation of libxml2 in
the "I/O Interfaces" page.

>   - (libxslt) The application changes the error handlers, calling 
>     xsltSetGenericErrorFunc with its own handler and its own
>     context. However, I sometimes get segfault due to transform.c
>     calling xsltGenericError(xsltGenericDebugContext, where
>     xsltGenericDebugContext is a different (unknown) data 
>     type than the one expected by my handler as GenericErrorContext. 
>     Is this behavior expected? How can I make sure 
>     xsltGenericError gets called only with its own context
>     (without enabling debugging - still there in 1.0.32)?

  No idea how you got there. Sorry you will have to debug !

>   - (libxml) The application I'm talking about is _not_ multithreaded
>     (at least by default). However, it is made
>     of a list of modules being called in a big loop, where 
>     more than a module may make use of the libxml library in 
>     the same thread of execution. libxml makes use of many global 
>     variables, some of which may be changed to customize its 
>     behavior. Actually, to avoid one module influencing the
>     parsing of another module, I compile libxml with multithreading
>     support and save the ``state'' of the library by copying
>     the memory area returned by xmlGetGlobalState with memcpy
>     and by restoring it after the module has executed, leading
>     to something like:
>       At module initialization
>         - create new global state (malloc and InitializeGlobalState)
>  	- save global state (GetGlobalState and memcpy)	
> 	- overwrite the global state with the one created above
> 	- (change libxml defaults)
> 	- save my own global state
> 	- restore previous global state

  That sounds very messy. If you compile with thread you already have
per thread global data so I don't understand what you're doing with this
memcpy. 

>       At module execution (in the big loop)
>         - save global state
> 	- overwrite the global state with my own
> 	- (work with libxml)
> 	- restore global state
> 
>     Is there a better way to do this? Is there any other

  I don't see why you think you needed it. Get a debugger and see
what's the default behaviour actually is.

>     solution than copying every single global variable
>     when multithreading is disabled? I've looked at the

  Oh it's without multithreading compiled in, well your code
is yours, you can try this kind of things but you're on your own.

>     source code, and I believe it would be nice to let 
>     the applications access the statics NewGlobalState
>     and FreeGlobalState, and to have a SetGlobalState
>     that acts directly on the tsd variables being used
>     (if you believe it worth, I could easily provide the
>     needed code).

   Well I don't understand why you want to do that. if you have
specific setup and you want to switch save the variable and restore
them I really don't see why it's not appropriate !

>   - (libxslt) What's the status for libxslt? I haven't seen 
>     any threading support and the only globals I've seen 
>     are those for error handling.
>     Am I on the safe side (with regard to the problem
>     highlited above) if I save and restore just them
>     before and after running the module? 

   Pleople are using libxslt in multithreaded apps without troubles
nearly since the beginning. For the errors yes they are shared, 
so far nobody provided code for something like libxml2 multithread
support so it must be that nobody felt an urgent need for it.

> Sorry for the long mail and sorry for the OT about libxml, but 
> I really didn't know how to best split the mail.  Feel free to
> answer me on any of the two lists.

  I'm not sure I understand every aspects of your problems nor
why you selected some solutions which looks rather complex.

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard@redhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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