XSD, restrictions and code generation

I am working on creating code for an existing project and I want to start with xsd. So I can use tools like Xsd2Code / xsd.exe to generate the code, and also use xsd to check the xml. This part works without problems.

I also want to translate some restrictions on DataAnnotations (enrich Xsd2Code). For example xs: minInclusive / xs: maxInclusive I can translate to RangeAttribute.

But what to do with the custom validation attributes we created? Can I add custom faces / constraints? And How? Or there is another solution / best practice.

I would like to collect everything in one file (xsd) so that one file contains the structure of the class (model), including the validation (attributes) that must be added.

<xs:element name="CertainValue">
  <xs:simpleType>
    <xs:restriction base="xs:double">
      <xs:minInclusive value="1" />
      <xs:maxInclusive value="100" />
      <xs_custom:customRule attribute="value" />
    </xs:restriction>
  </xs:simpleType>
</xs:element>
+3
1

XML , ( ). , , xs: annotation/xs: appinfo, . , - :

<xs:element name="CertainValue">
<xs:simpleType>
  <xs:restriction base="xs:double">
    <xs:annotation>
      <xs:appinfo>
        <xs_custom:customRule attribute="value" />       
      </xs:appinfo>
    </xs:annotation>
    <xs:minInclusive value="1" />
    <xs:maxInclusive value="100" />
  </xs:restriction>
</xs:simpleType>

, Xsd2Code , , XSD , appinfo, , . appinfo .

0

Source: https://habr.com/ru/post/1734864/


All Articles