Relax Ng list patterncomma separated

137 views Asked by At

I am using Relax Ng to validate XML file

In my XML file I have a tag with several values separated by comma

<mytage>01,02,03,04<mytage>

I can use <List> pattern in the .rng file but it matches a whitespace-separated sequence not comma-separated

1

There are 1 answers

2
sideshowbarker On BEST ANSWER

It could be specified using <param name="pattern"> with a regular expression; for example:

<data type="string" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <param name="pattern">[0-9][0-9](,[0-9][0-9])*</param>
</data>

Or in the compact syntax:

xsd:string {
    pattern = "[0-9][0-9](,[0-9][0-9])*"
}

If you want to make it part of a <choice>:

<choice>
    <data type="string" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
      <param name="pattern">[0-9][0-9](,[0-9][0-9])*</param>
    </data>
    <data type="string" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
      <param name="pattern">…</param>
    </data>
</choice>

Or in the compact syntax:

(    xsd:string {
        pattern = "[0-9][0-9](,[0-9][0-9])*"
    }
|   xsd:string {
        pattern = "…"
    }
)