Re: [xml] why is htmlNewParserCtxt static?

Hi Daniel,

  But shouldn't you use one of the wrapper functions where you specify
what input will be used ? Like htmlCreateMemoryParserCtxt() or one of the
htmlRead... function ? What is your use case ?

The use case is replacing xmlDefaultExternalEntityLoader() with a customised entity loader function.

The entity loader is passed an xmlParserCtxtPtr, which allows document-specific options to be passed in using the _private field and used by the entity loader (as long as you don't use xmlReader :) So when I parse a document I want to pass in some stuff in the _private field of the context.

Normally I would use xmlReadFile(), but that creates its own context and destroys it afterwards and doesn't give me a chance to put anything in _private. However, xmlCtxtReadFile() looks like just what I want, as it takes a context that I've already created with the appropriate stuff in _private.

On the HTMLparser side of things I can't do this, as htmlNewParserCtxt() is static and I can't call it. I want to call htmlCtxtReadFile(), but first I need to create a context, set the _private field and pass it in.

The htmlCreateFileParserCtxt() is the only way I can create a context, but I can't use it, because it calls xmlLoadExternalEntity() itself, before I have had a chance to set _private. Then when I pass the context into htmlCtxtReadFile() it will call xmlLoadExternalEntity() again!

So I need a way to create a HTML parsing context that will let me set _private before trying to load any external entities. Does this seem reasonable? I can do it with the XML parsing API, so I just assume that the HTML parsing API should work the same way.

Best regards,


Print XML with Prince!

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