I’d like to get an “ID” attribute of type int with a fixed number of digits and leading zeros if necessary.
So, if this number is, for example, 6 and I enter 1 I would get
000001
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
XSD doesn’t offer the kind of string manipulation you seem to have in mind here. If you want the ID to have six decimal digits, you can define it to require six decimal digits. Or if you want the user to be able to give a value as “1”, you can define the ID to have at most six digits. But in general, rules of the form “The user enters string X and the system maps that automatically to string Y” are out of scope for XSD.
To figure out how to deal with this situation, ask yourself (and perhaps explain to those reading this question) why you want this kind of string mapping? If it’s to ensure that “1” and “01” and “000001” all map to the same value, then declaring the attribute as integer already does that. If it’s something else (I’m having trouble coming up with alternate motivations), a different solution may be in order.
But now to the question you actually asked.
To define a subtype of
xs:integerwith exactly six digits in the lexical representation, you can write something like this:Or if (as Sean Kenny suggests in his comment) what you really want is not an integer, but just a string of exactly six decimal digits:
To define a subtype of integer that allows at most six digits, you can change
{6}to{1,6}in the pattern above, or use amaxExclusiveof 1000000, or settotalDigitsto 6.All this assumes that your problem is defining the datatype, not imposing the uniqueness constraint.