public static XmlSchema GenerateXSD(GeneratorContext context)
        {
            string targetNameSpace = NDR.getTargetNameSpace(context, false);
            IMa    documentRoot    = context.DocLibrary.DocumentRoot;
            var    schema          = new XmlSchema
            {
                TargetNamespace = targetNameSpace
            };

            //namespaces
            schema.Namespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
            schema.Namespaces.Add(context.NamespacePrefix, targetNameSpace);
            //qualifiedSetting
            schema.ElementFormDefault   = XmlSchemaForm.Qualified;
            schema.AttributeFormDefault = XmlSchemaForm.Unqualified;
            //version
            schema.Version = context.DocLibrary.VersionIdentifier.DefaultTo("1");

            string schemaFileName = getSchemaFileName(context, false);

            AddRootElementDeclaration(schema, documentRoot, context);
            GenerateComplexTypeForMa(context, schema, documentRoot);

            //non root elements, not used
            IEnumerable <IMa> nonRootDocLibraryElements = context.DocLibrary.NonRootMas;

            AddGlobalTypeDefinitions(schema, nonRootDocLibraryElements, context);
            AddGlobalElementDeclarations(schema, nonRootDocLibraryElements, context);

            context.AddSchema(schema, schemaFileName, UpccSchematype.ROOT);
            return(schema);
        }
        ///<summary>
        ///</summary>
        ///<param name="context"></param>
        public static void GenerateXSD(GeneratorContext context)
        {
            globalAsmas = new List <string>();
            IMa documentRoot = context.DocLibrary.DocumentRoot;
            var schema       = new XmlSchema
            {
                TargetNamespace = context.TargetNamespace
            };

            schema.Namespaces.Add(context.NamespacePrefix, context.TargetNamespace);
            schema.Namespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
            schema.Namespaces.Add("ccts",
                                  "urn:un:unece:uncefact:documentation:standard:XMLNDRDocumentation:3");
            schema.Namespaces.Add(NSPREFIX_BDT, context.TargetNamespace);
            schema.Namespaces.Add(NSPREFIX_BIE, context.TargetNamespace);

            schema.ElementFormDefault   = XmlSchemaForm.Qualified;
            schema.AttributeFormDefault = XmlSchemaForm.Unqualified;
            schema.Version = context.DocLibrary.VersionIdentifier.DefaultTo("1");

            //TODO how do i now what schemas to include and what to import
            AddImports(schema, context, context.DocLibrary);
            AddIncludes(schema, context, context.DocLibrary);

            AddRootElementDeclaration(schema, documentRoot, context);
            AddRootTypeDefinition(schema, documentRoot, context, context.DocLibrary);

            IEnumerable <IMa> nonRootDocLibraryElements = context.DocLibrary.NonRootMas;

            AddGlobalElementDeclarations(schema, nonRootDocLibraryElements, context);
            AddGlobalTypeDefinitions(schema, nonRootDocLibraryElements, context);
            context.AddSchema(schema, documentRoot.Name + "_" + schema.Version + ".xsd");
        }
示例#3
0
        ///<summary>
        ///</summary>
        ///<param name="context"></param>
        ///<param name="abies"></param>
        public static void GenerateXSD(GeneratorContext context, IEnumerable <IAbie> abies)
        {
            // Create XML schema file and prepare the XML schema header
            // R 88E2: all XML schema files must use UTF-8 encoding
            // R B387: every XML schema must have a declared target namespace
            globalASBIEs = new List <String>();

            var schema = new XmlSchema {
                TargetNamespace = context.TargetNamespace
            };

            schema.Namespaces.Add(context.NamespacePrefix, context.TargetNamespace);
            schema.Version = context.DocLibrary.VersionIdentifier.DefaultTo("1");

            // TODO: discuss R A0E5 and R A9C5 with Christian E. and Michi S. since this is something that should be added to the context
            // R A0E5: all XML schemas must contain elementFormDefault and set it to qualified
            schema.ElementFormDefault = XmlSchemaForm.Qualified;
            // R A9C5: All XML schemas must contain attributeFormDefault and set it to unqualified
            schema.AttributeFormDefault = XmlSchemaForm.Unqualified;

            // R 9B18: all XML schemas must utilize the xsd prefix when referring to the W3C XML schema namespace
            schema.Namespaces.Add(NSPREFIX_XSD, NS_XSD);

            schema.Namespaces.Add(NSPREFIX_DOC, NS_DOC);

            // add namespace to be able to utilize BDTs
            schema.Namespaces.Add(NSPREFIX_BDT, context.TargetNamespace);
            // add namespace to be able to utilize ABIEs
            schema.Namespaces.Add(NSPREFIX_TNS, context.TargetNamespace);


            // R 8FE2: include BDT XML schema file
            // TODO: check with christian e. if we can retrieve the bdt schema file from the context
            XmlSchemaInclude bdtInclude = new XmlSchemaInclude();

            bdtInclude.SchemaLocation = "BusinessDataType_" + schema.Version + ".xsd";
            schema.Includes.Add(bdtInclude);

            foreach (IAbie abie in abies.OrderBy(a => a.Name))
            {
                // finally add the complex type to the schema
                schema.Items.Add(GenerateComplexTypeABIE(context, schema, abie));

                // R 9DA0: for each ABIE a named element must be globally declared
                // R 9A25: the name of the ABIE element must be the DictionaryEntryName with whitespace
                //         and the 'Details' suffix removed
                // R B27B: every ABIE global element declaration must be of the complexType that represents
                //         the ABIE
                XmlSchemaElement elementBIE = new XmlSchemaElement();
                elementBIE.Name           = abie.Name;
                elementBIE.SchemaTypeName = new XmlQualifiedName(NSPREFIX_TNS + ":" + abie.Name + "Type");
                schema.Items.Add(elementBIE);
            }

            context.AddSchema(schema, "BusinessInformationEntity_" + schema.Version + ".xsd");
        }
        ///<summary>
        ///</summary>
        ///<param name="context"></param>
        ///<param name="cdts"></param>
        public static void GenerateXSD(GeneratorContext context, IEnumerable <ICdt> cdts)
        {
            var schema = new XmlSchema {
                TargetNamespace = context.TargetNamespace
            };

            schema.Namespaces.Add(context.NamespacePrefix, context.TargetNamespace);
            schema.Namespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
            schema.Namespaces.Add("ccts", "urn:un:unece:uncefact:documentation:standard:XMLNDRDocumentation:3");
            schema.Version = context.DocLibrary.VersionIdentifier.DefaultTo("1");

            foreach (ICdt cdt in cdts)
            {
                var sups = new List <ICdtSup>(cdt.Sups);
                if (sups.Count == 0)
                {
                    var simpleType = new XmlSchemaSimpleType {
                        Name = GetTypeName(cdt)
                    };
                    var simpleTypeRestriction = new XmlSchemaSimpleTypeRestriction
                    {
                        BaseTypeName = GetXmlQualifiedName(NDR.getConBasicTypeName(cdt))
                    };
                    simpleType.Content = simpleTypeRestriction;
                    if (context.Annotate)
                    {
                        simpleType.Annotation = GetTypeAnnotation(cdt);
                    }
                    schema.Items.Add(simpleType);
                }
                else
                {
                    var complexType = new XmlSchemaComplexType
                    {
                        // Deviation from rule [R 90FB]: Using simpler and shorter names for CDT complex types.
                        Name = GetTypeName(cdt)
                    };
                    var simpleContent          = new XmlSchemaSimpleContent();
                    var simpleContentExtension = new XmlSchemaSimpleContentExtension
                    {
                        BaseTypeName = GetXmlQualifiedName(NDR.getConBasicTypeName(cdt))
                    };
                    foreach (ICdtSup sup in sups)
                    {
                        var attribute = new XmlSchemaAttribute
                        {
                            // Deviation from rule [R ABC1]: Using only attribute name and type as xml attribute name (instead of complete DEN), following the examples given in the specification.
                            Name           = GetAttributeName(sup),
                            SchemaTypeName = new XmlQualifiedName(GetXSDType(NDR.GetBasicTypeName(sup as UpccAttribute)),
                                                                  "http://www.w3.org/2001/XMLSchema"),
                        };
                        if (context.Annotate)
                        {
                            attribute.Annotation = GetAttributeAnnotation(sup);
                        }
                        simpleContentExtension.Attributes.Add(attribute);
                    }

                    simpleContent.Content    = simpleContentExtension;
                    complexType.ContentModel = simpleContent;
                    if (context.Annotate)
                    {
                        complexType.Annotation = GetTypeAnnotation(cdt);
                    }
                    schema.Items.Add(complexType);
                }
            }

            context.AddSchema(schema, "CoreDataType_" + schema.Version + ".xsd", UpccSchematype.CDT);
        }
        ///<summary>
        ///</summary>
        ///<param name="context"></param>
        ///<param name="accs"></param>
        public static void GenerateXSD(GeneratorContext context, IEnumerable <IAcc> accs)
        {
            // Create XML schema file and prepare the XML schema header
            // R 88E2: all XML schema files must use UTF-8 encoding
            // R B387: every XML schema must have a declared target namespace
            globalASCCs = new List <string>();

            var schema = new XmlSchema {
                TargetNamespace = context.TargetNamespace
            };

            schema.Namespaces.Add(context.NamespacePrefix, context.TargetNamespace);
            schema.Version = context.DocLibrary.VersionIdentifier.DefaultTo("1");

            // TODO: discuss R A0E5 and R A9C5 with Christian E. and Michi S. since this is something that should be added to the context
            // R A0E5: all XML schemas must contain elementFormDefault and set it to qualified
            schema.ElementFormDefault = XmlSchemaForm.Qualified;
            // R A9C5: All XML schemas must contain attributeFormDefault and set it to unqualified
            schema.AttributeFormDefault = XmlSchemaForm.Unqualified;

            // R 9B18: all XML schemas must utilize the xsd prefix when referring to the W3C XML schema namespace

            schema.Namespaces.Add(NSPREFIX_XSD, NS_XSD);
            if (context.Annotate)
            {
                XmlSchemaImport import = new XmlSchemaImport
                {
                    Namespace =
                        "urn:un:unece:uncefact:documentation:standard:XMLNDRDocumentation:3",
                    SchemaLocation = "documentation/standard/XMLNDR_Documentation_3p0.xsd"
                };

                schema.Includes.Add(import);
                schema.Namespaces.Add(NSPREFIX_DOC, NS_DOC);
            }

            // add namespace to be able to utilize BDTs
            schema.Namespaces.Add(NSPREFIX_CDT, context.TargetNamespace);

            // R 8FE2: include BDT XML schema file
            // TODO: check with christian e. if we can retrieve the bdt schema file from the context
            XmlSchemaInclude cdtInclude = new XmlSchemaInclude();

            cdtInclude.SchemaLocation = "CoreDataType_" + schema.Version + ".xsd";
            schema.Includes.Add(cdtInclude);

            foreach (IAcc acc in accs.OrderBy(a => a.Name))
            {
                // finally add the complex type to the schema
                schema.Items.Add(GenerateComplexTypeACC(context, schema, acc));

                // R 9DA0: for each ABIE a named element must be globally declared
                // R 9A25: the name of the ABIE element must be the DictionaryEntryName with whitespace
                //         and the 'Details' suffix removed
                // R B27B: every ABIE global element declaration must be of the complexType that represents
                //         the ABIE
                XmlSchemaElement elementACC = new XmlSchemaElement();
                elementACC.Name           = acc.Name;
                elementACC.SchemaTypeName = new XmlQualifiedName(context.NamespacePrefix + ":" + acc.Name + "Type");
                schema.Items.Add(elementACC);
            }

            context.AddSchema(schema, "CoreComponent_" + schema.Version + ".xsd", UpccSchematype.ACC);
        }