コード例 #1
0
        private void WriteDataType(XmlSchema schema, CremaDataType dataType)
        {
            var simpleType = new XmlSchemaSimpleType();

            if (dataType.IsFlag == true)
            {
                var flagType = new XmlSchemaSimpleType()
                {
                    Name = dataType.FlagTypeName
                };
                this.WriteTypeMembers(schema, flagType, dataType.Members);

                var simpleTypeList = new XmlSchemaSimpleTypeList()
                {
                    ItemTypeName = new XmlQualifiedName(dataType.FlagTypeName, schema.TargetNamespace)
                };
                simpleType.Content = simpleTypeList;

                schema.Items.Add(flagType);
                schema.Items.Add(simpleType);
            }
            else
            {
                this.WriteTypeMembers(schema, simpleType, dataType.Members);
                schema.Items.Add(simpleType);
            }

            simpleType.Name = dataType.TypeName;

            simpleType.WriteDescription(dataType.Comment);
            simpleType.WriteAppInfo(CremaSchema.TypeInfo, CremaSchema.Creator, dataType.CreationInfo.ID, schema.TargetNamespace);
            simpleType.WriteAppInfo(CremaSchema.TypeInfo, CremaSchema.CreatedDateTime, dataType.CreationInfo.DateTime, schema.TargetNamespace);
            simpleType.WriteAppInfo(CremaSchema.TypeInfo, CremaSchema.Modifier, dataType.ModificationInfo.ID, schema.TargetNamespace);
            simpleType.WriteAppInfo(CremaSchema.TypeInfo, CremaSchema.ModifiedDateTime, dataType.ModificationInfo.DateTime, schema.TargetNamespace);
            simpleType.WriteAppInfo(CremaSchema.TypeInfo, CremaSchema.ID, dataType.TypeID, schema.TargetNamespace);
            simpleType.WriteAppInfo(CremaSchema.TypeInfo, CremaSchema.Tags, dataType.Tags, schema.TargetNamespace);
            simpleType.WriteAppInfo(CremaSchema.TypeInfo, CremaSchema.CategoryPath, dataType.CategoryPath, schema.TargetNamespace, PathUtility.Separator);
        }
コード例 #2
0
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

        // <xs:simpleType name="LotteryNumber">
        XmlSchemaSimpleType LotteryNumberType = new XmlSchemaSimpleType();

        LotteryNumberType.Name = "LotteryNumber";

        // <xs:restriction base="xs:int">
        XmlSchemaSimpleTypeRestriction LotteryNumberRestriction = new XmlSchemaSimpleTypeRestriction();

        LotteryNumberRestriction.BaseTypeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");

        // <xs:minInclusive value="1"/>
        XmlSchemaMinInclusiveFacet minInclusive = new XmlSchemaMinInclusiveFacet();

        minInclusive.Value = "1";
        LotteryNumberRestriction.Facets.Add(minInclusive);

        // <xs:maxInclusive value="99"/>
        XmlSchemaMaxInclusiveFacet maxInclusive = new XmlSchemaMaxInclusiveFacet();

        maxInclusive.Value = "99";
        LotteryNumberRestriction.Facets.Add(maxInclusive);

        LotteryNumberType.Content = LotteryNumberRestriction;
        schema.Items.Add(LotteryNumberType);

        // <xs:simpleType name="LotteryNumberList">
        XmlSchemaSimpleType LotteryNumberListType = new XmlSchemaSimpleType();

        LotteryNumberListType.Name = "LotteryNumberList";

        // <xs:list itemType="LotteryNumber"/>
        XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();

        list.ItemTypeName             = new XmlQualifiedName("LotteryNumber", "");
        LotteryNumberListType.Content = list;

        schema.Items.Add(LotteryNumberListType);

        // <xs:simpleType name="LotteryNumbers">
        XmlSchemaSimpleType LotteryNumbersType = new XmlSchemaSimpleType();

        LotteryNumbersType.Name = "LotteryNumbers";

        // <xs:restriction base="LotteryNumberList">
        XmlSchemaSimpleTypeRestriction LotteryNumbersRestriction = new XmlSchemaSimpleTypeRestriction();

        LotteryNumbersRestriction.BaseTypeName = new XmlQualifiedName("LotteryNumberList", "");

        // <xs:length value="5"/>
        XmlSchemaLengthFacet length = new XmlSchemaLengthFacet();

        length.Value = "5";
        LotteryNumbersRestriction.Facets.Add(length);

        LotteryNumbersType.Content = LotteryNumbersRestriction;

        schema.Items.Add(LotteryNumbersType);

        // <xs:element name="TodaysLottery" type="LotteryNumbers">
        XmlSchemaElement TodaysLottery = new XmlSchemaElement();

        TodaysLottery.Name           = "TodaysLottery";
        TodaysLottery.SchemaTypeName = new XmlQualifiedName("LotteryNumbers", "");

        schema.Items.Add(TodaysLottery);

        XmlSchemaSet schemaSet = new XmlSchemaSet();

        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
        schemaSet.Add(schema);
        schemaSet.Compile();

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
        {
            compiledSchema = schema1;
        }

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        compiledSchema.Write(Console.Out, nsmgr);
    }
コード例 #3
0
        static void Check(ConformanceCheckContext ctx, ConformanceChecker checker, Hashtable visitedObjects, XmlSchemaObject value)
        {
            if (value == null)
            {
                return;
            }

            if (visitedObjects.Contains(value))
            {
                return;
            }
            visitedObjects.Add(value, value);

            if (value is XmlSchemaImport)
            {
                XmlSchemaImport so = (XmlSchemaImport)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaAll)
            {
                XmlSchemaAll so = (XmlSchemaAll)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaAnnotation)
            {
                XmlSchemaAnnotation so = (XmlSchemaAnnotation)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaAttribute)
            {
                XmlSchemaAttribute so = (XmlSchemaAttribute)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaAttributeGroup)
            {
                XmlSchemaAttributeGroup so = (XmlSchemaAttributeGroup)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
                Check(ctx, checker, visitedObjects, so.RedefinedAttributeGroup);
            }
            else if (value is XmlSchemaAttributeGroupRef)
            {
                XmlSchemaAttributeGroupRef so = (XmlSchemaAttributeGroupRef)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaChoice)
            {
                XmlSchemaChoice so = (XmlSchemaChoice)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaComplexContent)
            {
                XmlSchemaComplexContent so = (XmlSchemaComplexContent)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Content);
            }
            else if (value is XmlSchemaComplexContentExtension)
            {
                XmlSchemaComplexContentExtension so = (XmlSchemaComplexContentExtension)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Particle);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
            }
            else if (value is XmlSchemaComplexContentRestriction)
            {
                XmlSchemaComplexContentRestriction so = (XmlSchemaComplexContentRestriction)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Particle);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
            }
            else if (value is XmlSchemaComplexType)
            {
                XmlSchemaComplexType so = (XmlSchemaComplexType)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.ContentModel);
                Check(ctx, checker, visitedObjects, so.Particle);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
                Check(ctx, checker, visitedObjects, so.ContentTypeParticle);
                Check(ctx, checker, visitedObjects, so.AttributeWildcard);
            }
            else if (value is XmlSchemaElement)
            {
                XmlSchemaElement so = (XmlSchemaElement)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.SchemaType);
                CheckObjects(ctx, checker, visitedObjects, so.Constraints);
            }
            else if (value is XmlSchemaGroup)
            {
                XmlSchemaGroup so = (XmlSchemaGroup)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Particle);
            }
            else if (value is XmlSchemaGroupRef)
            {
                XmlSchemaGroupRef so = (XmlSchemaGroupRef)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaIdentityConstraint)
            {
                XmlSchemaIdentityConstraint so = (XmlSchemaIdentityConstraint)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Fields);
                Check(ctx, checker, visitedObjects, so.Selector);
            }
            else if (value is XmlSchemaKeyref)
            {
                XmlSchemaKeyref so = (XmlSchemaKeyref)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaRedefine)
            {
                XmlSchemaRedefine so = (XmlSchemaRedefine)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaSequence)
            {
                XmlSchemaSequence so = (XmlSchemaSequence)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaSimpleContent)
            {
                XmlSchemaSimpleContent so = (XmlSchemaSimpleContent)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Content);
            }
            else if (value is XmlSchemaSimpleContentExtension)
            {
                XmlSchemaSimpleContentExtension so = (XmlSchemaSimpleContentExtension)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
            }
            else if (value is XmlSchemaSimpleContentRestriction)
            {
                XmlSchemaSimpleContentRestriction so = (XmlSchemaSimpleContentRestriction)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
                CheckObjects(ctx, checker, visitedObjects, so.Facets);
            }
            else if (value is XmlSchemaSimpleType)
            {
                XmlSchemaSimpleType so = (XmlSchemaSimpleType)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Content);
            }
            else if (value is XmlSchemaSimpleTypeList)
            {
                XmlSchemaSimpleTypeList so = (XmlSchemaSimpleTypeList)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaSimpleTypeRestriction)
            {
                XmlSchemaSimpleTypeRestriction so = (XmlSchemaSimpleTypeRestriction)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Facets);
            }
            else if (value is XmlSchemaSimpleTypeUnion)
            {
                XmlSchemaSimpleTypeUnion so = (XmlSchemaSimpleTypeUnion)value;
                checker.Check(ctx, so);
            }
        }
コード例 #4
0
        internal void Depends(XmlSchemaObject item, ArrayList refs)
        {
            if (item == null || scope[item] != null)
            {
                return;
            }

            Type t = item.GetType();

            if (typeof(XmlSchemaType).IsAssignableFrom(t))
            {
                XmlQualifiedName          baseName   = XmlQualifiedName.Empty;
                XmlSchemaType             baseType   = null;
                XmlSchemaParticle         particle   = null;
                XmlSchemaObjectCollection attributes = null;

                if (item is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ct = (XmlSchemaComplexType)item;
                    if (ct.ContentModel != null)
                    {
                        XmlSchemaContent content = ct.ContentModel.Content;
                        if (content is XmlSchemaComplexContentRestriction)
                        {
                            baseName   = ((XmlSchemaComplexContentRestriction)content).BaseTypeName;
                            attributes = ((XmlSchemaComplexContentRestriction)content).Attributes;
                        }
                        else if (content is XmlSchemaSimpleContentRestriction)
                        {
                            XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction)content;
                            if (restriction.BaseType != null)
                            {
                                baseType = restriction.BaseType;
                            }
                            else
                            {
                                baseName = restriction.BaseTypeName;
                            }
                            attributes = restriction.Attributes;
                        }
                        else if (content is XmlSchemaComplexContentExtension)
                        {
                            XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content;
                            attributes = extension.Attributes;
                            particle   = extension.Particle;
                            baseName   = extension.BaseTypeName;
                        }
                        else if (content is XmlSchemaSimpleContentExtension)
                        {
                            XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension)content;
                            attributes = extension.Attributes;
                            baseName   = extension.BaseTypeName;
                        }
                    }
                    else
                    {
                        attributes = ct.Attributes;
                        particle   = ct.Particle;
                    }
                    if (particle is XmlSchemaGroupRef)
                    {
                        XmlSchemaGroupRef refGroup = (XmlSchemaGroupRef)particle;
                        particle = ((XmlSchemaGroup)schemas.Find(refGroup.RefName, typeof(XmlSchemaGroup), false)).Particle;
                    }
                    else if (particle is XmlSchemaGroupBase)
                    {
                        particle = (XmlSchemaGroupBase)particle;
                    }
                }
                else if (item is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType        simpleType = (XmlSchemaSimpleType)item;
                    XmlSchemaSimpleTypeContent content    = simpleType.Content;
                    if (content is XmlSchemaSimpleTypeRestriction)
                    {
                        baseType = ((XmlSchemaSimpleTypeRestriction)content).BaseType;
                        baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName;
                    }
                    else if (content is XmlSchemaSimpleTypeList)
                    {
                        XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList)content;
                        if (list.ItemTypeName != null && !list.ItemTypeName.IsEmpty)
                        {
                            baseName = list.ItemTypeName;
                        }
                        if (list.ItemType != null)
                        {
                            baseType = list.ItemType;
                        }
                    }
                    else if (content is XmlSchemaSimpleTypeRestriction)
                    {
                        baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName;
                    }
                    else if (t == typeof(XmlSchemaSimpleTypeUnion))
                    {
                        XmlQualifiedName[] memberTypes = ((XmlSchemaSimpleTypeUnion)item).MemberTypes;

                        if (memberTypes != null)
                        {
                            for (int i = 0; i < memberTypes.Length; i++)
                            {
                                XmlSchemaType type = (XmlSchemaType)schemas.Find(memberTypes[i], typeof(XmlSchemaType), false);
                                AddRef(refs, type);
                            }
                        }
                    }
                }
                if (baseType == null && !baseName.IsEmpty && baseName.Namespace != XmlSchema.Namespace)
                {
                    baseType = (XmlSchemaType)schemas.Find(baseName, typeof(XmlSchemaType), false);
                }

                if (baseType != null)
                {
                    AddRef(refs, baseType);
                }
                if (particle != null)
                {
                    Depends(particle, refs);
                }
                if (attributes != null)
                {
                    for (int i = 0; i < attributes.Count; i++)
                    {
                        Depends(attributes[i], refs);
                    }
                }
            }
            else if (t == typeof(XmlSchemaElement))
            {
                XmlSchemaElement el = (XmlSchemaElement)item;
                if (!el.SubstitutionGroup.IsEmpty)
                {
                    if (el.SubstitutionGroup.Namespace != XmlSchema.Namespace)
                    {
                        XmlSchemaElement head = (XmlSchemaElement)schemas.Find(el.SubstitutionGroup, typeof(XmlSchemaElement), false);
                        AddRef(refs, head);
                    }
                }
                if (!el.RefName.IsEmpty)
                {
                    el = (XmlSchemaElement)schemas.Find(el.RefName, typeof(XmlSchemaElement), false);
                    AddRef(refs, el);
                }
                else if (!el.SchemaTypeName.IsEmpty)
                {
                    XmlSchemaType type = (XmlSchemaType)schemas.Find(el.SchemaTypeName, typeof(XmlSchemaType), false);
                    AddRef(refs, type);
                }
                else
                {
                    Depends(el.SchemaType, refs);
                }
            }
            else if (t == typeof(XmlSchemaGroup))
            {
                Depends(((XmlSchemaGroup)item).Particle);
            }
            else if (t == typeof(XmlSchemaGroupRef))
            {
                XmlSchemaGroup group = (XmlSchemaGroup)schemas.Find(((XmlSchemaGroupRef)item).RefName, typeof(XmlSchemaGroup), false);
                AddRef(refs, group);
            }
            else if (typeof(XmlSchemaGroupBase).IsAssignableFrom(t))
            {
                foreach (XmlSchemaObject o in ((XmlSchemaGroupBase)item).Items)
                {
                    Depends(o, refs);
                }
            }
            else if (t == typeof(XmlSchemaAttributeGroupRef))
            {
                XmlSchemaAttributeGroup group = (XmlSchemaAttributeGroup)schemas.Find(((XmlSchemaAttributeGroupRef)item).RefName, typeof(XmlSchemaAttributeGroup), false);
                AddRef(refs, group);
            }
            else if (t == typeof(XmlSchemaAttributeGroup))
            {
                foreach (XmlSchemaObject o in ((XmlSchemaAttributeGroup)item).Attributes)
                {
                    Depends(o, refs);
                }
            }
            else if (t == typeof(XmlSchemaAttribute))
            {
                XmlSchemaAttribute at = (XmlSchemaAttribute)item;
                if (!at.RefName.IsEmpty)
                {
                    at = (XmlSchemaAttribute)schemas.Find(at.RefName, typeof(XmlSchemaAttribute), false);
                    AddRef(refs, at);
                }
                else if (!at.SchemaTypeName.IsEmpty)
                {
                    XmlSchemaType type = (XmlSchemaType)schemas.Find(at.SchemaTypeName, typeof(XmlSchemaType), false);
                    AddRef(refs, type);
                }
                else
                {
                    Depends(at.SchemaType, refs);
                }
            }
            if (typeof(XmlSchemaAnnotated).IsAssignableFrom(t))
            {
                XmlAttribute[] attrs = (XmlAttribute[])((XmlSchemaAnnotated)item).UnhandledAttributes;

                if (attrs != null)
                {
                    for (int i = 0; i < attrs.Length; i++)
                    {
                        XmlAttribute attribute = attrs[i];
                        if (attribute.LocalName == Wsdl.ArrayType && attribute.NamespaceURI == Wsdl.Namespace)
                        {
                            string           dims;
                            XmlQualifiedName qname = TypeScope.ParseWsdlArrayType(attribute.Value, out dims, item);
                            XmlSchemaType    type  = (XmlSchemaType)schemas.Find(qname, typeof(XmlSchemaType), false);
                            AddRef(refs, type);
                        }
                    }
                }
            }
        }
コード例 #5
0
        private XmlSchemaSimpleType ExtractSimpleType(string name, JsonSchema jSchema)
        {
            XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType
            {
                Name = name,
            };

            AddAnnotations(simpleType, jSchema);

            string reference = GetterExtensions.Ref(jSchema);
            if (reference != null)
            {
                XmlQualifiedName baseTypeName = new XmlQualifiedName(ExtractTypeFromDefinitionReference(reference));
                XmlSchemaSimpleTypeRestriction simpleTypeRestriction = new XmlSchemaSimpleTypeRestriction
                {
                    BaseTypeName = baseTypeName,
                };

                XmlSchemaSimpleTypeRestriction stringFacets = ExtractStringFacets(jSchema);
                if (stringFacets.Facets.Count > 0)
                {
                    foreach (XmlSchemaObject facet in stringFacets.Facets)
                    {
                        simpleTypeRestriction.Facets.Add(facet);
                    }
                }

                XmlSchemaSimpleTypeRestriction numberFacets = ExtractNumberAndIntegerFacets(jSchema, new TypeKeyword(JsonSchemaType.Number));
                if (numberFacets.Facets.Count > 0)
                {
                    foreach (XmlSchemaObject facet in numberFacets.Facets)
                    {
                        simpleTypeRestriction.Facets.Add(facet);
                    }
                }

                simpleType.Content = simpleTypeRestriction;

                return simpleType;
            }

            TypeKeyword type = jSchema.Get<TypeKeyword>();

            if (type == null)
            {
                // assume string type if type is missing
                XmlSchemaSimpleTypeRestriction noTypeSimpleType = ExtractStringFacets(jSchema);
                noTypeSimpleType.BaseTypeName = null;

                simpleType.Content = noTypeSimpleType;

                return simpleType;
            }

            if (type.Value == JsonSchemaType.String)
            {
                simpleType.Content = ExtractStringFacets(jSchema);
            }
            else if (type.Value == JsonSchemaType.Number || type.Value == JsonSchemaType.Integer)
            {
                simpleType.Content = ExtractNumberAndIntegerFacets(jSchema, type);
            }
            else if (type.Value == JsonSchemaType.Boolean)
            {
                XmlSchemaSimpleTypeRestriction content = new XmlSchemaSimpleTypeRestriction
                {
                    BaseTypeName = new XmlQualifiedName("boolean", XML_SCHEMA_NS),
                };
                simpleType.Content = content;
            }
            else if (type.Value == JsonSchemaType.Array)
            {
                string xlist = jSchema.OtherData.TryGetString("@xsdType");
                if (xlist.Equals("XmlList"))
                {
                    XmlSchemaSimpleTypeList theList = new XmlSchemaSimpleTypeList();
                    List<JsonSchema> items = GetterExtensions.Items(jSchema);
                    string typeRef = GetterExtensions.Ref(items[0]);
                    theList.ItemTypeName = new XmlQualifiedName(ExtractTypeFromDefinitionReference(typeRef));

                    simpleType.Content = theList;
                }
            }

            return simpleType;
        }
コード例 #6
0
 public override void Check(ConformanceCheckContext ctx, XmlSchemaSimpleTypeList value)
 {
     CheckSchemaQName(ctx, value, value.ItemTypeName);
 }
コード例 #7
0
        void ExportAttributeAccessor(XmlSchemaComplexType type, AttributeAccessor accessor, bool valueTypeOptional, string ns)
        {
            if (accessor == null)
            {
                return;
            }
            XmlSchemaObjectCollection attributes;

            if (type.ContentModel != null)
            {
                if (type.ContentModel.Content is XmlSchemaComplexContentRestriction)
                {
                    attributes = ((XmlSchemaComplexContentRestriction)type.ContentModel.Content).Attributes;
                }
                else if (type.ContentModel.Content is XmlSchemaComplexContentExtension)
                {
                    attributes = ((XmlSchemaComplexContentExtension)type.ContentModel.Content).Attributes;
                }
                else if (type.ContentModel.Content is XmlSchemaSimpleContentExtension)
                {
                    attributes = ((XmlSchemaSimpleContentExtension)type.ContentModel.Content).Attributes;
                }
                else
                {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidContent, type.ContentModel.Content.GetType().Name));
                }
            }
            else
            {
                attributes = type.Attributes;
            }

            if (accessor.IsSpecialXmlNamespace)
            {
                // add <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
                AddSchemaImport(XmlReservedNs.NsXml, ns);

                // generate <xsd:attribute ref="xml:lang" use="optional" />
                XmlSchemaAttribute attribute = new XmlSchemaAttribute();
                attribute.Use     = XmlSchemaUse.Optional;
                attribute.RefName = new XmlQualifiedName(accessor.Name, XmlReservedNs.NsXml);
                attributes.Add(attribute);
            }
            else if (accessor.Any)
            {
                if (type.ContentModel == null)
                {
                    type.AnyAttribute = new XmlSchemaAnyAttribute();
                }
                else
                {
                    XmlSchemaContent content = type.ContentModel.Content;
                    if (content is XmlSchemaComplexContentExtension)
                    {
                        XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content;
                        extension.AnyAttribute = new XmlSchemaAnyAttribute();
                    }
                    else if (content is XmlSchemaComplexContentRestriction)
                    {
                        XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)content;
                        restriction.AnyAttribute = new XmlSchemaAnyAttribute();
                    }
                }
            }
            else
            {
                XmlSchemaAttribute attribute = new XmlSchemaAttribute();
                attribute.Use = XmlSchemaUse.None;
                if (!accessor.HasDefault && !valueTypeOptional && accessor.Mapping.TypeDesc.IsValueType)
                {
                    attribute.Use = XmlSchemaUse.Required;
                }
                attribute.Name = accessor.Name;
                if (accessor.Namespace == null || accessor.Namespace == ns)
                {
                    // determine the form attribute value
                    XmlSchema schema = schemas[ns];
                    if (schema == null)
                    {
                        attribute.Form = accessor.Form == attributeFormDefault ? XmlSchemaForm.None : accessor.Form;
                    }
                    else
                    {
                        attribute.Form = accessor.Form == schema.AttributeFormDefault ? XmlSchemaForm.None : accessor.Form;
                    }
                    attributes.Add(attribute);
                }
                else
                {
                    // we are going to add the attribute to the top-level items. "use" attribute should not be set
                    attribute.Use  = XmlSchemaUse.None;
                    attribute.Form = accessor.Form;
                    AddSchemaItem(attribute, accessor.Namespace, ns);
                    XmlSchemaAttribute refAttribute = new XmlSchemaAttribute();
                    refAttribute.Use     = XmlSchemaUse.None;
                    refAttribute.RefName = new XmlQualifiedName(accessor.Name, accessor.Namespace);
                    attributes.Add(refAttribute);
                }
                if (accessor.Mapping is PrimitiveMapping)
                {
                    PrimitiveMapping pm = (PrimitiveMapping)accessor.Mapping;
                    if (pm.IsList)
                    {
                        // create local simple type for the list-like attributes
                        XmlSchemaSimpleType     dataType = new XmlSchemaSimpleType();
                        XmlSchemaSimpleTypeList list     = new XmlSchemaSimpleTypeList();
                        list.ItemTypeName    = ExportPrimitiveMapping(pm, accessor.Namespace == null ? ns : accessor.Namespace);
                        dataType.Content     = list;
                        attribute.SchemaType = dataType;
                    }
                    else
                    {
                        attribute.SchemaTypeName = ExportPrimitiveMapping(pm, accessor.Namespace == null ? ns : accessor.Namespace);
                    }
                }
                else if (!(accessor.Mapping is SpecialMapping))
                {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInternalError));
                }

                if (accessor.HasDefault && accessor.Mapping.TypeDesc.HasDefaultSupport)
                {
                    attribute.DefaultValue = ExportDefaultValue(accessor.Mapping, accessor.Default);
                }
            }
        }
コード例 #8
0
ファイル: ConformanceChecker.cs プロジェクト: Tsalex71/mono-1
 public virtual void Check(ConformanceCheckContext ctx, XmlSchemaSimpleTypeList value)
 {
 }
コード例 #9
0
 protected virtual void Visit(XmlSchemaSimpleTypeList list)
 {
     Traverse(list.BaseItemType);
 }
コード例 #10
0
        /// <summary>
        /// Processes an attribute, generating the required field and property. Potentially generates
        /// an enum for an attribute restriction.
        /// </summary>
        /// <param name="attribute">Attribute element being processed.</param>
        /// <param name="typeDeclaration">CodeTypeDeclaration to be used when outputting code.</param>
        /// <param name="outputXmlMethod">Member method for the OutputXml method.</param>
        private static void ProcessAttribute(XmlSchemaAttribute attribute, CodeTypeDeclaration typeDeclaration, CodeMemberMethod outputXmlMethod)
        {
            string          attributeName    = attribute.Name;
            string          rawAttributeType = attribute.SchemaTypeName.Name;
            string          attributeType    = null;
            EnumDeclaration enumDeclaration  = null;

            if (rawAttributeType == null || rawAttributeType.Length == 0)
            {
                XmlSchemaSimpleTypeRestriction simpleTypeRestriction = attribute.SchemaType.Content as XmlSchemaSimpleTypeRestriction;
                if (simpleTypeRestriction != null)
                {
                    attributeType = String.Concat(attributeName, "Type");

                    bool enumRestriction = false;
                    CodeTypeDeclaration enumTypeDeclaration = new CodeTypeDeclaration(attributeType);
                    enumTypeDeclaration.Attributes = MemberAttributes.Public;
                    enumTypeDeclaration.IsEnum     = true;
                    enumDeclaration = new EnumDeclaration(attributeType, enumTypeDeclaration);

                    foreach (XmlSchemaFacet facet in simpleTypeRestriction.Facets)
                    {
                        XmlSchemaEnumerationFacet enumFacet = facet as XmlSchemaEnumerationFacet;
                        if (enumFacet != null)
                        {
                            enumRestriction = true;
                            string enumValue = MakeEnumValue(enumFacet.Value);
                            enumDeclaration.AddValue(enumFacet.Value);
                            CodeMemberField memberField = new CodeMemberField(typeof(int), enumValue);
                            enumTypeDeclaration.Members.Add(memberField);

                            string enumItemDocumentation = GetDocumentation(enumFacet.Annotation);
                            if (enumItemDocumentation != null)
                            {
                                GenerateSummaryComment(memberField.Comments, enumItemDocumentation);
                            }
                        }

                        XmlSchemaPatternFacet patternFacet = facet as XmlSchemaPatternFacet;
                        if (patternFacet != null)
                        {
                            attributeType = (string)simpleTypeNamesToClrTypeNames[simpleTypeRestriction.BaseTypeName.Name];
                        }
                    }

                    if (enumRestriction)
                    {
                        typeDeclaration.Members.Add(enumTypeDeclaration);
                    }
                    else
                    {
                        enumDeclaration = null;
                    }
                }

                XmlSchemaSimpleTypeList simpleTypeList = attribute.SchemaType.Content as XmlSchemaSimpleTypeList;
                if (simpleTypeList != null)
                {
                    attributeType = simpleTypeList.ItemTypeName.Name;
                    EnumDeclaration declaration = (EnumDeclaration)typeNamesToEnumDeclarations[attributeType];
                    declaration.Flags = true;
                }
            }
            else
            {
                attributeType = (string)simpleTypeNamesToClrTypeNames[rawAttributeType];
            }

            string documentation = GetDocumentation(attribute.Annotation);

            // TODO: Handle required fields.
            GenerateFieldAndProperty(attributeName, attributeType, typeDeclaration, outputXmlMethod, enumDeclaration, documentation, false, false);
        }
コード例 #11
0
 internal void Depends(XmlSchemaObject item, ArrayList refs)
 {
     if ((item != null) && (this.scope[item] == null))
     {
         Type c = item.GetType();
         if (typeof(XmlSchemaType).IsAssignableFrom(c))
         {
             XmlQualifiedName          empty      = XmlQualifiedName.Empty;
             XmlSchemaType             o          = null;
             XmlSchemaParticle         particle   = null;
             XmlSchemaObjectCollection attributes = null;
             if (item is XmlSchemaComplexType)
             {
                 XmlSchemaComplexType type3 = (XmlSchemaComplexType)item;
                 if (type3.ContentModel != null)
                 {
                     XmlSchemaContent content = type3.ContentModel.Content;
                     if (content is XmlSchemaComplexContentRestriction)
                     {
                         empty      = ((XmlSchemaComplexContentRestriction)content).BaseTypeName;
                         attributes = ((XmlSchemaComplexContentRestriction)content).Attributes;
                     }
                     else if (content is XmlSchemaSimpleContentRestriction)
                     {
                         XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction)content;
                         if (restriction.BaseType != null)
                         {
                             o = restriction.BaseType;
                         }
                         else
                         {
                             empty = restriction.BaseTypeName;
                         }
                         attributes = restriction.Attributes;
                     }
                     else if (content is XmlSchemaComplexContentExtension)
                     {
                         XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content;
                         attributes = extension.Attributes;
                         particle   = extension.Particle;
                         empty      = extension.BaseTypeName;
                     }
                     else if (content is XmlSchemaSimpleContentExtension)
                     {
                         XmlSchemaSimpleContentExtension extension2 = (XmlSchemaSimpleContentExtension)content;
                         attributes = extension2.Attributes;
                         empty      = extension2.BaseTypeName;
                     }
                 }
                 else
                 {
                     attributes = type3.Attributes;
                     particle   = type3.Particle;
                 }
                 if (particle is XmlSchemaGroupRef)
                 {
                     XmlSchemaGroupRef ref2 = (XmlSchemaGroupRef)particle;
                     particle = ((XmlSchemaGroup)this.schemas.Find(ref2.RefName, typeof(XmlSchemaGroup), false)).Particle;
                 }
                 else if (particle is XmlSchemaGroupBase)
                 {
                     particle = (XmlSchemaGroupBase)particle;
                 }
             }
             else if (item is XmlSchemaSimpleType)
             {
                 XmlSchemaSimpleType        type4    = (XmlSchemaSimpleType)item;
                 XmlSchemaSimpleTypeContent content2 = type4.Content;
                 if (content2 is XmlSchemaSimpleTypeRestriction)
                 {
                     o     = ((XmlSchemaSimpleTypeRestriction)content2).BaseType;
                     empty = ((XmlSchemaSimpleTypeRestriction)content2).BaseTypeName;
                 }
                 else if (content2 is XmlSchemaSimpleTypeList)
                 {
                     XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList)content2;
                     if ((list.ItemTypeName != null) && !list.ItemTypeName.IsEmpty)
                     {
                         empty = list.ItemTypeName;
                     }
                     if (list.ItemType != null)
                     {
                         o = list.ItemType;
                     }
                 }
                 else if (content2 is XmlSchemaSimpleTypeRestriction)
                 {
                     empty = ((XmlSchemaSimpleTypeRestriction)content2).BaseTypeName;
                 }
                 else if (c == typeof(XmlSchemaSimpleTypeUnion))
                 {
                     XmlQualifiedName[] memberTypes = ((XmlSchemaSimpleTypeUnion)item).MemberTypes;
                     if (memberTypes != null)
                     {
                         for (int i = 0; i < memberTypes.Length; i++)
                         {
                             XmlSchemaType type5 = (XmlSchemaType)this.schemas.Find(memberTypes[i], typeof(XmlSchemaType), false);
                             this.AddRef(refs, type5);
                         }
                     }
                 }
             }
             if (((o == null) && !empty.IsEmpty) && (empty.Namespace != "http://www.w3.org/2001/XMLSchema"))
             {
                 o = (XmlSchemaType)this.schemas.Find(empty, typeof(XmlSchemaType), false);
             }
             if (o != null)
             {
                 this.AddRef(refs, o);
             }
             if (particle != null)
             {
                 this.Depends(particle, refs);
             }
             if (attributes != null)
             {
                 for (int j = 0; j < attributes.Count; j++)
                 {
                     this.Depends(attributes[j], refs);
                 }
             }
         }
         else if (c == typeof(XmlSchemaElement))
         {
             XmlSchemaElement element = (XmlSchemaElement)item;
             if (!element.SubstitutionGroup.IsEmpty && (element.SubstitutionGroup.Namespace != "http://www.w3.org/2001/XMLSchema"))
             {
                 XmlSchemaElement element2 = (XmlSchemaElement)this.schemas.Find(element.SubstitutionGroup, typeof(XmlSchemaElement), false);
                 this.AddRef(refs, element2);
             }
             if (!element.RefName.IsEmpty)
             {
                 element = (XmlSchemaElement)this.schemas.Find(element.RefName, typeof(XmlSchemaElement), false);
                 this.AddRef(refs, element);
             }
             else if (!element.SchemaTypeName.IsEmpty)
             {
                 XmlSchemaType type6 = (XmlSchemaType)this.schemas.Find(element.SchemaTypeName, typeof(XmlSchemaType), false);
                 this.AddRef(refs, type6);
             }
             else
             {
                 this.Depends(element.SchemaType, refs);
             }
         }
         else if (c == typeof(XmlSchemaGroup))
         {
             this.Depends(((XmlSchemaGroup)item).Particle);
         }
         else if (c == typeof(XmlSchemaGroupRef))
         {
             XmlSchemaGroup group = (XmlSchemaGroup)this.schemas.Find(((XmlSchemaGroupRef)item).RefName, typeof(XmlSchemaGroup), false);
             this.AddRef(refs, group);
         }
         else if (typeof(XmlSchemaGroupBase).IsAssignableFrom(c))
         {
             foreach (XmlSchemaObject obj2 in ((XmlSchemaGroupBase)item).Items)
             {
                 this.Depends(obj2, refs);
             }
         }
         else if (c == typeof(XmlSchemaAttributeGroupRef))
         {
             XmlSchemaAttributeGroup group2 = (XmlSchemaAttributeGroup)this.schemas.Find(((XmlSchemaAttributeGroupRef)item).RefName, typeof(XmlSchemaAttributeGroup), false);
             this.AddRef(refs, group2);
         }
         else if (c == typeof(XmlSchemaAttributeGroup))
         {
             foreach (XmlSchemaObject obj3 in ((XmlSchemaAttributeGroup)item).Attributes)
             {
                 this.Depends(obj3, refs);
             }
         }
         else if (c == typeof(XmlSchemaAttribute))
         {
             XmlSchemaAttribute attribute = (XmlSchemaAttribute)item;
             if (!attribute.RefName.IsEmpty)
             {
                 attribute = (XmlSchemaAttribute)this.schemas.Find(attribute.RefName, typeof(XmlSchemaAttribute), false);
                 this.AddRef(refs, attribute);
             }
             else if (!attribute.SchemaTypeName.IsEmpty)
             {
                 XmlSchemaType type7 = (XmlSchemaType)this.schemas.Find(attribute.SchemaTypeName, typeof(XmlSchemaType), false);
                 this.AddRef(refs, type7);
             }
             else
             {
                 this.Depends(attribute.SchemaType, refs);
             }
         }
         if (typeof(XmlSchemaAnnotated).IsAssignableFrom(c))
         {
             XmlAttribute[] unhandledAttributes = ((XmlSchemaAnnotated)item).UnhandledAttributes;
             if (unhandledAttributes != null)
             {
                 for (int k = 0; k < unhandledAttributes.Length; k++)
                 {
                     XmlAttribute attribute2 = unhandledAttributes[k];
                     if ((attribute2.LocalName == "arrayType") && (attribute2.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/"))
                     {
                         string           str;
                         XmlQualifiedName name  = TypeScope.ParseWsdlArrayType(attribute2.Value, out str, item);
                         XmlSchemaType    type8 = (XmlSchemaType)this.schemas.Find(name, typeof(XmlSchemaType), false);
                         this.AddRef(refs, type8);
                     }
                 }
             }
         }
     }
 }
コード例 #12
0
        static void JsonSimpleTypeListHandler(XmlSchemaObject schemaObject, HelpExampleGeneratorContext context)
        {
            XmlSchemaSimpleTypeList simpleTypeList = (XmlSchemaSimpleTypeList)schemaObject;

            InvokeHandler(simpleTypeList.ItemType, context);
        }