xs:int and xs:integer, what's the difference....

I am busy creating schema's and exposing them as a web service.
I always generate a client and try to post some messages and this time I was again surprised by BizTalk. (or should I say XML).
When creating a schema you can chose several types for an element. Some of these are xs:int and xs:integer.
I noticed these two before but didn't bother too much.
But now for the first time I see there is a clear difference in the way stuff is treated by .Net. Below is a screenshot of a node with the type xs:integer.

I also have some regular elements of type xs:int. Below is a screenshot of that.

Now after I generated the WCF service for this schema, I imported the WSDL into VS 2005 and I was quite surprised to see what intellisense did to these elements in visual studio :

 So intellisense showed me it was actually a string !... And the other node of type xs:int was the .Net type I expected to see.

So what did I learn today, to stay away from xs:integer and use xs:int instead.
Hope this will help someone in the future, if it does, leave a comment

 

Published Tue, Feb 8 2011 9:05 AM by Patrick Wellink
Filed under: , ,

Comments

# re: xs:int and xs:integer, what's the difference....

Tuesday, February 08, 2011 1:03 PM by Carlo

Hé Patrick,

the behavior is expected as the int in XML is limited to 32-bits numbers while the integer in XML is unlimited in the numbers it might contain. So, use int when the numbers you communicate are always within the boundaries of 32 bits and consider integer otherwise.

Carlo

# re: xs:int and xs:integer, what's the difference....

Tuesday, February 08, 2011 2:48 PM by Pinaki Ghatak

Hi Patrick.

Whoa!. I never realized this. Good to know. This is a good wake-up info, and keep this in mind.

# re: xs:int and xs:integer, what's the difference....

Tuesday, February 08, 2011 3:58 PM by Dan

Hi Patrick,

  The definitions for xs:int and xs:integer can be found in the documentation of W3C XML Schema, such as the following:

www.tech-know-ware.com/.../xsd-overview.html

  Basically, they recommend avoiding the use of types like xs:integer in schemas intended for binding tools.

# re: xs:int and xs:integer, what's the difference....

Thursday, February 10, 2011 8:13 AM by Patrick Wellink

@Carlo,

I knew there was a diference, but i did not expect the xs:integer to show up in code as a string.....

# re: xs:int and xs:integer, what's the difference....

Thursday, February 17, 2011 12:00 PM by Marc Weber

Hi Patrick,

I did encounter that behavior once before. And it actually correct by the w3C definition

byte -> A signed 8-bit integer

decimal ->      A decimal value

int ->      A signed 32-bit integer

integer ->      An integer value

long ->      A signed 64-bit integer

# re: xs:int and xs:integer, what's the difference....

Thursday, February 17, 2011 4:20 PM by Patrick Wellink

I know they were different, but i was surpised to see the 'integer' turn up as a string in intellisense when I used the webref I had in the client project.

That's what surprised me. Not that they were different but to see a integer (you would expect some number) reflected as a string.

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Please add 4 and 3 and type the answer here: