[xml] libxml2 Relax NG include bug?



Hi there,

As mentioned in an earlier thread, I ran into some weird behavior concerning Relax NG include processing. It may be that I'm misunderstanding something, but I thought I'd run it by the list.

Take the following program:

#include <stdio.h>
#include "libxml/parser.h"
#include "libxml/relaxng.h"

int main() {
  xmlDocPtr doc;
  xmlParserCtxtPtr pctxt;
  xmlRelaxNGParserCtxtPtr rng_pctxt;
  xmlRelaxNGPtr schema;

  xmlInitParser();
  pctxt = xmlNewParserCtxt();
  doc = xmlCtxtReadFile(pctxt, "test1.rng", NULL, 0);
  rng_pctxt = xmlRelaxNGNewDocParserCtxt(doc);
  schema = xmlRelaxNGParse(rng_pctxt);
}

Place it in a directory which contains the following rng files:

test1.rng

<grammar ns="http://www.w3.org/1999/xhtml";
         xmlns="http://relaxng.org/ns/structure/1.0";>

<include href="test2.rng"/>

</grammar>

test2.rng

<grammar xmlns="http://relaxng.org/ns/structure/1.0";>

<start>
  <ref name="a" />
</start>

<define name="a">
  <element name="a">
  <text/>
  </element>
</define>

</grammar>

Now if you compile and run the program, it should work -- the test1.rng should load successfully, loading test2.rng in turn.

Now create a subdirectory called 'sub', and place test1.rng and test2.rng in there.

Now change the program so it loads sub/test1.rng instead of test1.rng.

when I run this I get the following error:

I/O warning : failed to load external entity "test2.rng"
element include: Relax-NG parser error : xmlRelaxNG: could not load test2.rng
element include: Relax-NG parser error : Failed to load include test2.rng
Relax-NG parser error : grammar has no children
Relax-NG parser error : Element <grammar> has no <start>

This is against libxml2-2.6.16 on a linux box.

So, am I doing something wrong, or is this a bug? Things do appear to work as expected if I use xmlRelaxNGNewParserCtxt() and give it the "sub/test1.rng" path instead.

Regards,

Martijn



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