문제

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.

도움이 되었습니까?

해결책 2

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top