XSD, restrictions and code generation

Posted by bob on Stack Overflow See other posts from Stack Overflow or by bob
Published on 2010-03-01T12:13:44Z Indexed on 2010/06/18 13:33 UTC
Read the original article Hit count: 250

Filed under:
|
|
|

Hello,

I'm working on some code generation for an existing project and I want to start from a xsd. So I can use tools as Xsd2Code / xsd.exe to generate the code and also the use the xsd to validate the xml. That part works without any problems.

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

But what to do with custom validation attributes that we created? Can I add custom facets / restrictions? And how? Or is there another solution / best practice.

I would like to collect everything in a single (xsd) file so that one file contains the structure of the class (model) including the validation (attributes) that has to 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>

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xsd