private static ICdtSup GetSup(ICdt cdt, string name)
 {
     foreach (ICdtSup sup in cdt.Sups)
     {
         if (name == NDR.GetXsdAttributeNameFromSup(sup))
         {
             return(sup);
         }
     }
     return(null);
 }
示例#2
0
        ///<summary>
        ///</summary>
        ///<param name="context"></param>
        ///<param name="bdts"></param>
        public static void GenerateXSD(GeneratorContext context, IEnumerable <IBdt> bdts)
        {
            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 (IBdt bdt in bdts)
            {
                var sups = new List <IBdtSup>(bdt.Sups);
                if (sups.Count == 0)
                {
                    var simpleType = new XmlSchemaSimpleType {
                        Name = NDR.GetXsdTypeNameFromBdt(bdt)
                    };
                    var simpleTypeRestriction = new XmlSchemaSimpleTypeRestriction
                    {
                        BaseTypeName = GetXmlQualifiedName(bdt.Con.BasicType.Name)
                    };
                    simpleType.Content = simpleTypeRestriction;
                    if (context.Annotate)
                    {
                        simpleType.Annotation = GetTypeAnnotation(bdt);
                    }
                    schema.Items.Add(simpleType);
                }
                else
                {
                    var complexType = new XmlSchemaComplexType
                    {
                        Name = NDR.GetXsdTypeNameFromBdt(bdt)
                    };
                    var simpleContent          = new XmlSchemaSimpleContent();
                    var simpleContentExtension = new XmlSchemaSimpleContentExtension
                    {
                        BaseTypeName = GetXmlQualifiedName(bdt.Con.BasicType.Name)
                    };
                    foreach (IBdtSup 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           = NDR.GetXsdAttributeNameFromSup(sup),
                            SchemaTypeName = new XmlQualifiedName(GetXSDType(sup.BasicType.Name),
                                                                  "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(bdt);
                    }
                    schema.Items.Add(complexType);
                }
            }
            context.AddSchema(schema, "BusinessDataType_" + schema.Version + ".xsd");
        }