Craig
Craig

Reputation: 31

XML XSD Decimal fractionDigits

I have an XSD schema, which a SimpleType - Decimal, fractionDigits = 2, as per this example How to specify minimal value for fractionDigits restriction in XML Schema?.

This quite rightly allows:-

12 12.34 12.06 12.5

But it also accepts 12.230000000 (it does not accept 12.230000001). Why does it not recognise those trailing zeros?

So, is there a way to only allow 2 digits after the decimal, so it errors on 12.230000000?

I've tried the pattern restriction seen here - How to specify minimal value for fractionDigits restriction in XML Schema? but still, it doesn't error on 12.23000000.

Any help will be greatly appreciated - I'm sure I'm missing something very simple!

thanks Craig

Upvotes: 2

Views: 2764

Answers (1)

Michael Kay
Michael Kay

Reputation: 163262

The fractionDigits facet is a restriction on the value space, not on the lexical space. This means that the value must be a multiple of 0.01, but there is no restriction on how the value is written.

If you want to restrict the lexical space (that is, the way in which the value is written) you can only do this using the pattern facet.

Personally I think it's generally a mistake to restrict the lexical space, because software that generates XML won't generally respect this. But that's up to you.

I can't explain why your attempt to use the pattern facet was unsuccesfull. If you do it as in the post that you cite, it should work.

Upvotes: 2

Related Questions