Limit the list of words in an XML schema

I am writing an XML schema and I must prevent the element text from matching certain values. (For example, the variableName element cannot match 'int', 'byte', 'string', etc.)

I tried using a constraint with a template element similar to "^ (int | byte | string)", but without success.

Do you know a way to format a regular expression or any other way to do this?

+4
source share
3 answers

After testing XML Schema (XSD) regular expressions three times, there really aren't any features that would facilitate this task (in particular, views and bindings), I came up with an approach that seems to work. I used the free space mode to make it easier to read, but this other feature does not support the XSD flavor.

[^ibs].* | i(.{0,1} | [^n].* | n[^t].* | nt.+) | b(.{0,2} | [^y].* | y[^t].* | yt[^e].* | yte.+) | s(.{0,4} | [^t].* | t[^r].* | tr[^i].* | tri[^n].* | trin[^g].* | tring.+) 

The first alternative matches any that does not begin with the initial letter of any of the keywords. Each of the other top-level alternatives corresponds to a line that begins with the same letter as one of the keywords, but:

  • shorter than the keyword
  • has another second letter, another third letter, etc., or
  • longer than the keyword.

Note that XSD regular expressions do not support explicit bindings (i.e. ^ , $ , \A , \z ), but all matches are implicitly fixed at both ends.

One potential problem that I see: if the list of keywords is long, you may encounter a restriction on the entire length of the regular expression.

+6
source

Does this need a W3C Schema (otherwise called an "XML Schema")? Or will a standard alternative be used, for example RelaxNG ? Maybe I'm wrong, but I thought that he had several attempts to unite restrictions, including the ability to crossroads.

+1
source

Without a negative look, it is quite tiring. Attached is a regular expression that works with some unit tests. It is written in Perl, not XSD, but it is a fairly basic regular expression, so it should work ... You must remove the space from the regular expression before using it. I added a space to make it a little easier to read.

Note. I do not know if "\ A" and "\ z" are allowed in XSD. If not, replace them with "^" and "$" respectively.

 use Test::More 'no_plan'; my $re = qr/\A(\z|[^ibs] |i(\z|[^n]|n(\z|[^t]|t.)) |b(\z|[^y]|y(\z|[^t]|t(\z|[^e]|e.))) |s(\z|[^t]|t(\z|[^r]|r(\z|[^i]|i(\z|[^n]|n(\z|[^g]|g.))))))/x; for my $str ( qw(inter bytes ins str strings in sdgsdfger ibs by byt bite st \ str stri strin strink) ) { like($str, $re, $str); } for my $str ( qw(int byte string) ) { unlike($str, $re, $str); } 
0
source

All Articles