0

I have an xsd file that I have used to generate XML entity classes with xsd.exe. The issue I am encountering is spaces appended to a numeric field. The specific section of the schema looks like this:

<xs:simpleType name="MyNumber">
    <xs:restriction base="xs:token">
      <xs:pattern value="\d{1,9}"/>
    </xs:restriction>
</xs:simpleType>

This number should contain values like: 1 or 123 or 123456, or 123456789. Basically, any number from 0 to 999999999. The problem is that the value is stored in the database as a char(9), so spaces are appended to the end if the value is less than 9 characters.

I'm wondering if there is a way to alter the schema file so that xsd.exe includes a restriction. The tools seems to be fairly limited, so I'm guessing this is not the case. I'm going to try minValue, maxValue as int instead of the current token and pattern. Hopefully that works. I just wanted to put this out there in case someone knows immediately. Thanks.

Update: I forgot to mention that I tried adding <xs:whiteSpace value="collapse"/> to the restriction and that did not work either.

kakridge
  • 2,153
  • 1
  • 17
  • 27

2 Answers2

0

I'm not sure if I understand well you need but couldn't <xs:whiteSpace value="collapse"/> make a job?

Jirka Š.
  • 3,388
  • 2
  • 15
  • 17
  • I tried that. It was in my update, but I didn't add the code block, so it wasn't showing up. I've added the code block. xsd.exe did not seem to generate anything to enforce it though. – kakridge Jul 12 '13 at 18:10
0

xsd.exe does not seem to support this at all. I can use int, but minValue and maxValue are also not enforced. I ended up adding code to enforce the constraint.

kakridge
  • 2,153
  • 1
  • 17
  • 27