1

I am using "Generate Sample XML" in visual studio 2010 based on my xsd file. However, the result contains invalid data for integer data types. Does anyone know of a way to fix it?

for example I get a number like -79724793284932479284902477492 for an element that its type is type="xsd:integer"

Any help is greatly appreciated!

Nicole
  • 57
  • 9
  • 1
    You could try this: http://www.xsd2xml.com/ – tom redfern Aug 21 '14 at 20:41
  • Thanks for this Tom! I already tried xsd2xml.com. Unfortunately it only generates one instance per tag. I need something that generates more sample. Also, it needs to generate sample data like "TagName1, TagName2,... not "string". – Nicole Aug 21 '14 at 20:54
  • 1
    Why do you believe that -79724793284932479284902477492 is not a valid integer? Are you using xsd:integer when you mean xsd:int? – C. M. Sperberg-McQueen Aug 22 '14 at 00:12
  • @C. M. Sperberg-McQueen It cause error when I bulk upload the xml to the database. I used "xsd:integer". Even when I use "xsd:int" in some tags it produces 10 digits negatives instead of 1, 2 3,... How can I avoid it? – Nicole Aug 22 '14 at 12:12
  • @C. M. Sperberg-McQueen Actually changing "xsd:integer" to "xsd:int" solved the problem. Although still I get ten digits negetive numbers but they can be uploaded to the database. I guess it is because xsd:integer represents longint! If you like, provide your comment as answer so I select it. Thanks for your help! :) – Nicole Aug 22 '14 at 12:22

1 Answers1

2

The value space of xsd:integer is the set of integers. That set includes numbers like the ones you specify, as well as ones which require even more digits, so the example generator you are using is not making any error here.

If you need to ensure that the values can fit into some fixed-width integer datatype, then you should consider using xsd:long, xsd:int, xsd:short, or xsd:byte. If you want to ensure that values are non-negative, consider xsd:unsignedLong, xsd:unsignedInt, xsd:unsignedShort, or xsd:unsignedByte.

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
  • So you mean there is no way to generate a sequence of integers? For the string data types I get sequence like TagName1, TagName2, TagnName3, ... – Nicole Aug 22 '14 at 13:39
  • No, I didn't say anything about sequences of integers or about what the tool you are using can and cannot generate. Your initial problem is that you supposed the generator to be generating invalid examples of the type xsd:integer; your analysis is incorrect, because the example you give is perfectly valid. My answer is about the value spaces of the different XSD numeric types and the need to say what you mean and mean what you say. – C. M. Sperberg-McQueen Aug 22 '14 at 13:46
  • Sorry, I was unclear. You are right, based on the data type, the resulting xml data is correct. I wonder if there is any way in Visual Studio to generate sequence for xsd:unsignedShort. Thanks for your help! :) – Nicole Aug 22 '14 at 13:51
  • 1
    It sounds like you may want to read up on XSD list datatypes; they would allow you to get a whitespace-delimited sequence of integers (or other simple types) in a single element or attribute. – C. M. Sperberg-McQueen Aug 22 '14 at 14:06