[cxml-devel] RNG question

David Lichteblau david at lichteblau.com
Tue Mar 6 21:14:55 UTC 2012


Quoting Cyrus Harmon (ch-lisp at bobobeach.com):
> While we're at it? Any idea why the following gives an error saying "restriction on string sequences violated"?
...
> type-byday = element byday {
>     xsd:integer?,
>     type-weekday
> }

IIUC, the restrictions on string sequences are mainly designed to annoy
the user (or equivalently, to simplify implementation :-)) and enforce a
particularly narrow-minded idea of what XML is for.

In this case, the restriction is (sort of) understandable though, I
think.

Relax NG checks that the tree of XML nodes in a document conforms to a
certain grammar.  Compare this to an ordinary regex, which checks that
the sequence of characters in a string conform to a certain grammar.

These are two different levels of thinking. You can, in fact, work at
both levels and have Relax NG check that the string contained in an XML
text node conforms to a certain regex.

What you cannot do is to mix both features, i.e. you cannot describe the
regex for a text node's string using schema patterns.  And that is what
the fragment above, if Relax NG supported it, would do: It would take
the single child of the byday element (a text node), and check that this
text node's string starts with a substring matching something like
/-?[0-9]/ and continues with something like /SU|MO|TU|WE|TH|FR|SA/.

As a workaround, I believe you need to check for both parts together
using an ad-hoc regex:

  type-byday = element byday {
      xsd:string { pattern='-?[0-9]+(SU|MO|TU|WE|TH|FR|SA)' }
  }

(It's been years since I looked at Relax NG, so I could be completely
wrong about all of this.  I have no idea why that relatively recent RFC
would include a grammar that doesn't work.  Maybe there are newer
versions of Relax NG that I am not aware of.  The homepage mentions
something about a version 2 that I can't find any information on.)

d.




More information about the cxml-devel mailing list