Example #1
0
		internal XmlSchemaInfo (IXmlSchemaInfo info)
		{
			isDefault = info.IsDefault;
			isNil = info.IsNil;
			memberType = info.MemberType;
			attr = info.SchemaAttribute;
			elem = info.SchemaElement;
			type = info.SchemaType;
			validity = info.Validity;
		}
        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);
                        }
                    }
                }
            }
        }
Example #3
0
 public TypeDesc(string name, string fullName, bool isXsdType, XmlSchemaSimpleType dataType, string formatterName, TypeFlags flags) : this(name, fullName, TypeKind.Primitive, (TypeDesc)null, flags)
 {
     this.dataType      = dataType;
     this.formatterName = formatterName;
     this.isXsdType     = isXsdType;
 }
Example #4
0
        internal void LoadTypeValues(XmlSchemaSimpleType node)
        {
            if ((node.Content is XmlSchemaSimpleTypeList) ||
                (node.Content is XmlSchemaSimpleTypeUnion))
            {
                throw ExceptionBuilder.SimpleTypeNotSupported();
            }

            if (node.Content is XmlSchemaSimpleTypeRestriction)
            {
                XmlSchemaSimpleTypeRestriction content = (XmlSchemaSimpleTypeRestriction)node.Content;

                XmlSchemaSimpleType ancestor = node.BaseXmlSchemaType as XmlSchemaSimpleType;
                if ((ancestor != null) && (ancestor.QualifiedName.Namespace != Keywords.XSDNS))
                {
                    _baseSimpleType = new SimpleType(node.BaseXmlSchemaType as XmlSchemaSimpleType);
                }

                // do we need to put qualified name?
                // for user defined simpletype, always go with qname
                if (content.BaseTypeName.Namespace == Keywords.XSDNS)
                {
                    _baseType = content.BaseTypeName.Name;
                }
                else
                {
                    _baseType = content.BaseTypeName.ToString();
                }


                if (_baseSimpleType != null && _baseSimpleType.Name != null && _baseSimpleType.Name.Length > 0)
                {
                    _xmlBaseType = _baseSimpleType.XmlBaseType; //  SimpleTypeQualifiedName;
                }
                else
                {
                    _xmlBaseType = content.BaseTypeName;
                }

                if (_baseType == null || _baseType.Length == 0)
                {
                    _baseType    = content.BaseType.Name;
                    _xmlBaseType = null;
                }

                if (_baseType == "NOTATION")
                {
                    _baseType = "string";
                }


                foreach (XmlSchemaFacet facet in content.Facets)
                {
                    if (facet is XmlSchemaLengthFacet)
                    {
                        _length = Convert.ToInt32(facet.Value, null);
                    }

                    if (facet is XmlSchemaMinLengthFacet)
                    {
                        _minLength = Convert.ToInt32(facet.Value, null);
                    }

                    if (facet is XmlSchemaMaxLengthFacet)
                    {
                        _maxLength = Convert.ToInt32(facet.Value, null);
                    }

                    if (facet is XmlSchemaPatternFacet)
                    {
                        _pattern = facet.Value;
                    }

                    if (facet is XmlSchemaEnumerationFacet)
                    {
                        _enumeration = !string.IsNullOrEmpty(_enumeration) ? _enumeration + " " + facet.Value : facet.Value;
                    }

                    if (facet is XmlSchemaMinExclusiveFacet)
                    {
                        _minExclusive = facet.Value;
                    }

                    if (facet is XmlSchemaMinInclusiveFacet)
                    {
                        _minInclusive = facet.Value;
                    }

                    if (facet is XmlSchemaMaxExclusiveFacet)
                    {
                        _maxExclusive = facet.Value;
                    }

                    if (facet is XmlSchemaMaxInclusiveFacet)
                    {
                        _maxInclusive = facet.Value;
                    }
                }
            }

            string tempStr = XSDSchema.GetMsdataAttribute(node, Keywords.TARGETNAMESPACE);

            if (tempStr != null)
            {
                _ns = tempStr;
            }
        }
Example #5
0
        TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, bool isList)
        {
            TypeMapping mapping = (TypeMapping)ImportedMappings[dataType];

            if (mapping != null)
            {
                return(mapping);
            }

            XmlSchemaSimpleType sourceDataType = FindDataType(dataType.DerivedFrom);
            TypeDesc            sourceTypeDesc = Scope.GetTypeDesc(sourceDataType);

            if (sourceTypeDesc != null && sourceTypeDesc != Scope.GetTypeDesc(typeof(string)))
            {
                return(ImportPrimitiveDataType(dataType));
            }
            identifier = Accessor.UnescapeName(identifier);
            string      typeName    = GenerateUniqueTypeName(identifier);
            EnumMapping enumMapping = new EnumMapping();

            enumMapping.IsReference = Schemas.IsReference(dataType);
            enumMapping.TypeDesc    = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0);
            enumMapping.TypeName    = identifier;
            enumMapping.Namespace   = typeNs;
            enumMapping.IsFlags     = isList;
            CodeIdentifiers constants = new CodeIdentifiers();

            if (!(dataType.Content is XmlSchemaSimpleTypeRestriction))
            {
                throw new InvalidOperationException(Res.GetString(Res.XmlInvalidEnumContent, dataType.Content.GetType().Name, identifier));
            }

            XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)dataType.Content;

            for (int i = 0; i < restriction.Facets.Count; i++)
            {
                object facet = restriction.Facets[i];
                if (!(facet is XmlSchemaEnumerationFacet))
                {
                    continue;
                }
                XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet)facet;
                ConstantMapping           constant    = new ConstantMapping();
                string constantName = CodeIdentifier.MakeValid(enumeration.Value);
                constant.Name    = constants.AddUnique(constantName, constant);
                constant.XmlName = enumeration.Value;
                constant.Value   = i;
            }
            enumMapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping));
            if (isList && enumMapping.Constants.Length > 63)
            {
                // if we have 64+ flag constants we cannot map the type to long enum, we will use string mapping instead.
                mapping          = new PrimitiveMapping();
                mapping.TypeDesc = Scope.GetTypeDesc(typeof(string));
                mapping.TypeName = mapping.TypeDesc.DataType.Name;
                ImportedMappings.Add(dataType, mapping);
                return(mapping);
            }
            ImportedMappings.Add(dataType, enumMapping);
            Scope.AddTypeMapping(enumMapping);
            return(enumMapping);
        }
Example #6
0
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

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

        SizeType.Name = "SizeType";

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

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

        // <xs:enumeration value="Small"/>
        XmlSchemaEnumerationFacet enumerationSmall = new XmlSchemaEnumerationFacet();

        enumerationSmall.Value = "Small";
        restriction.Facets.Add(enumerationSmall);

        // <xs:enumeration value="Medium"/>
        XmlSchemaEnumerationFacet enumerationMedium = new XmlSchemaEnumerationFacet();

        enumerationMedium.Value = "Medium";
        restriction.Facets.Add(enumerationMedium);

        // <xs:enumeration value="Large"/>
        XmlSchemaEnumerationFacet enumerationLarge = new XmlSchemaEnumerationFacet();

        enumerationLarge.Value = "Large";
        restriction.Facets.Add(enumerationLarge);

        SizeType.Content = restriction;

        schema.Items.Add(SizeType);

        // <xs:element name="Item">
        XmlSchemaElement elementItem = new XmlSchemaElement();

        elementItem.Name = "Item";

        // <xs:complexType>
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();

        // <xs:attribute name="Size" type="SizeType"/>
        XmlSchemaAttribute attributeSize = new XmlSchemaAttribute();

        attributeSize.Name           = "Size";
        attributeSize.SchemaTypeName = new XmlQualifiedName("SizeType", "");
        complexType.Attributes.Add(attributeSize);

        elementItem.SchemaType = complexType;

        schema.Items.Add(elementItem);

        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);
    }
        /// <summary>
        /// Create a table schema from the XML Schema specification.
        /// </summary>
        /// <param name="presentationSchema">The data model to which this table belongs.</param>
        /// <param name="xmlSchemaElement">The root of the XmlSchema element that describes the table.</param>
        public PropertySchema(ClassSchema classSchema, XmlSchemaElement xmlSchemaElement)
        {
            // Initialize the object.
            this.classSchema       = classSchema;
            this.isSimpleType      = true;
            this.maxOccurs         = xmlSchemaElement.MaxOccurs;
            this.minOccurs         = xmlSchemaElement.MinOccurs;
            this.name              = xmlSchemaElement.Name;
            this.querySchemaList   = new List <QuerySchema>();
            this.snippetSchemaList = new List <SnippetSchema>();
            this.type              = String.Empty;

            // Initialize the data type from a complex type description.  The complex type can describe either a non-standard XML
            // data type through the unhandled 'DataType' specification, or it can reference a data type that's declared in the
            // schema.
            if (xmlSchemaElement.ElementSchemaType is XmlSchemaComplexType)
            {
                XmlSchemaComplexType xmlSchemaComplexType = xmlSchemaElement.ElementSchemaType as XmlSchemaComplexType;
                if (xmlSchemaComplexType.QualifiedName == QualifiedName.AnyType)
                {
                    foreach (XmlAttribute xmlAttribute in xmlSchemaElement.UnhandledAttributes)
                    {
                        if (QualifiedName.DataType == new XmlQualifiedName(xmlAttribute.LocalName, xmlAttribute.NamespaceURI))
                        {
                            this.isSimpleType = true;
                            this.type         = xmlAttribute.Value;
                        }
                    }
                }
                else
                {
                    this.type         = xmlSchemaComplexType.QualifiedName.ToString();
                    this.isSimpleType = false;
                }
            }

            // Initialize the data type from a simple type description.
            if (xmlSchemaElement.ElementSchemaType is XmlSchemaSimpleType)
            {
                XmlSchemaSimpleType xmlSchemaSimpleType = xmlSchemaElement.ElementSchemaType as XmlSchemaSimpleType;
                this.isSimpleType = true;
                this.type         = xmlSchemaSimpleType.Datatype.ValueType.FullName;
            }

            // This will run through each of the custom fields associated with the element and create fields that will sort, filter
            // and transform the data from the source list into the destination list.
            if (xmlSchemaElement.Annotation != null)
            {
                foreach (XmlSchemaObject xmlSchemaObject in xmlSchemaElement.Annotation.Items)
                {
                    if (xmlSchemaObject is XmlSchemaAppInfo)
                    {
                        XmlSchemaAppInfo xmlSchemaAppInfo = xmlSchemaObject as XmlSchemaAppInfo;
                        foreach (XmlNode xmlNode in xmlSchemaAppInfo.Markup)
                        {
                            XmlQualifiedName nodeName = new XmlQualifiedName(xmlNode.LocalName, xmlNode.NamespaceURI);
                            if (QualifiedName.Where == nodeName)
                            {
                                this.querySchemaList.Add(new WhereSchema(this, xmlNode));
                            }
                            if (QualifiedName.Select == nodeName)
                            {
                                this.querySchemaList.Add(new SelectSchema(this, xmlNode));
                            }
                            if (QualifiedName.OrderBy == nodeName)
                            {
                                this.querySchemaList.Add(new OrderBySchema(this, xmlNode));
                            }
                            if (QualifiedName.Snippet == nodeName)
                            {
                                this.snippetSchemaList.Add(new SnippetSchema(xmlNode));
                            }
                            if (QualifiedName.Setter == nodeName)
                            {
                                this.snippetSchemaList.Add(new SetterSchema(xmlNode));
                            }
                        }
                    }
                }
            }
        }
Example #8
0
 void WriteSimpleTypeSample(XmlTextWriter xtw, XmlSchemaSimpleType stype)
 {
     xtw.WriteString(GetLiteral(FindBuiltInType(stype)));
 }
Example #9
0
        public XmlSchemaElement GetSchema()
        {
            var type = new XmlSchemaComplexType();

            type.Attributes.Add(new XmlSchemaAttribute
            {
                Name           = "refValue",
                Use            = XmlSchemaUse.Required,
                SchemaTypeName =
                    new XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema")
            });

            type.Attributes.Add(new XmlSchemaAttribute
            {
                Name           = "test",
                Use            = XmlSchemaUse.Optional,
                SchemaTypeName =
                    new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
            });


            var restriction = new XmlSchemaSimpleTypeRestriction
            {
                BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
            };

            restriction.Facets.Add(new XmlSchemaEnumerationFacet {
                Value = "years"
            });
            restriction.Facets.Add(new XmlSchemaEnumerationFacet {
                Value = "weeks"
            });
            restriction.Facets.Add(new XmlSchemaEnumerationFacet {
                Value = "days"
            });

            var simpleType = new XmlSchemaSimpleType {
                Content = restriction
            };


            type.Attributes.Add(new XmlSchemaAttribute
            {
                Name       = "units",
                Use        = XmlSchemaUse.Required,
                SchemaType = simpleType
            });


            type.Attributes.Add(new XmlSchemaAttribute
            {
                Name           = "expressionLanguage",
                Use            = XmlSchemaUse.Optional,
                SchemaTypeName =
                    new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
            });

            var element = new XmlSchemaElement
            {
                Name       = "dicom-age-less-than",
                SchemaType = type
            };

            return(element);
        }
Example #10
0
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

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

        StringOrIntType.Name = "StringOrIntType";
        schema.Items.Add(StringOrIntType);

        // <xs:union>
        XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion();

        StringOrIntType.Content = union;

        // <xs:simpleType>
        XmlSchemaSimpleType simpleType1 = new XmlSchemaSimpleType();

        union.BaseTypes.Add(simpleType1);

        // <xs:restriction base="xs:string"/>
        XmlSchemaSimpleTypeRestriction restriction1 = new XmlSchemaSimpleTypeRestriction();

        restriction1.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        simpleType1.Content       = restriction1;

        // <xs:simpleType>
        XmlSchemaSimpleType simpleType2 = new XmlSchemaSimpleType();

        union.BaseTypes.Add(simpleType2);

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

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


        // <xs:element name="size" type="StringOrIntType"/>
        XmlSchemaElement elementSize = new XmlSchemaElement();

        elementSize.Name           = "size";
        elementSize.SchemaTypeName = new XmlQualifiedName("StringOrIntType");
        schema.Items.Add(elementSize);

        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);
    }
Example #11
0
        internal void LoadTypeValues(XmlSchemaSimpleType node)
        {
            if ((node.Content is XmlSchemaSimpleTypeList) ||
                (node.Content is XmlSchemaSimpleTypeUnion))
            {
                throw ExceptionBuilder.SimpleTypeNotSupported();
            }

            if (node.Content is XmlSchemaSimpleTypeRestriction)
            {
                XmlSchemaSimpleTypeRestriction content = (XmlSchemaSimpleTypeRestriction)node.Content;

                XmlSchemaSimpleType ancestor = node.BaseXmlSchemaType as XmlSchemaSimpleType;
                if ((ancestor != null) && (ancestor.QualifiedName.Namespace != Keywords.XSDNS))   // I'm assuming that built-in types don't have a name!
//                    Console.WriteLine("In simpleNode, ancestor.Name = '{0}'", ancestor.Name);
                {
                    baseSimpleType = new SimpleType(node.BaseXmlSchemaType as XmlSchemaSimpleType);
//                    baseSimpleType = new SimpleType(node);
                }

// do we need to put qualified name?
// for user defined simpletype, always go with qname
                if (content.BaseTypeName.Namespace == Keywords.XSDNS)
                {
                    baseType = content.BaseTypeName.Name;
                }
                else
                {
                    baseType = content.BaseTypeName.ToString();
                }


                if (baseSimpleType != null && baseSimpleType.Name != null && baseSimpleType.Name.Length > 0)
                {
                    xmlBaseType = baseSimpleType.XmlBaseType;//  SimpleTypeQualifiedName;
                }
                else
                {
                    xmlBaseType = content.BaseTypeName;
                }

                if (baseType == null || baseType.Length == 0)
                {
//                    Console.WriteLine("baseType == null, setting it to ", content.BaseType.Name);
                    baseType    = content.BaseType.Name;
                    xmlBaseType = null;
                }

                if (baseType == "NOTATION")
                {
                    baseType = "string";
                }


                foreach (XmlSchemaFacet facet in content.Facets)
                {
                    if (facet is XmlSchemaLengthFacet)
                    {
                        length = Convert.ToInt32(facet.Value, null);
                    }

                    if (facet is XmlSchemaMinLengthFacet)
                    {
                        minLength = Convert.ToInt32(facet.Value, null);
                    }

                    if (facet is XmlSchemaMaxLengthFacet)
                    {
                        maxLength = Convert.ToInt32(facet.Value, null);
                    }

                    if (facet is XmlSchemaPatternFacet)
                    {
                        pattern = facet.Value;
                    }

                    if (facet is XmlSchemaEnumerationFacet)
                    {
                        enumeration = !Common.ADP.IsEmpty(enumeration) ? enumeration + " " + facet.Value : facet.Value;
                    }

                    if (facet is XmlSchemaMinExclusiveFacet)
                    {
                        minExclusive = facet.Value;
                    }

                    if (facet is XmlSchemaMinInclusiveFacet)
                    {
                        minInclusive = facet.Value;
                    }

                    if (facet is XmlSchemaMaxExclusiveFacet)
                    {
                        maxExclusive = facet.Value;
                    }

                    if (facet is XmlSchemaMaxInclusiveFacet)
                    {
                        maxInclusive = facet.Value;
                    }
                }
            }

            string tempStr = XSDSchema.GetMsdataAttribute(node, Keywords.TARGETNAMESPACE);

            if (tempStr != null)
            {
                ns = tempStr;
            }
        }
        private ClrPropertyInfo BuildComplexTypeTextProperty(XmlSchemaElement parentElement,
                                                             XmlSchemaComplexType schemaType)
        {
            Debug.Assert(schemaType != null);
            Debug.Assert(schemaType.GetContentType() == XmlSchemaContentType.TextOnly);

            ClrPropertyInfo textProperty = new ClrPropertyInfo(Constants.SInnerTypePropertyName, string.Empty,
                                                               Constants.SInnerTypePropertyName, Occurs.One);

            textProperty.Origin = SchemaOrigin.Text;
            ClrTypeReference typeRef   = null;
            bool             anonymous = false;

            //Could be derived by restriction or extension
            //If first time extension, make the base simple type as the type reference
            XmlSchemaType baseType = schemaType.BaseXmlSchemaType;

            if (baseType is XmlSchemaSimpleType)
            {
                typeRef   = BuildTypeReference(baseType, baseType.QualifiedName, false, true);
                anonymous = false;
                if (!textPropInheritanceTracker.ContainsKey(schemaType))
                {
                    textPropInheritanceTracker.Add(schemaType, textProperty);
                }
            }
            else if (schemaType.HasFacetRestrictions())
            {
                //Derived by restriction, represents the content type with restrictions as a local type
                //Make the base simple type as the type reference so that we know if it is a list, union or atomic
                XmlSchemaSimpleType st = schemaType.GetBaseSimpleType();
                Debug.Assert(st != null);
                typeRef          = BuildTypeReference(st, st.QualifiedName, true, true);
                typeRef.Validate = true;
                anonymous        = true;

                //Also get its base complex type and see if we need to override the content property
                ClrPropertyInfo baseProp = null;
                if (textPropInheritanceTracker.TryGetValue(baseType, out baseProp))
                {
                    textProperty.IsOverride = true;
                    if (!baseProp.IsOverride)
                    {
                        baseProp.IsVirtual = true;
                    }
                }
            }
            else
            {
                return(null);
            }

            if (anonymous)
            {
                //anonymous type, fixed up the name later, treat complex type with restrictions as an anonymous type
                //because we need to generate a type to encapsualte these restrictions
                if (parentElement != null)
                {
                    string identifier = localSymbolTable.AddLocalElement(parentElement);
                    localSymbolTable.AddAnonymousType(identifier, parentElement, typeRef);
                }
                else
                {
                    localSymbolTable.AddComplexRestrictedContentType(schemaType, typeRef);
                }
            }

            textProperty.TypeReference = typeRef;

            return(textProperty);
        }
        private void BuildNestedTypes(ClrContentTypeInfo typeInfo)
        {
            List <AnonymousType> anonymousTypes = localSymbolTable.GetAnonymousTypes();

            foreach (AnonymousType at in anonymousTypes)
            {
                XmlQualifiedName     qname       = null;
                XmlSchemaComplexType complexType = null;

                XmlSchemaElement elem = at.parentElement;
                if (elem == null)
                {
                    //case 1: "dummy" type for text content in a complex type, with restrictions
                    complexType = at.wrappingType;
                    qname       = complexType.QualifiedName;
                }
                else
                {
                    //case 2: anonymous type can also be nested under an element
                    qname       = elem.QualifiedName;
                    complexType = elem.ElementSchemaType as XmlSchemaComplexType;
                }

                if (complexType != null)
                {
                    if (complexType.GetContentType() == XmlSchemaContentType.TextOnly &&
                        complexType.IsDerivedByRestriction())
                    {
                        //In this case, we take care of the content/text part only. No nesting types exist.
                        ClrSimpleTypeInfo
                            nestedTypeInfo =
                            ClrSimpleTypeInfo
                            .CreateSimpleTypeInfo(
                                complexType);         //Generate its "simple type" version to save restrictions
                        nestedTypeInfo.clrtypeName = at.identifier;
                        nestedTypeInfo.clrtypeNs   = configSettings.GetClrNamespace(qname.Namespace);
                        nestedTypeInfo.schemaName  = qname.Name;
                        nestedTypeInfo.schemaNs    = qname.Namespace;
                        nestedTypeInfo.typeOrigin  = SchemaOrigin.Fragment;
                        nestedTypeInfo.IsNested    = true;
                        BuildAnnotationInformation(nestedTypeInfo, complexType);
                        typeInfo.NestedTypes.Add(nestedTypeInfo);
                    }
                    else
                    {
                        ClrContentTypeInfo nestedTypeInfo = new ClrContentTypeInfo()
                        {
                            Parent = typeInfo
                        };
                        localSymbolTable.Init(at.identifier);
                        nestedTypeInfo.clrtypeName = at.identifier;
                        nestedTypeInfo.clrtypeNs   = configSettings.GetClrNamespace(qname.Namespace);
                        nestedTypeInfo.schemaName  = qname.Name;
                        nestedTypeInfo.schemaNs    = qname.Namespace;
                        nestedTypeInfo.typeOrigin  = SchemaOrigin.Fragment;
                        nestedTypeInfo.IsNested    = true;
                        nestedTypeInfo.baseType    = BaseType(complexType);
                        BuildProperties(elem, complexType, nestedTypeInfo);
                        BuildNestedTypes(nestedTypeInfo);
                        BuildAnnotationInformation(nestedTypeInfo, complexType);
                        typeInfo.NestedTypes.Add(nestedTypeInfo);
                    }
                }

                //Also handle simple types
                XmlSchemaSimpleType simpleType = null;
                if (elem != null)
                {
                    simpleType = elem.ElementSchemaType as XmlSchemaSimpleType;
                }

                if (simpleType != null)
                {
                    ClrSimpleTypeInfo nestedTypeInfo = ClrSimpleTypeInfo.CreateSimpleTypeInfo(simpleType);
                    nestedTypeInfo.clrtypeName = at.identifier;
                    nestedTypeInfo.clrtypeNs   = configSettings.GetClrNamespace(qname.Namespace);
                    nestedTypeInfo.schemaName  = qname.Name;
                    nestedTypeInfo.schemaNs    = qname.Namespace;
                    nestedTypeInfo.typeOrigin  = SchemaOrigin.Fragment;
                    nestedTypeInfo.IsNested    = true;
                    BuildAnnotationInformation(nestedTypeInfo, simpleType);
                    typeInfo.NestedTypes.Add(nestedTypeInfo);
                }
            }
        }
Example #14
0
        public void compileFacets(XmlSchemaSimpleType simpleType)
        {
            XmlSchemaSimpleType type           = simpleType;
            XmlSchemaSimpleType enumSimpleType = null;

            this.flags = (Xml.Schema.Linq.RestrictionFlags) 0;
            while (true)
            {
                if ((type == null ? true : string.Equals(type.QualifiedName.Namespace, "http://www.w3.org/2001/XMLSchema", StringComparison.Ordinal)))
                {
                    break;
                }
                XmlSchemaSimpleTypeRestriction simpleTypeRestriction = type.Content as XmlSchemaSimpleTypeRestriction;
                if (simpleTypeRestriction != null)
                {
                    foreach (XmlSchemaFacet facet in simpleTypeRestriction.Facets)
                    {
                        if (facet is XmlSchemaMinLengthFacet)
                        {
                            if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MinLength) == 0)
                            {
                                this.minLength = XmlConvert.ToInt32(facet.Value);
                                this.flags    |= Xml.Schema.Linq.RestrictionFlags.MinLength;
                            }
                        }
                        else if (facet is XmlSchemaMaxLengthFacet)
                        {
                            if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MaxLength) == 0)
                            {
                                this.maxLength = XmlConvert.ToInt32(facet.Value);
                                this.flags    |= Xml.Schema.Linq.RestrictionFlags.MaxLength;
                            }
                        }
                        else if (facet is XmlSchemaLengthFacet)
                        {
                            if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.Length) == 0)
                            {
                                this.length = XmlConvert.ToInt32(facet.Value);
                                this.flags |= Xml.Schema.Linq.RestrictionFlags.Length;
                            }
                        }
                        else if (facet is XmlSchemaEnumerationFacet)
                        {
                            if (enumSimpleType == null)
                            {
                                this.enumerations = new ArrayList();
                                this.flags       |= Xml.Schema.Linq.RestrictionFlags.Enumeration;
                                enumSimpleType    = type;
                            }
                            else if (enumSimpleType != type)
                            {
                                continue;
                            }
                            this.enumerations.Add(type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null));
                        }
                        else if (facet is XmlSchemaPatternFacet)
                        {
                            if (this.patterns == null)
                            {
                                this.patterns = new ArrayList();
                                this.flags   |= Xml.Schema.Linq.RestrictionFlags.Pattern;
                            }
                            this.patterns.Add(facet.Value);
                        }
                        else if (facet is XmlSchemaMaxInclusiveFacet)
                        {
                            if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MaxInclusive) == 0)
                            {
                                this.maxInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                                this.flags       |= Xml.Schema.Linq.RestrictionFlags.MaxInclusive;
                            }
                        }
                        else if (facet is XmlSchemaMaxExclusiveFacet)
                        {
                            if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MaxExclusive) == 0)
                            {
                                this.maxExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                                this.flags       |= Xml.Schema.Linq.RestrictionFlags.MaxExclusive;
                            }
                        }
                        else if (facet is XmlSchemaMinExclusiveFacet)
                        {
                            if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MinExclusive) == 0)
                            {
                                this.minExclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                                this.flags       |= Xml.Schema.Linq.RestrictionFlags.MinExclusive;
                            }
                        }
                        else if (facet is XmlSchemaMinInclusiveFacet)
                        {
                            if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.MinInclusive) == 0)
                            {
                                this.minInclusive = type.BaseXmlSchemaType.Datatype.ParseValue(facet.Value, null, null);
                                this.flags       |= Xml.Schema.Linq.RestrictionFlags.MinInclusive;
                            }
                        }
                        else if (facet is XmlSchemaFractionDigitsFacet)
                        {
                            if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.FractionDigits) == 0)
                            {
                                this.fractionDigits = XmlConvert.ToInt32(facet.Value);
                                this.flags         |= Xml.Schema.Linq.RestrictionFlags.FractionDigits;
                            }
                        }
                        else if (facet is XmlSchemaTotalDigitsFacet)
                        {
                            if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.TotalDigits) == 0)
                            {
                                this.totalDigits = XmlConvert.ToInt32(facet.Value);
                                this.flags      |= Xml.Schema.Linq.RestrictionFlags.TotalDigits;
                            }
                        }
                        else if (!(facet is XmlSchemaWhiteSpaceFacet))
                        {
                            continue;
                        }
                        else if ((int)(this.flags & Xml.Schema.Linq.RestrictionFlags.WhiteSpace) == 0)
                        {
                            if (facet.Value == "preserve")
                            {
                                this.whiteSpace = Xml.Schema.Linq.XmlSchemaWhiteSpace.Preserve;
                            }
                            else if (facet.Value == "replace")
                            {
                                this.whiteSpace = Xml.Schema.Linq.XmlSchemaWhiteSpace.Replace;
                            }
                            else if (facet.Value == "collapse")
                            {
                                this.whiteSpace = Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse;
                            }
                            this.flags |= Xml.Schema.Linq.RestrictionFlags.WhiteSpace;
                        }
                    }
                }
                type = type.BaseXmlSchemaType as XmlSchemaSimpleType;
            }
        }
Example #15
0
 internal SimpleType(XmlSchemaSimpleType node)
 { // named simpletype
     _name = node.Name;
     _ns   = (node.QualifiedName != null) ? node.QualifiedName.Namespace : "";
     LoadTypeValues(node);
 }
Example #16
0
    } //WriteXmlSchemaComplexType()

    //XmlSchemaSimpleType
    public static void WriteXmlSchemaSimpleType(XmlSchemaSimpleType simpleType, 
                                                XmlTextWriter myXmlTextWriter)
    {
      myXmlTextWriter.WriteStartElement("simpleType", XmlSchema.Namespace);
      if (simpleType.Name != null)
        myXmlTextWriter.WriteAttributeString("name", simpleType.Name);

      if (simpleType.Content is XmlSchemaSimpleTypeRestriction)
        myXmlTextWriter.WriteStartElement("restriction", XmlSchema.Namespace);
      else if (simpleType.Content is XmlSchemaSimpleTypeList)
        myXmlTextWriter.WriteStartElement("list", XmlSchema.Namespace);
      else
        myXmlTextWriter.WriteStartElement("union", XmlSchema.Namespace);

      myXmlTextWriter.WriteEndElement();
      myXmlTextWriter.WriteEndElement();
    } //WriteXmlSchemaSimpleType()
Example #17
0
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

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

        simpleType.Name = "northwestStates";
        schema.Items.Add(simpleType);

        // <xs:annotation>
        XmlSchemaAnnotation annNorthwestStates = new XmlSchemaAnnotation();

        simpleType.Annotation = annNorthwestStates;

        // <xs:documentation>States in the Pacific Northwest of US</xs:documentation>
        XmlSchemaDocumentation docNorthwestStates = new XmlSchemaDocumentation();

        annNorthwestStates.Items.Add(docNorthwestStates);
        docNorthwestStates.Markup = TextToNodeArray("States in the Pacific Northwest of US");

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

        simpleType.Content       = restriction;
        restriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:enumeration value="WA">
        XmlSchemaEnumerationFacet enumerationWA = new XmlSchemaEnumerationFacet();

        restriction.Facets.Add(enumerationWA);
        enumerationWA.Value = "WA";

        // <xs:annotation>
        XmlSchemaAnnotation annWA = new XmlSchemaAnnotation();

        enumerationWA.Annotation = annWA;

        // <xs:documentation>Washington</documentation>
        XmlSchemaDocumentation docWA = new XmlSchemaDocumentation();

        annWA.Items.Add(docWA);
        docWA.Markup = TextToNodeArray("Washington");

        // <xs:enumeration value="OR">
        XmlSchemaEnumerationFacet enumerationOR = new XmlSchemaEnumerationFacet();

        restriction.Facets.Add(enumerationOR);
        enumerationOR.Value = "OR";

        // <xs:annotation>
        XmlSchemaAnnotation annOR = new XmlSchemaAnnotation();

        enumerationOR.Annotation = annOR;

        // <xs:documentation>Oregon</xs:documentation>
        XmlSchemaDocumentation docOR = new XmlSchemaDocumentation();

        annOR.Items.Add(docOR);
        docOR.Markup = TextToNodeArray("Oregon");

        // <xs:enumeration value="ID">
        XmlSchemaEnumerationFacet enumerationID = new XmlSchemaEnumerationFacet();

        restriction.Facets.Add(enumerationID);
        enumerationID.Value = "ID";

        // <xs:annotation>
        XmlSchemaAnnotation annID = new XmlSchemaAnnotation();

        enumerationID.Annotation = annID;

        // <xs:documentation>Idaho</xs:documentation>
        XmlSchemaDocumentation docID = new XmlSchemaDocumentation();

        annID.Items.Add(docID);
        docID.Markup = TextToNodeArray("Idaho");

        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);
    }
        /// <summary>
        /// Creates an XML schema element for reading a value of the given type
        /// </summary>
        /// <param name="Name">Name of the field</param>
        /// <param name="Type">Type of the field</param>
        /// <returns>New schema element representing the field</returns>
        static XmlSchemaElement CreateSchemaFieldElement(string Name, Type Type)
        {
            XmlSchemaElement Element = new XmlSchemaElement();

            Element.Name      = Name;
            Element.MinOccurs = 0;
            Element.MaxOccurs = 1;

            if (Type == typeof(string))
            {
                Element.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).QualifiedName;
            }
            else if (Type == typeof(bool) || Type == typeof(bool?))
            {
                Element.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Boolean).QualifiedName;
            }
            else if (Type == typeof(int))
            {
                Element.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Int).QualifiedName;
            }
            else if (Type == typeof(float))
            {
                Element.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Float).QualifiedName;
            }
            else if (Type == typeof(double))
            {
                Element.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Double).QualifiedName;
            }
            else if (Type == typeof(FileReference))
            {
                Element.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).QualifiedName;
            }
            else if (Type.IsEnum)
            {
                XmlSchemaSimpleTypeRestriction Restriction = new XmlSchemaSimpleTypeRestriction();
                Restriction.BaseTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).QualifiedName;

                foreach (string EnumName in Enum.GetNames(Type))
                {
                    XmlSchemaEnumerationFacet Facet = new XmlSchemaEnumerationFacet();
                    Facet.Value = EnumName;
                    Restriction.Facets.Add(Facet);
                }

                XmlSchemaSimpleType EnumType = new XmlSchemaSimpleType();
                EnumType.Content   = Restriction;
                Element.SchemaType = EnumType;
            }
            else if (Type == typeof(string[]))
            {
                XmlSchemaElement ItemElement = new XmlSchemaElement();
                ItemElement.Name            = "Item";
                ItemElement.SchemaTypeName  = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).QualifiedName;
                ItemElement.MinOccurs       = 0;
                ItemElement.MaxOccursString = "unbounded";

                XmlSchemaSequence Sequence = new XmlSchemaSequence();
                Sequence.Items.Add(ItemElement);

                XmlSchemaComplexType ArrayType = new XmlSchemaComplexType();
                ArrayType.Particle = Sequence;
                Element.SchemaType = ArrayType;
            }
            else
            {
                throw new Exception("Unsupported field type for XmlConfigFile attribute");
            }
            return(Element);
        }
        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);
            }
        }
        static XmlQualifiedName AddAttributeTypeToXmlSchema(SchemaInfo schemaInfo, UxmlAttributeDescription description, IUxmlFactory factory, FactoryProcessingHelper processingData)
        {
            if (description.name == null)
            {
                return(null);
            }

            string attrTypeName = factory.uxmlQualifiedName + "_" + description.name + "_" + k_TypeSuffix;
            string attrTypeNameInBaseElement = factory.substituteForTypeQualifiedName + "_" + description.name + "_" + k_TypeSuffix;

            FactoryProcessingHelper.AttributeRecord attrRecord;
            if (processingData.attributeTypeNames.TryGetValue(attrTypeNameInBaseElement, out attrRecord))
            {
                // If restriction != baseElement.restriction, we need to declare a new type.
                // Note: we do not support attributes having a less restrictive restriction than its base type.
                if ((description.restriction == null && attrRecord.desc.restriction == null) ||
                    (description.restriction != null && description.restriction.Equals(attrRecord.desc.restriction)))
                {
                    // Register attrTypeName -> attrRecord for potential future derived elements.
                    processingData.attributeTypeNames.Add(attrTypeName, attrRecord);
                    return(attrRecord.name);
                }
            }

            XmlQualifiedName xqn;

            FactoryProcessingHelper.AttributeRecord attributeRecord;

            if (description.restriction == null)
            {
                // Type is a built-in type.
                xqn             = new XmlQualifiedName(description.type, description.typeNamespace);
                attributeRecord = new FactoryProcessingHelper.AttributeRecord {
                    name = xqn, desc = description
                };
                processingData.attributeTypeNames.Add(attrTypeName, attributeRecord);
                return(xqn);
            }

            string attrTypeNameForSchema = factory.uxmlName + "_" + description.name + "_" + k_TypeSuffix;

            xqn = new XmlQualifiedName(attrTypeNameForSchema, schemaInfo.schema.TargetNamespace);

            XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType();

            simpleType.Name = attrTypeNameForSchema;

            UxmlEnumeration enumRestriction = description.restriction as UxmlEnumeration;

            if (enumRestriction != null)
            {
                XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
                simpleType.Content       = restriction;
                restriction.BaseTypeName = new XmlQualifiedName(description.type, description.typeNamespace);

                foreach (var v in enumRestriction.values)
                {
                    XmlSchemaEnumerationFacet enumValue = new XmlSchemaEnumerationFacet();
                    enumValue.Value = v;
                    restriction.Facets.Add(enumValue);
                }
            }
            else
            {
                UxmlValueMatches regexRestriction = description.restriction as UxmlValueMatches;
                if (regexRestriction != null)
                {
                    XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
                    simpleType.Content       = restriction;
                    restriction.BaseTypeName = new XmlQualifiedName(description.type, description.typeNamespace);

                    XmlSchemaPatternFacet pattern = new XmlSchemaPatternFacet();
                    pattern.Value = regexRestriction.regex;
                    restriction.Facets.Add(pattern);
                }
                else
                {
                    UxmlValueBounds bounds = description.restriction as UxmlValueBounds;
                    if (bounds != null)
                    {
                        XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
                        simpleType.Content       = restriction;
                        restriction.BaseTypeName = new XmlQualifiedName(description.type, description.typeNamespace);

                        XmlSchemaFacet facet;
                        if (bounds.excludeMin)
                        {
                            facet = new XmlSchemaMinExclusiveFacet();
                        }
                        else
                        {
                            facet = new XmlSchemaMinInclusiveFacet();
                        }
                        facet.Value = bounds.min;
                        restriction.Facets.Add(facet);

                        if (bounds.excludeMax)
                        {
                            facet = new XmlSchemaMaxExclusiveFacet();
                        }
                        else
                        {
                            facet = new XmlSchemaMaxInclusiveFacet();
                        }
                        facet.Value = bounds.max;
                        restriction.Facets.Add(facet);
                    }
                    else
                    {
                        Debug.Log("Unsupported restriction type.");
                    }
                }
            }

            schemaInfo.schema.Items.Add(simpleType);
            attributeRecord = new FactoryProcessingHelper.AttributeRecord {
                name = xqn, desc = description
            };
            processingData.attributeTypeNames.Add(attrTypeName, attributeRecord);
            return(xqn);
        }
Example #21
0
        private IEnumerable <RestrictionModel> GetRestrictions(IEnumerable <XmlSchemaFacet> facets, XmlSchemaSimpleType type)
        {
            var min = facets.OfType <XmlSchemaMinLengthFacet>().Select(f => int.Parse(f.Value)).DefaultIfEmpty().Max();
            var max = facets.OfType <XmlSchemaMaxLengthFacet>().Select(f => int.Parse(f.Value)).DefaultIfEmpty().Min();

            if (DataAnnotationMode == XmlSchemaClassGenerator.DataAnnotationMode.All)
            {
                if (min > 0)
                {
                    yield return(new MinLengthRestrictionModel(_configuration)
                    {
                        Value = min
                    });
                }
                if (max > 0)
                {
                    yield return(new MaxLengthRestrictionModel(_configuration)
                    {
                        Value = max
                    });
                }
            }
            else if (min > 0 || max > 0)
            {
                yield return(new MinMaxLengthRestrictionModel(_configuration)
                {
                    Min = min, Max = max
                });
            }

            foreach (var facet in facets)
            {
                if (facet is XmlSchemaTotalDigitsFacet)
                {
                    yield return(new TotalDigitsRestrictionModel(_configuration)
                    {
                        Value = int.Parse(facet.Value)
                    });
                }
                if (facet is XmlSchemaFractionDigitsFacet)
                {
                    yield return(new FractionDigitsRestrictionModel(_configuration)
                    {
                        Value = int.Parse(facet.Value)
                    });
                }

                if (facet is XmlSchemaPatternFacet)
                {
                    yield return(new PatternRestrictionModel(_configuration)
                    {
                        Value = facet.Value
                    });
                }

                var valueType = type.Datatype.ValueType;

                if (facet is XmlSchemaMinInclusiveFacet)
                {
                    yield return(new MinInclusiveRestrictionModel(_configuration)
                    {
                        Value = facet.Value, Type = valueType
                    });
                }
                if (facet is XmlSchemaMinExclusiveFacet)
                {
                    yield return(new MinExclusiveRestrictionModel(_configuration)
                    {
                        Value = facet.Value, Type = valueType
                    });
                }
                if (facet is XmlSchemaMaxInclusiveFacet)
                {
                    yield return(new MaxInclusiveRestrictionModel(_configuration)
                    {
                        Value = facet.Value, Type = valueType
                    });
                }
                if (facet is XmlSchemaMaxExclusiveFacet)
                {
                    yield return(new MaxExclusiveRestrictionModel(_configuration)
                    {
                        Value = facet.Value, Type = valueType
                    });
                }
            }
        }
Example #22
0
        private static void GetSchemaTypeRestrictions(ICollection <XmlSchemaFacet> facets, XmlSchemaSimpleType elementType)
        {
            while (elementType != null)
            {
                var restrictions = elementType.Content as XmlSchemaSimpleTypeRestriction;

                if (restrictions != null)
                {
                    foreach (var facet in restrictions.Facets.OfType <XmlSchemaFacet>().Where(facet => facets.All(x => x.GetType() != facet.GetType())))
                    {
                        facets.Add(facet);
                    }
                }

                elementType = elementType.BaseXmlSchemaType as XmlSchemaSimpleType;
            }
        }
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

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

        OrderQuantityType.Name = "OrderQuantityType";

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

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

        // <xs:minExclusive value="5"/>
        XmlSchemaMinExclusiveFacet MinExclusive = new XmlSchemaMinExclusiveFacet();

        MinExclusive.Value = "5";
        restriction.Facets.Add(MinExclusive);

        OrderQuantityType.Content = restriction;

        schema.Items.Add(OrderQuantityType);

        // <xs:element name="item">
        XmlSchemaElement element = new XmlSchemaElement();

        element.Name = "item";

        // <xs:complexType>
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();

        // <xs:attribute name="OrderQuantity" type="OrderQuantityType"/>
        XmlSchemaAttribute OrderQuantityAttribute = new XmlSchemaAttribute();

        OrderQuantityAttribute.Name           = "OrderQuantity";
        OrderQuantityAttribute.SchemaTypeName = new XmlQualifiedName("OrderQuantityType", "");
        complexType.Attributes.Add(OrderQuantityAttribute);

        element.SchemaType = complexType;

        schema.Items.Add(element);

        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);
    }
Example #24
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);
    }
        public XmlSchemaElement GetSchema()
        {
            XmlSchemaSimpleType timeUnitType = new XmlSchemaSimpleType();

            XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();

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

            XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();

            enumeration.Value = "minutes";
            restriction.Facets.Add(enumeration);

            enumeration       = new XmlSchemaEnumerationFacet();
            enumeration.Value = "hours";
            restriction.Facets.Add(enumeration);

            enumeration       = new XmlSchemaEnumerationFacet();
            enumeration.Value = "days";
            restriction.Facets.Add(enumeration);

            enumeration       = new XmlSchemaEnumerationFacet();
            enumeration.Value = "weeks";
            restriction.Facets.Add(enumeration);

            enumeration       = new XmlSchemaEnumerationFacet();
            enumeration.Value = "months";
            restriction.Facets.Add(enumeration);

            enumeration       = new XmlSchemaEnumerationFacet();
            enumeration.Value = "years";
            restriction.Facets.Add(enumeration);

            timeUnitType.Content = restriction;

            XmlSchemaSimpleType            languageType = new XmlSchemaSimpleType();
            XmlSchemaSimpleTypeRestriction languageEnum = new XmlSchemaSimpleTypeRestriction();

            languageEnum.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
            enumeration       = new XmlSchemaEnumerationFacet();
            enumeration.Value = "dicom";
            languageEnum.Facets.Add(enumeration);
            languageType.Content = languageEnum;

            XmlSchemaComplexType type = new XmlSchemaComplexType();

            XmlSchemaAttribute attrib = new XmlSchemaAttribute();

            attrib.Name           = "time";
            attrib.Use            = XmlSchemaUse.Required;
            attrib.SchemaTypeName = new XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema");
            type.Attributes.Add(attrib);

            attrib            = new XmlSchemaAttribute();
            attrib.Name       = "unit";
            attrib.Use        = XmlSchemaUse.Required;
            attrib.SchemaType = timeUnitType;
            type.Attributes.Add(attrib);

            attrib                = new XmlSchemaAttribute();
            attrib.Name           = "refValue";
            attrib.Use            = XmlSchemaUse.Optional;
            attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
            type.Attributes.Add(attrib);

            attrib            = new XmlSchemaAttribute();
            attrib.Name       = "expressionLanguage";
            attrib.Use        = XmlSchemaUse.Optional;
            attrib.SchemaType = languageType;
            type.Attributes.Add(attrib);

            XmlSchemaElement element = new XmlSchemaElement();

            element.Name       = OperatorTag;
            element.SchemaType = type;


            return(element);
        }
Example #26
0
 public TypeDesc GetTypeDesc(XmlSchemaSimpleType dataType)
 {
     return((TypeDesc)primitiveDataTypes[dataType]);
 }
Example #27
0
 public DefResponseElement(string tagName, decimal minOccurs, XmlSchemaSimpleType type) : base(tagName)
 {
     this.minOccurs = minOccurs;
     this.xmlType   = type;
 }
Example #28
0
        private string GetClassTypeFromDataType(XmlSchemaType dataType,
                                                string enclosingName,
                                                string parentName,
                                                out bool isEnum)
        {
            //System.Diagnostics.Debug.Assert( dataType.TypeCode != XmlTypeCode.AnyAtomicType );
            //System.Diagnostics.Debug.Assert( dataType.TypeCode != XmlTypeCode.AnyUri );
            Debug.Assert(dataType.TypeCode != XmlTypeCode.UntypedAtomic);


            isEnum = false;
            XmlSchemaSimpleType simpleType = dataType as XmlSchemaSimpleType;

            if (simpleType != null)
            {
                XmlSchemaSimpleTypeRestriction restriction =
                    simpleType.Content as XmlSchemaSimpleTypeRestriction;
                if (restriction != null)
                {
                    IList <DataItem> enumItems = new List <DataItem>();
                    foreach (XmlSchemaFacet facet in restriction.Facets)
                    {
                        if (facet is XmlSchemaEnumerationFacet)
                        {
                            // LOok for a facet description
                            DataItem item = new DataItem();
                            item.Name        = ((XmlSchemaEnumerationFacet)facet).Value;
                            item.Description = item.Name;
                            if (facet.Annotation != null && facet.Annotation.Items.Count == 1)
                            {
                                XmlSchemaDocumentation doc =
                                    facet.Annotation.Items[0] as XmlSchemaDocumentation;
                                if (doc != null)
                                {
                                    item.Description = doc.Markup[0].OuterXml;
                                }
                            }
                            enumItems.Add(item);
                        }
                    }
                    if (enumItems.Count > 0)
                    {
                        // TODO: Pull out common enums, such as Yes, No, Unknown types (SIF should do this in the schema)
                        Debug.Assert(!parentName.EndsWith("SchoolYearType"));
                        isEnum = true;
                        if (simpleType.Name != null)
                        {
                            enclosingName = simpleType.Name;
                        }
                        // TODO: Determine what the final algorithm should be for local element names

                        /*else
                         * {
                         *  enclosingName = parentName + enclosingName;
                         * }
                         */
                        if (enclosingName == "Type" || enclosingName == "Code" ||
                            enclosingName == "CodeType" || enclosingName == "TypeCode" ||
                            fDB.GetEnum(enclosingName) != null)
                        {
                            enclosingName = parentName + enclosingName;
                        }
                        EnumDef enumDef =
                            new EnumDef
                                (enclosingName,
                                restriction.SourceUri + ":" + restriction.LineNumber);
                        enumDef.LocalPackage = getLocalPackage(restriction.SourceUri);
                        foreach (DataItem item in enumItems)
                        {
                            if (item.Name != null)
                            {
                                enumDef.DefineValue(item.Name, item.Name, item.Description);
                            }
                        }
                        fDB.defineEnum(enclosingName, enumDef);
                        return(enclosingName);
                    }
                }
            }
            if (dataType != null)
            {
                return(dataType.TypeCode.ToString());
            }
            else
            {
                return(null);
            }
        }
Example #29
0
 /// <summary>
 /// Build the XML tag element (transform if necessary, itemVariable, OR default value)
 /// </summary>
 /// <param name="tagName"></param>
 /// <param name="minOccurs"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 private static DefResponseElement BuildDefResponseElement(string tagName, decimal minOccurs, XmlSchemaSimpleType type)
 {
     return(new DefResponseElement(tagName, minOccurs, type));
 }
Example #30
0
        /// <summary>
        /// Initializes the column from an XmlSchemaElement or XmlSchemaAttribute.
        /// </summary>
        /// <param name="xmlSchemaAnnotated">An XmlSchema object containing the attributes of the column.</param>
        private void Initialize(XmlSchemaAnnotated xmlSchemaAnnotated)
        {
            // Extract the column properties from an XmlSchemaElement.
            if (xmlSchemaAnnotated is XmlSchemaElement)
            {
                // This element is used to describe the column.
                XmlSchemaElement xmlSchemaElement = xmlSchemaAnnotated as XmlSchemaElement;

                // This information is taken directly from the known XmlSchema attributes.  The rest of the information about the
                // column needs to be extracted using unhandled attributes and element facets.
                this.name       = xmlSchemaElement.Name;
                this.isNullable = xmlSchemaElement.MinOccurs == 0.0m;

                // Extract the string that contains the type information from the 'DataType' custom attribute.  This is a
                // Microsoft extension to the XML Schema definition.
                XmlAttribute dataTypeAttribute = ObjectSchema.GetUnhandledAttribute(xmlSchemaElement, QualifiedName.DataType);
                if (dataTypeAttribute != null)
                {
                    // The type information is stored as a string.  This will rip apart the string to get the type,
                    // assembly, version, etc. information that can be used to access the type through reflection.
                    string   typeName = dataTypeAttribute.Value;
                    string[] parts    = typeName.Split(',');

                    // There's no a lot of fancy parsing going on here.  If it doesn't match the expected format, then
                    // reject the type.
                    if (parts.Length != 5)
                    {
                        throw new Exception(String.Format("Can't analyze the data type found on line {0}, {1}", xmlSchemaElement.LineNumber, typeName));
                    }

                    // This will load the assembly into memory and use reflection to get the data type that was specified
                    // in the XML file as a string.
                    string   assemblyFullName = String.Format("{0},{1},{2},{3}", parts[1], parts[2], parts[3], parts[4]);
                    Assembly assembly         = Assembly.Load(assemblyFullName);
                    if (assembly == null)
                    {
                        throw new Exception(String.Format("Unable to load the type {0} from assembly {1}", parts[0], assemblyFullName));
                    }
                    this.dataType = assembly.GetType(parts[0]);
                    if (this.dataType == null)
                    {
                        throw new Exception(String.Format("Unable to load the type {0} from assembly {1}", parts[0], assemblyFullName));
                    }
                }
                else
                {
                    // This will extract the simple data type and the maximum field length from the facets associated with the element.
                    if (xmlSchemaElement.ElementSchemaType is XmlSchemaSimpleType)
                    {
                        XmlSchemaSimpleType xmlSchemaSimpleType = xmlSchemaElement.ElementSchemaType as XmlSchemaSimpleType;
                        this.dataType = xmlSchemaSimpleType.Datatype.ValueType;
                        if (xmlSchemaSimpleType.Content is XmlSchemaSimpleTypeRestriction)
                        {
                            XmlSchemaSimpleTypeRestriction xmlSchemaSimpleTypeRestriction = xmlSchemaSimpleType.Content as XmlSchemaSimpleTypeRestriction;
                            foreach (XmlSchemaFacet xmlSchemaFacet in xmlSchemaSimpleTypeRestriction.Facets)
                            {
                                if (xmlSchemaFacet is XmlSchemaMaxLengthFacet)
                                {
                                    XmlSchemaMaxLengthFacet xmlSchemaMaxLengthFacet = xmlSchemaFacet as XmlSchemaMaxLengthFacet;
                                    this.maximumLength = Convert.ToInt32(xmlSchemaMaxLengthFacet.Value);
                                }
                            }
                        }
                    }
                }

                // The defalt value can only be evaluated after the data type has been determined.  Otherwise, there's no way to
                // know to which data type the default value is converted.
                this.defaultValue = DataModelSchema.ConvertValue(this.dataType, xmlSchemaElement.DefaultValue);
            }

            // Extract the column properties from an Attribute.
            if (xmlSchemaAnnotated is XmlSchemaAttribute)
            {
                // This attribute describes the column.
                XmlSchemaAttribute xmlSchemaAttribute = xmlSchemaAnnotated as XmlSchemaAttribute;

                // This information is taken directly from the known XmlSchema attributes.  The rest of the information about the
                // column needs to be extracted using unhandled attributes and element facets.
                this.name         = xmlSchemaAttribute.Name;
                this.dataType     = xmlSchemaAttribute.AttributeSchemaType.Datatype.ValueType;
                this.defaultValue = DataModelSchema.ConvertValue(this.dataType, xmlSchemaAttribute.DefaultValue);
            }

            // Determine the IsEncryptedColumn property.
            XmlAttribute isColumnEncrytedAttribute = ObjectSchema.GetUnhandledAttribute(xmlSchemaAnnotated,
                                                                                        QualifiedName.IsEncrypted);

            this.isEncrypted = isColumnEncrytedAttribute == null ? false : Convert.ToBoolean(isColumnEncrytedAttribute.Value);

            // Determine the IsIdentityColumn property.
            XmlAttribute autoIncrementAttribute = ObjectSchema.GetUnhandledAttribute(xmlSchemaAnnotated,
                                                                                     QualifiedName.AutoIncrement);

            this.isAutoIncrement = autoIncrementAttribute == null ? false : Convert.ToBoolean(autoIncrementAttribute.Value);

            // Determine the IsPersistent property.
            XmlAttribute isColumnPersistentAttribute = ObjectSchema.GetUnhandledAttribute(xmlSchemaAnnotated,
                                                                                          QualifiedName.IsPersistent);

            this.isPersistent = isColumnPersistentAttribute == null ? true : Convert.ToBoolean(isColumnPersistentAttribute.Value);

            // Determine the AutoIncrementSeed property.
            XmlAttribute autoIncrementSeedAttribute = ObjectSchema.GetUnhandledAttribute(xmlSchemaAnnotated,
                                                                                         QualifiedName.AutoIncrementSeed);

            this.autoIncrementSeed = autoIncrementSeedAttribute == null ? 0 : Convert.ToInt32(autoIncrementSeedAttribute.Value);

            // Determine the AutoIncrementStop property
            XmlAttribute autoIncrementStepAttribute = ObjectSchema.GetUnhandledAttribute(xmlSchemaAnnotated,
                                                                                         QualifiedName.AutoIncrementStep);

            this.autoIncrementStep = autoIncrementStepAttribute == null ? 0 : Convert.ToInt32(autoIncrementStepAttribute.Value);
        }
Example #31
0
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

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

        ZipCodeType.Name = "ZipCodeType";

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

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

        // <xs:pattern value="[0-9]{5}(-[0-9]{4})?"/>
        XmlSchemaPatternFacet pattern = new XmlSchemaPatternFacet();

        pattern.Value = "[0-9]{5}(-[0-9]{4})?";
        restriction.Facets.Add(pattern);

        ZipCodeType.Content = restriction;

        schema.Items.Add(ZipCodeType);

        // <xs:element name="Address">
        XmlSchemaElement element = new XmlSchemaElement();

        element.Name = "Address";

        // <xs:complexType>
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();

        // <xs:attribute name="ZipCode" type="ZipCodeType"/>
        XmlSchemaAttribute ZipCodeAttribute = new XmlSchemaAttribute();

        ZipCodeAttribute.Name           = "ZipCode";
        ZipCodeAttribute.SchemaTypeName = new XmlQualifiedName("ZipCodeType", "");
        complexType.Attributes.Add(ZipCodeAttribute);

        element.SchemaType = complexType;

        schema.Items.Add(element);

        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);
    }
Example #32
0
 /// <summary>
 /// Create assembly documentation for a simple type
 /// </summary>
 private static void CreateAssemblyDoc(XmlSchemaSimpleType xmlSchemaSimpleType, Type type, XmlDocument xmlDoc)
 {
     Console.WriteLine("Generating {0}...", xmlSchemaSimpleType.Name);
 }
Example #33
0
	public void DumpSimpleType (XmlSchemaSimpleType s)
	{
		depth++;

		IndentLine ("**SimpleType**");
		IndentLine ("QualifiedName: " + s.QualifiedName);
		IndentLine ("BaseSchemaType:");
		DumpType (s.BaseSchemaType);

		depth--;
	}