1
votes

I am validating an xml against xsd, which has a parameter, say "code" with datatype as integer.

I was expecting a validation error if I give "code", any value that starts with "0" such as "05" since it's not a valid integer as far as I know.

But the validation was successful. I wanted to know how is this possible? Or my understanding is wrong with respect to the valid values that integer can take.

1

1 Answers

0
votes

The xs:integer data type in XSD (both 1.0 and 1.1) permits leading zeros in the value. It also allows a leading "+" or "-" sign.

If you want to disallow leading zeroes for some reason (or to disallow a leading sign) you can achieve this by restricting the type using an xs:pattern facet; for example <xs:pattern value="0|[1-9][0-9]*"/> prohibits both leading zeroes and leading signs.

For the specification, see https://www.w3.org/TR/xmlschema11-2/#integer