xsdcodefluentaltova

How to create and XSD schema file from a Codefluent CFP file?


I'm working on a project which uses Codefluent entities to define the application's schema and produce and SQL database, class libraries, web pages, and winforms. Also used are the Altova XmlSpy products.

I am trying to figure out how I can extract from the Codefluent model an XSD schema representation of the Codefluent model so that it could be used with Altova's XmlStyleVision.

In Softfluent's documentation, https://www.softfluent.com/documentation/CF_Tools_Builder.html, there is a compile option "/ExtractSchema" but that create 5000 lines of attributes and enumerations and contains nothing relating to the data model.

Any thoughts or suggestions would be greatly appreciated!


Solution

  • /ExtractSchema extracts the xsd for creating CodeFluent Entities models. For instance, this allows you to get auto-completion in Visual Studio. This schema is not related to your model, and is not what you want.

    The easiest way to generate a schema for you model is to create a template and add the Template Producer to your model. First, create a folder and add a file named [Template]schema.xsd (must be prefixed by [Template]). I don't know what Altova's XmlStyleVision needs, but the following template should be a good start.

    [%@ namespace name="CodeFluent.Model"%]
    [%@ namespace name="CodeFluent.Model.Persistence"%]
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    [%foreach (Entity e in Producer.Project.Entities)
    {%]
        <xs:element name="[%= e.Name %]">
            <xs:complexType>
                <xs:sequence>
                [%foreach (Property p in e.Properties) { %]      
                    <xs:element name="[%= p.Name %]" type="xs:string" />
                [% } %]                    
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    [% } %]
    </xs:schema>
    

    Finally, add the template producer to your model: https://www.softfluent.com/documentation/TemplateProducers_TemplateProducer.html

    Now, the xsd file will be generated when you build the model.