Hi all,

My understanding of the behaviour of nested Relax NG grammars is that
putting them into an external file and referencing via <externalRef>
should be identical to having the nested grammar in the main file.  But
I'm not seeing that from libxml2 2.7.8 (specifically 2.7.8.dfsg-2ub in
ubuntu)

Consider the following simple grammar.

<?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"; 
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes";>
    <start>
        <element name="foo">
           <ref name="bar"/>
        </element>
    </start>

    <define name="bar">
        <grammar xmlns="http://relaxng.org/ns/structure/1.0"; 
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes";>
            <start>
                <element name="bar">
                    <parentRef name="na"/>
                </element>
            </start>
        </grammar>
    </define>
    
    <define name="na">
        <attribute name="name">
            <data type="string"/>
        </attribute>
    </define>

And the same grammar broken into two files: core.rng,

<?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"; 
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes";>
    <start>
        <element name="foo">
           <ref name="bar"/>
        </element>
    </start>

    <define name="bar">
      <externalRef href="extern.rng"/>
    </define>
    
    <define name="na">
        <attribute name="name">
            <data type="string"/>
        </attribute>
    </define>
</grammar>

and the external grammar.

<?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"; 
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes";>
    <start>
      <element name="bar">
        <parentRef name="na"/>
      </element>
    </start>
</grammar>

I wrote this small python script (using python-lxml which wraps libxml2)

#!/usr/bin/env python

from lxml import etree
import sys

schema_file = sys.argv[1]
print "load %s" % schema_file

sch = etree.RelaxNG(file=schema_file)

When I run test.py and pass in the first form, it loads without error.
When I run test.py and pass in the second form I get the following
output:

peterh@citypig:~$ ./test.py core.rng 
load core.rng
Traceback (most recent call last):
  File "./test.py", line 9, in <module>
    sch = etree.RelaxNG(file=schema_file)
  File "relaxng.pxi", line 86, in lxml.etree.RelaxNG.__init__ 
(src/lxml/lxml.etree.c:127492)
lxml.etree.RelaxNGParseError: Use of parentRef without a parent grammar, line 5


(the error is generated in relaxng.c)

So, is this a bug in libxml2, or have I misunderstood the way things work?

Thanks

-- 
Peter Howard <pet...@ok-labs.com>
OK Labs

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to