Re: [xml] setting URL for xmlRelaxNGParserCtxt?



Daniel Veillard wrote:
On Tue, Jan 25, 2005 at 08:14:22PM +0100, Martijn Faassen wrote:

Hi there,

In my lxml Python binding for libxml2, I was using the following approach to construct a Relax NG schemas:

xmlDocPtr* doc = ...
parser_ctxt = xmlRelaxNGNewDocParserCtxt(doc)

unfortunately, this got me into trouble with Relax NG schemas that use the 'include' statement. They try to load the files to be included, but have no idea where to look, as this information is lost.

Glancing through the source, it seems like the only way to make the 'include' statement work is to use xmlRelaxNGNewParserCtxt, which takes a URL.

   Wrong. How did you built "doc" ?  If it's from a memory string you can
still define the base for that document by providing the URL argument
of xmlReadMemory().

Would it be useful to have a way to supply this URL to an existing xmlRelaxNGParserCtxtPtr? Something like:


  no the base has to be set in the document. Since that part is just
described by '...' in your mail there is little more indications I can
provide.

Interesting. This is how a doc typically get parsed now:

pctxt = xmlNewParserCtxt()
.. (share dictionaries)
result = xmlCtxtReadFile(pctxt, filename,
                                   NULL, _getParseOptions())

the other approach is to create a doc with xmlNewDoc().

Thinking it through, it's quite possible that I often have a node being passed from a doc that's parsed into a doc that's created with xmlNewDoc(). I will investigate whether that happens here, and whether I can pass along the URL somehow when it happens.

[snip]
  The base is a property of the document, not of the relax-NG transformation
compilation, this is really the wrong approach.

I imagine the same issues come up when using XSLT that tries to include or import external stylesheets.
yes the base is *in* the document.
  xmlNodeSetBase(xmlNodePtr cur, const xmlChar* uri)
to be called on your document. But it should really be there as the result
of parsing.

Good, good. I have an idea of what to do to fix the issue. Thanks for the hints and my apologies for the misunderstanding.

Regards,

Martijn



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