[relaxng-user] attribute wildcards in open and extensible schemata

Robin Berjon robin.berjon at expway.fr
Mon Jul 26 11:47:03 ICT 2004


Hi,

MURATA Makoto (FAMILY Given) wrote:
>>As you might expect, I keep hitting that problem where having an 
>>attribute wildcard creates a conflict with a declared attribute, and 
>>quite frankly it's driving me up the walls.
> 
> Could you show me a small example of this problem?  Some of us might 
> be able to think of a better workaround.

Sorry for the delayed answer, and thanks for the offer to help. Here is 
a sample RNG (it's not optimally small, but I hope small enough to make 
the problem clear):


<grammar ns='http://www.w3.org/2000/svg'
          xml:lang='en'
          xmlns='http://relaxng.org/ns/structure/1.0'
          xmlns:a='http://relaxng.org/ns/compatibility/annotations/1.0'
          datatypeLibrary='http://www.w3.org/2001/XMLSchema-datatypes'
          >

   <start>
     <ref name='svg'/>
   </start>

   <define name='svg'>
     <element name='svg'>
       <ref name='handler'/>
     </element>
   </define>

   <define name='handler'>
     <element name='handler'>
       <attribute name='id'>
         <data type='ID'/>
       </attribute>
       <ref name='wildcard-noAttr.content'/>
     </element>
   </define>

   <define name='wildcard.content'>
     <zeroOrMore>
       <choice>
         <element>
           <anyName/>
           <ref name='wildcard.content'/>
         </element>
         <attribute>
           <anyName/>
         </attribute>
         <text/>
       </choice>
     </zeroOrMore>
   </define>

   <define name='wildcard-noAttr.content'>
     <zeroOrMore>
       <choice>
         <element>
           <anyName/>
           <ref name='wildcard.content'/>
         </element>
         <text/>
       </choice>
     </zeroOrMore>
   </define>
</grammar>

Here is a sample instance (but it is rather irrelevant):

<svg xmlns='http://www.w3.org/2000/svg'>
   <handler id='foo'>
     <foo xmlns=''/>
   </handler>
</svg>

As you can see, there are two fairly straightforward wildcard 
definitions (if I haven't gotten anything overly wrong). The handler 
element is meant to contain arbitrary XML, including possibly some SVG 
(though that SVG would not be processed by the SVG user agent -- the 
content of the handler element is passed as a parameter to code that 
handles the event). It therefore refers to wildcard-noAttr.content, 
which is a wildcard of everything except attributes. That, in turn, 
specifies that whatever elements are contained inside itself can have 
any attributes, children, etc.

This blows up because Jing complains (quite conformantly) that that 
wildcard content model could match svg:handler, and since it could it 
could not have any attributes on it as that would duplicate with the 
declared id attribute (and clash on its type, which is the error I get).

I can see where this makes sense and I could special-case for SVG by 
excluding the attribute wildcard in there for elements in the SVG 
namespace. But that gets tedious fast because a schema for SVG 1.2 also 
has to cover XLink, XML Events, sXBL, and probably a dozen or so other 
schemata that I'm forgetting about right now.


>>Or should I just give up and hop straight to NRL?
> 
> Although RELAX NG is intended to help schema modularization, I think that 
> sophisticated use of namespaces require something like NRL.

That's enough of an answer for me, I wish it were more strongly 
advertised (would have avoided me quite some trouble in this case). I 
assume that the problem above has good reasons to exist, and I'm 
probably only complaining like a spoiled child because this is the one 
and only situation for which I have found XML Schema to be more intuitive :)

Thanks a lot,

-- 
Robin Berjon


More information about the relaxng-user mailing list