Domanda

I have an attribute called 'page'. It is made up of two to three doubles, separated by commas, not spaces, with an optional '!' at the end. All of the following are valid:

page="8.5,11,3!"
page="8.5,11.4,3.1"
page="8.5,11!"
page="8.5,2.1"

I know I could use patterns, the following would work:

attribute page { xsd:string { pattern="[0-9]+(\.[0-9]+)?,[0-9]+(\.[0-9]+)(,[0-9]+(\.[0-9]+)?)?(!)?" } }

But if possible, I'd rather use something like this:

attribute page { xsd:double, ",", xsd:double, ( ",", xsd:double )?, ("!")? }

I can make the above sort-of work, using 'list':

attribute page { list { xsd:double, ",", xsd:double, ( ",", xsd:double )?, ("!")? } }

But then I end up with spaces between each of the pieces:

page="8.5 , 11 !"

Is there any way to do this without using pattern?

È stato utile?

Soluzione

Relax NG has no particular rules for how simple types are defined; it is designed to be able to use simple type libraries which make such rules. So in principle, yes, you can do what you like in Relax NG: just use a simple type library that provides the functionality you seek.

In practice, you seem to be using the XSD library of simple types. And while XSD does allow the definition of list types whose values are sequences of other simple values, for the sake of simplicity in the definition and in the validator, XSD list values are broken by the parser on white space; XSD does not allow arbitrary separators for the values. So, no you cannot do what you say you would like to do, with Relax NG's XSD-based library of simple types.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top