Re: [xslt] Embedded Stylesheets



On Fri, Aug 13, 2004 at 04:22:45PM -0700, David Hyatt wrote:
>     // Create an XMLParserContext and then build up an xmlDocPtr
>     xmlParserCtxtPtr parser = xmlCreatePushParserCtxt(NULL, NULL, NULL, 
> 0, doc->URL().ascii());
>     const QChar BOM(0xFEFF);
>     const unsigned char BOMHighByte = *reinterpret_cast<const unsigned 
> char *>(&BOM);
>     xmlSwitchEncoding(parser, BOMHighByte == 0xFF ? 
> XML_CHAR_ENCODING_UTF16LE : XML_CHAR_ENCODING_UTF16BE);
>     xmlParseChunk(parser,
>                   reinterpret_cast<const char 
> *>(doc->transformSource().unicode()),
>                   doc->transformSource().length() * sizeof(QChar), 1);

   That's really ugly ! Use xmlReadMemory().
I really can't make sense of that code and it breaks, no big surprize
honnestly.
You also must ask for entity substitution so that libxml2 generate a 
tree compatible with the XPath data model.
I can't make sense of that code and the error is there. Why use a 
Push parse when you have all data already in memory ? Why try to fool
the parser about encoding when libxml2 does implement the encoding
detection specified in appendix F of the XML specification ? Also 
xmlCreatePushParserCtxt has encoding detection, you're redoing in
a likely untested way what libxml2 does reliably for ages. By doing
a forced cast to UTF16 you're breaking the encoding detection, 
you're breaking performances, and you're likely to also break conformance
of the parser. Do not force a cast to UTF-16, it's really really bad !
Beware too of the decoupling from the HTTP engine and the XML parser,
you must read http://www.w3.org/TR/REC-xml/#sec-guessing and RFC 3023
you will have to pass the encoding as declared in the Content-Type
HTTP header.

>     xmlDocPtr sourceDoc = parser->myDoc;
>     if (!sourceDoc || !parser->wellFormed)
>         return 0;   <------ THE FAILURE HAPPENS HERE

  No it happens before because your attempt to coerce encoding detection
and handling just broke the parser IMHO.

Daniel

-- 
Daniel Veillard      | Red Hat Desktop team http://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]