Represents the pattern element from XML Schema as specified by the World Wide Web Consortium (W3C). This class can be used to specify a restriction on the value entered for a simpleType element.
Inheritance: XmlSchemaFacet
        /// <summary>
        ///     Returns a simple type which extends the basic datatype and
        ///     restricts is using the string validator
        /// </summary>
        public override XmlSchemaSimpleType GetSimpleType(string attributeDataType)
        {
            var retVal = base.GetSimpleType(attributeDataType);
            var restriction = (XmlSchemaSimpleTypeRestriction) retVal.Content;

            var sva = (StringValidatorAttribute) Attribute;
            if (!string.IsNullOrEmpty(sva.InvalidCharacters))
            {
                var pFacet = new XmlSchemaPatternFacet { Value = sva.InvalidCharacters };
                // TODO: convert this to a regex that excludes the characters
                pFacet.Value = string.Format(
                    "[^{0}]*",
                    pFacet.Value
                        .Replace(@"\", @"\\")
                        .Replace(@"[", @"\[")
                        .Replace(@"]", @"\]"));

                restriction.Facets.Add(pFacet);
            }

            var minFacet = new XmlSchemaMinLengthFacet { Value = sva.MinLength.ToString() };
            restriction.Facets.Add(minFacet);

            var maxFacet = new XmlSchemaMaxLengthFacet { Value = sva.MaxLength.ToString() };
            restriction.Facets.Add(maxFacet);

            return retVal;
        }
        /// <summary>
        ///     Returns a simple type which extends the basic datatype and
        ///     restricts it using a regex pattern
        /// </summary>
        public override XmlSchemaSimpleType GetSimpleType(string attributeDataType)
        {
            var retVal = base.GetSimpleType(attributeDataType);
            var restriction = (XmlSchemaSimpleTypeRestriction) retVal.Content;

            var rxa = (RegexStringValidatorAttribute) Attribute;
            var pFacet = new XmlSchemaPatternFacet { Value = rxa.Regex };
            restriction.Facets.Add(pFacet);

            return retVal;
        }
Example #3
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction) {
     firstPattern = true;
     regStr = null;
     pattern_facet = null;
     datatype = baseDatatype;
     derivedRestriction = restriction;
     baseFlags = datatype.Restriction != null ? datatype.Restriction.Flags : 0;
     baseFixedFlags = datatype.Restriction != null ? datatype.Restriction.FixedFlags : 0;
     validRestrictionFlags = datatype.ValidRestrictionFlags;
     nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     builtInEnum = !(datatype is Datatype_union || datatype is Datatype_List) ? datatype.TypeCode : 0;
     builtInType = (int)builtInEnum > 0 ? DatatypeImplementation.GetSimpleTypeFromTypeCode(builtInEnum).Datatype : datatype;
 }
Example #4
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     this.firstPattern          = true;
     this.regStr                = null;
     this.pattern_facet         = null;
     this.datatype              = baseDatatype;
     this.derivedRestriction    = restriction;
     this.baseFlags             = (this.datatype.Restriction != null) ? this.datatype.Restriction.Flags : ((RestrictionFlags)0);
     this.baseFixedFlags        = (this.datatype.Restriction != null) ? this.datatype.Restriction.FixedFlags : ((RestrictionFlags)0);
     this.validRestrictionFlags = this.datatype.ValidRestrictionFlags;
     this.nonNegativeInt        = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     this.builtInEnum           = (!(this.datatype is Datatype_union) && !(this.datatype is Datatype_List)) ? this.datatype.TypeCode : XmlTypeCode.None;
     this.builtInType           = (this.builtInEnum > XmlTypeCode.None) ? DatatypeImplementation.GetSimpleTypeFromTypeCode(this.builtInEnum).Datatype : this.datatype;
 }
Example #5
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     _firstPattern = true;
     _regStr = null;
     _pattern_facet = null;
     _datatype = baseDatatype;
     _derivedRestriction = restriction;
     _baseFlags = _datatype.Restriction != null ? _datatype.Restriction.Flags : 0;
     _baseFixedFlags = _datatype.Restriction != null ? _datatype.Restriction.FixedFlags : 0;
     _validRestrictionFlags = _datatype.ValidRestrictionFlags;
     _nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     _builtInEnum = !(_datatype is Datatype_union || _datatype is Datatype_List) ? _datatype.TypeCode : 0;
     _builtInType = (int)_builtInEnum > 0 ? DatatypeImplementation.GetSimpleTypeFromTypeCode(_builtInEnum).Datatype : _datatype;
 }
Example #6
0
 internal void CompilePatternFacet(XmlSchemaPatternFacet facet)
 {
     this.CheckProhibitedFlag(facet, RestrictionFlags.Pattern, "Sch_PatternFacetProhibited");
     if (this.firstPattern)
     {
         this.regStr = new StringBuilder();
         this.regStr.Append("(");
         this.regStr.Append(facet.Value);
         this.pattern_facet = facet;
         this.firstPattern  = false;
     }
     else
     {
         this.regStr.Append(")|(");
         this.regStr.Append(facet.Value);
     }
     this.SetFlag(facet, RestrictionFlags.Pattern);
 }
Example #7
0
		public TypeData (Type type, string elementName, bool isPrimitive, TypeData mappedType, XmlSchemaPatternFacet facet)
		{
#if NET_2_0
			if (type.IsGenericTypeDefinition)
				throw new InvalidOperationException ("Generic type definition cannot be used in serialization. Only specific generic types can be used.");
#endif
			this.mappedType = mappedType;
			this.facet = facet;
			this.type = type;
			this.typeName = type.Name;
			this.fullTypeName = type.FullName.Replace ('+', '.');

			if (isPrimitive)
				sType = SchemaTypes.Primitive;
			else
			{
				if (type.IsEnum)
					sType = SchemaTypes.Enum;
				else if (typeof(IXmlSerializable).IsAssignableFrom (type))
					sType = SchemaTypes.XmlSerializable;
				else if (typeof (System.Xml.XmlNode).IsAssignableFrom (type))
					sType = SchemaTypes.XmlNode;
				else if (type.IsArray || typeof(IEnumerable).IsAssignableFrom (type))
					sType = SchemaTypes.Array;
				else
					sType = SchemaTypes.Class;
			}
			
			if (IsListType)
				this.elementName = TypeTranslator.GetArrayName (ListItemTypeData.XmlType);
			else
				this.elementName = elementName;

			if (sType == SchemaTypes.Array || sType == SchemaTypes.Class) {
				hasPublicConstructor = !type.IsInterface && (type.IsArray || type.GetConstructor (Type.EmptyTypes) != null || type.IsAbstract || type.IsValueType);
			}
		}
 static TypeScope()
 {
     AddPrimitive(typeof(string), "string", "String", TypeFlags.HasDefaultConstructor | TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.CanBeAttributeValue | TypeFlags.Reference);
     AddPrimitive(typeof(int), "int", "Int32", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(bool), "boolean", "Boolean", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(short), "short", "Int16", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(long), "long", "Int64", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(float), "float", "Single", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(double), "double", "Double", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(decimal), "decimal", "Decimal", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(DateTime), "dateTime", "DateTime", TypeFlags.XmlEncodingNotRequired | TypeFlags.HasCustomFormatter | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(XmlQualifiedName), "QName", "XmlQualifiedName", TypeFlags.XmlEncodingNotRequired | TypeFlags.HasIsEmpty | TypeFlags.HasCustomFormatter | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue | TypeFlags.Reference);
     AddPrimitive(typeof(byte), "unsignedByte", "Byte", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(sbyte), "byte", "SByte", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(ushort), "unsignedShort", "UInt16", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(uint), "unsignedInt", "UInt32", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(ulong), "unsignedLong", "UInt64", TypeFlags.XmlEncodingNotRequired | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(DateTime), "date", "Date", TypeFlags.XmlEncodingNotRequired | TypeFlags.AmbiguousDataType | TypeFlags.HasCustomFormatter | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(DateTime), "time", "Time", TypeFlags.XmlEncodingNotRequired | TypeFlags.AmbiguousDataType | TypeFlags.HasCustomFormatter | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddPrimitive(typeof(string), "Name", "XmlName", TypeFlags.AmbiguousDataType | TypeFlags.HasCustomFormatter | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue | TypeFlags.Reference);
     AddPrimitive(typeof(string), "NCName", "XmlNCName", TypeFlags.AmbiguousDataType | TypeFlags.HasCustomFormatter | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue | TypeFlags.Reference);
     AddPrimitive(typeof(string), "NMTOKEN", "XmlNmToken", TypeFlags.AmbiguousDataType | TypeFlags.HasCustomFormatter | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue | TypeFlags.Reference);
     AddPrimitive(typeof(string), "NMTOKENS", "XmlNmTokens", TypeFlags.AmbiguousDataType | TypeFlags.HasCustomFormatter | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue | TypeFlags.Reference);
     AddPrimitive(typeof(byte[]), "base64Binary", "ByteArrayBase64", TypeFlags.XmlEncodingNotRequired | TypeFlags.HasDefaultConstructor | TypeFlags.IgnoreDefault | TypeFlags.AmbiguousDataType | TypeFlags.HasCustomFormatter | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue | TypeFlags.Reference);
     AddPrimitive(typeof(byte[]), "hexBinary", "ByteArrayHex", TypeFlags.XmlEncodingNotRequired | TypeFlags.HasDefaultConstructor | TypeFlags.IgnoreDefault | TypeFlags.AmbiguousDataType | TypeFlags.HasCustomFormatter | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue | TypeFlags.Reference);
     XmlSchemaPatternFacet facet = new XmlSchemaPatternFacet {
         Value = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
     };
     AddNonXsdPrimitive(typeof(Guid), "guid", "http://microsoft.com/wsdl/types/", "Guid", new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"), new XmlSchemaFacet[] { facet }, TypeFlags.XmlEncodingNotRequired | TypeFlags.IgnoreDefault | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddNonXsdPrimitive(typeof(char), "char", "http://microsoft.com/wsdl/types/", "Char", new XmlQualifiedName("unsignedShort", "http://www.w3.org/2001/XMLSchema"), new XmlSchemaFacet[0], TypeFlags.IgnoreDefault | TypeFlags.HasCustomFormatter | TypeFlags.CanBeElementValue | TypeFlags.CanBeAttributeValue);
     AddSoapEncodedTypes("http://schemas.xmlsoap.org/soap/encoding/");
     AddPrimitive(typeof(string), "normalizedString", "String", TypeFlags.HasDefaultConstructor | TypeFlags.AmbiguousDataType | TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.CanBeAttributeValue | TypeFlags.Reference);
     for (int i = 0; i < unsupportedTypes.Length; i++)
     {
         AddPrimitive(typeof(string), unsupportedTypes[i], "String", TypeFlags.CollapseWhitespace | TypeFlags.AmbiguousDataType | TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.CanBeAttributeValue | TypeFlags.Reference);
     }
 }
Example #9
0
        static TypeScope() {
            AddPrimitive(typeof(string), "string", "String", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.Reference | TypeFlags.HasDefaultConstructor);
            AddPrimitive(typeof(int), "int", "Int32", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(bool), "boolean", "Boolean", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(short), "short", "Int16", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(long), "long", "Int64", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(float), "float", "Single", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(double), "double", "Double", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(decimal), "decimal", "Decimal", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(DateTime), "dateTime", "DateTime", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(XmlQualifiedName), "QName", "XmlQualifiedName", TypeFlags.CanBeAttributeValue | TypeFlags.HasCustomFormatter | TypeFlags.HasIsEmpty | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired | TypeFlags.Reference);
            AddPrimitive(typeof(byte), "unsignedByte", "Byte", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(SByte), "byte", "SByte", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(UInt16), "unsignedShort", "UInt16", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(UInt32), "unsignedInt", "UInt32", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(UInt64), "unsignedLong", "UInt64", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);

            // Types without direct mapping (ambigous)
            AddPrimitive(typeof(DateTime), "date", "Date", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(DateTime), "time", "Time", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.XmlEncodingNotRequired);

            AddPrimitive(typeof(string), "Name", "XmlName", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference);
            AddPrimitive(typeof(string), "NCName", "XmlNCName", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference);
            AddPrimitive(typeof(string), "NMTOKEN", "XmlNmToken", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference);
            AddPrimitive(typeof(string), "NMTOKENS", "XmlNmTokens", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference);

            AddPrimitive(typeof(byte[]), "base64Binary", "ByteArrayBase64", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference | TypeFlags.IgnoreDefault | TypeFlags.XmlEncodingNotRequired | TypeFlags.HasDefaultConstructor);
            AddPrimitive(typeof(byte[]), "hexBinary", "ByteArrayHex", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference | TypeFlags.IgnoreDefault | TypeFlags.XmlEncodingNotRequired | TypeFlags.HasDefaultConstructor);
            // NOTE, [....]: byte[] can also be used to mean array of bytes. That datatype is not a primitive, so we
            // can't use the AmbiguousDataType mechanism. To get an array of bytes in literal XML, apply [XmlArray] or
            // [XmlArrayItem].

            XmlSchemaPatternFacet guidPattern = new XmlSchemaPatternFacet();
            guidPattern.Value = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";

            AddNonXsdPrimitive(typeof(Guid), "guid", UrtTypes.Namespace, "Guid", new XmlQualifiedName("string", XmlSchema.Namespace), new XmlSchemaFacet[] { guidPattern }, TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired | TypeFlags.IgnoreDefault);
            AddNonXsdPrimitive(typeof(char), "char", UrtTypes.Namespace, "Char", new XmlQualifiedName("unsignedShort", XmlSchema.Namespace), new XmlSchemaFacet[0], TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.IgnoreDefault);

            AddSoapEncodedTypes(Soap.Encoding);

            // Unsuppoted types that we map to string, if in the future we decide 
            // to add support for them we would need to create custom formatters for them
            // normalizedString is the only one unsuported type that suppose to preserve whitesapce
            AddPrimitive(typeof(string), "normalizedString", "String", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.Reference | TypeFlags.HasDefaultConstructor);
            for (int i = 0; i < unsupportedTypes.Length; i++) {
                AddPrimitive(typeof(string), unsupportedTypes[i], "String", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.Reference | TypeFlags.CollapseWhitespace);
            }
        }
Example #10
0
		static TypeTranslator ()
		{
			nameCache = new Hashtable ();
			primitiveArrayTypes = Hashtable.Synchronized (new Hashtable ());

#if !TARGET_JVM
			nameCache = Hashtable.Synchronized (nameCache);
#endif
			// XSD Types with direct map to CLR types

			nameCache.Add (typeof (bool), new TypeData (typeof (bool), "boolean", true));
			nameCache.Add (typeof (short), new TypeData (typeof (short), "short", true));
			nameCache.Add (typeof (ushort), new TypeData (typeof (ushort), "unsignedShort", true));
			nameCache.Add (typeof (int), new TypeData (typeof (int), "int", true));
			nameCache.Add (typeof (uint), new TypeData (typeof (uint), "unsignedInt", true));
			nameCache.Add (typeof (long), new TypeData (typeof (long), "long", true));
			nameCache.Add (typeof (ulong), new TypeData (typeof (ulong), "unsignedLong", true));
			nameCache.Add (typeof (float), new TypeData (typeof (float), "float", true));
			nameCache.Add (typeof (double), new TypeData (typeof (double), "double", true));
			nameCache.Add (typeof (DateTime), new TypeData (typeof (DateTime), "dateTime", true));	// TODO: timeInstant, Xml date, xml time
			nameCache.Add (typeof (decimal), new TypeData (typeof (decimal), "decimal", true));
			nameCache.Add (typeof (XmlQualifiedName), new TypeData (typeof (XmlQualifiedName), "QName", true));
			nameCache.Add (typeof (string), new TypeData (typeof (string), "string", true));
#if !MOONLIGHT
			XmlSchemaPatternFacet guidFacet = new XmlSchemaPatternFacet();
			guidFacet.Value = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
			nameCache.Add (typeof (Guid), new TypeData (typeof (Guid), "guid", true, (TypeData)nameCache[typeof (string)], guidFacet));
#endif
			nameCache.Add (typeof (byte), new TypeData (typeof (byte), "unsignedByte", true));
			nameCache.Add (typeof (sbyte), new TypeData (typeof (sbyte), "byte", true));
			nameCache.Add (typeof (char), new TypeData (typeof (char), "char", true, (TypeData)nameCache[typeof (ushort)], null));
			nameCache.Add (typeof (object), new TypeData (typeof (object), "anyType", false));
			nameCache.Add (typeof (byte[]), new TypeData (typeof (byte[]), "base64Binary", true));
#if !MOONLIGHT
			nameCache.Add (typeof (XmlNode), new TypeData (typeof (XmlNode), "XmlNode", false));
			nameCache.Add (typeof (XmlElement), new TypeData (typeof (XmlElement), "XmlElement", false));
#endif

			primitiveTypes = new Hashtable();
			ICollection types = nameCache.Values;
			foreach (TypeData td in types)
				primitiveTypes.Add (td.XmlType, td);

			// Additional XSD types

			primitiveTypes.Add ("date", new TypeData (typeof (DateTime), "date", true));	// TODO: timeInstant
			primitiveTypes.Add ("time", new TypeData (typeof (DateTime), "time", true));
			primitiveTypes.Add ("timePeriod", new TypeData (typeof (DateTime), "timePeriod", true));
			primitiveTypes.Add ("gDay", new TypeData (typeof (string), "gDay", true));
			primitiveTypes.Add ("gMonthDay", new TypeData (typeof (string), "gMonthDay", true));
			primitiveTypes.Add ("gYear", new TypeData (typeof (string), "gYear", true));
			primitiveTypes.Add ("gYearMonth", new TypeData (typeof (string), "gYearMonth", true));
			primitiveTypes.Add ("month", new TypeData (typeof (DateTime), "month", true));
			primitiveTypes.Add ("NMTOKEN", new TypeData (typeof (string), "NMTOKEN", true));
			primitiveTypes.Add ("NMTOKENS", new TypeData (typeof (string), "NMTOKENS", true));
			primitiveTypes.Add ("Name", new TypeData (typeof (string), "Name", true));
			primitiveTypes.Add ("NCName", new TypeData (typeof (string), "NCName", true));
			primitiveTypes.Add ("language", new TypeData (typeof (string), "language", true));
			primitiveTypes.Add ("integer", new TypeData (typeof (string), "integer", true));
			primitiveTypes.Add ("positiveInteger", new TypeData (typeof (string), "positiveInteger", true));
			primitiveTypes.Add ("nonPositiveInteger", new TypeData (typeof (string), "nonPositiveInteger", true));
			primitiveTypes.Add ("negativeInteger", new TypeData (typeof (string), "negativeInteger", true));
			primitiveTypes.Add ("nonNegativeInteger", new TypeData (typeof (string), "nonNegativeInteger", true));
			primitiveTypes.Add ("ENTITIES", new TypeData (typeof (string), "ENTITIES", true));
			primitiveTypes.Add ("ENTITY", new TypeData (typeof (string), "ENTITY", true));
			primitiveTypes.Add ("hexBinary", new TypeData (typeof (byte[]), "hexBinary", true));
			primitiveTypes.Add ("ID", new TypeData (typeof (string), "ID", true));
			primitiveTypes.Add ("IDREF", new TypeData (typeof (string), "IDREF", true));
			primitiveTypes.Add ("IDREFS", new TypeData (typeof (string), "IDREFS", true));
			primitiveTypes.Add ("NOTATION", new TypeData (typeof (string), "NOTATION", true));
			primitiveTypes.Add ("token", new TypeData (typeof (string), "token", true));
			primitiveTypes.Add ("normalizedString", new TypeData (typeof (string), "normalizedString", true));
			primitiveTypes.Add ("anyURI", new TypeData (typeof (string), "anyURI", true));
			primitiveTypes.Add ("base64", new TypeData (typeof (byte[]), "base64", true));
			primitiveTypes.Add ("duration", new TypeData (typeof (string), "duration", true));

#if NET_2_0
			nullableTypes = Hashtable.Synchronized(new Hashtable ());
			foreach (DictionaryEntry de in primitiveTypes) {
				TypeData td = (TypeData) de.Value;
				TypeData ntd = new TypeData (td.Type, td.XmlType, true);
				ntd.IsNullable = true;
				nullableTypes.Add (de.Key, ntd);
			}
#endif
		}
        internal static XmlSchemaSimpleContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContentRestriction xmlSchemaSimpleContentRestriction = new XmlSchemaSimpleContentRestriction();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "restriction")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }
            xmlSchemaSimpleContentRestriction.LineNumber   = reader.LineNumber;
            xmlSchemaSimpleContentRestriction.LinePosition = reader.LinePosition;
            xmlSchemaSimpleContentRestriction.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception ex;
                    xmlSchemaSimpleContentRestriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out ex);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for base attribute", ex);
                    }
                }
                else if (reader.Name == "id")
                {
                    xmlSchemaSimpleContentRestriction.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for restriction", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaSimpleContentRestriction);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaSimpleContentRestriction);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "restriction")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaSimpleContentRestriction.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaSimpleContentRestriction.Annotation = xmlSchemaAnnotation;
                    }
                }
                else if (num <= 2 && reader.LocalName == "simpleType")
                {
                    num = 3;
                    XmlSchemaSimpleType xmlSchemaSimpleType = XmlSchemaSimpleType.Read(reader, h);
                    if (xmlSchemaSimpleType != null)
                    {
                        xmlSchemaSimpleContentRestriction.baseType = xmlSchemaSimpleType;
                    }
                }
                else
                {
                    if (num <= 3)
                    {
                        if (reader.LocalName == "minExclusive")
                        {
                            num = 3;
                            XmlSchemaMinExclusiveFacet xmlSchemaMinExclusiveFacet = XmlSchemaMinExclusiveFacet.Read(reader, h);
                            if (xmlSchemaMinExclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMinExclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "minInclusive")
                        {
                            num = 3;
                            XmlSchemaMinInclusiveFacet xmlSchemaMinInclusiveFacet = XmlSchemaMinInclusiveFacet.Read(reader, h);
                            if (xmlSchemaMinInclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMinInclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "maxExclusive")
                        {
                            num = 3;
                            XmlSchemaMaxExclusiveFacet xmlSchemaMaxExclusiveFacet = XmlSchemaMaxExclusiveFacet.Read(reader, h);
                            if (xmlSchemaMaxExclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMaxExclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "maxInclusive")
                        {
                            num = 3;
                            XmlSchemaMaxInclusiveFacet xmlSchemaMaxInclusiveFacet = XmlSchemaMaxInclusiveFacet.Read(reader, h);
                            if (xmlSchemaMaxInclusiveFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMaxInclusiveFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "totalDigits")
                        {
                            num = 3;
                            XmlSchemaTotalDigitsFacet xmlSchemaTotalDigitsFacet = XmlSchemaTotalDigitsFacet.Read(reader, h);
                            if (xmlSchemaTotalDigitsFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaTotalDigitsFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "fractionDigits")
                        {
                            num = 3;
                            XmlSchemaFractionDigitsFacet xmlSchemaFractionDigitsFacet = XmlSchemaFractionDigitsFacet.Read(reader, h);
                            if (xmlSchemaFractionDigitsFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaFractionDigitsFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "length")
                        {
                            num = 3;
                            XmlSchemaLengthFacet xmlSchemaLengthFacet = XmlSchemaLengthFacet.Read(reader, h);
                            if (xmlSchemaLengthFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaLengthFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "minLength")
                        {
                            num = 3;
                            XmlSchemaMinLengthFacet xmlSchemaMinLengthFacet = XmlSchemaMinLengthFacet.Read(reader, h);
                            if (xmlSchemaMinLengthFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMinLengthFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "maxLength")
                        {
                            num = 3;
                            XmlSchemaMaxLengthFacet xmlSchemaMaxLengthFacet = XmlSchemaMaxLengthFacet.Read(reader, h);
                            if (xmlSchemaMaxLengthFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaMaxLengthFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "enumeration")
                        {
                            num = 3;
                            XmlSchemaEnumerationFacet xmlSchemaEnumerationFacet = XmlSchemaEnumerationFacet.Read(reader, h);
                            if (xmlSchemaEnumerationFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaEnumerationFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "whiteSpace")
                        {
                            num = 3;
                            XmlSchemaWhiteSpaceFacet xmlSchemaWhiteSpaceFacet = XmlSchemaWhiteSpaceFacet.Read(reader, h);
                            if (xmlSchemaWhiteSpaceFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaWhiteSpaceFacet);
                            }
                            continue;
                        }
                        if (reader.LocalName == "pattern")
                        {
                            num = 3;
                            XmlSchemaPatternFacet xmlSchemaPatternFacet = XmlSchemaPatternFacet.Read(reader, h);
                            if (xmlSchemaPatternFacet != null)
                            {
                                xmlSchemaSimpleContentRestriction.facets.Add(xmlSchemaPatternFacet);
                            }
                            continue;
                        }
                    }
                    if (num <= 4)
                    {
                        if (reader.LocalName == "attribute")
                        {
                            num = 4;
                            XmlSchemaAttribute xmlSchemaAttribute = XmlSchemaAttribute.Read(reader, h);
                            if (xmlSchemaAttribute != null)
                            {
                                xmlSchemaSimpleContentRestriction.Attributes.Add(xmlSchemaAttribute);
                            }
                            continue;
                        }
                        if (reader.LocalName == "attributeGroup")
                        {
                            num = 4;
                            XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = XmlSchemaAttributeGroupRef.Read(reader, h);
                            if (xmlSchemaAttributeGroupRef != null)
                            {
                                xmlSchemaSimpleContentRestriction.attributes.Add(xmlSchemaAttributeGroupRef);
                            }
                            continue;
                        }
                    }
                    if (num <= 5 && reader.LocalName == "anyAttribute")
                    {
                        num = 6;
                        XmlSchemaAnyAttribute xmlSchemaAnyAttribute = XmlSchemaAnyAttribute.Read(reader, h);
                        if (xmlSchemaAnyAttribute != null)
                        {
                            xmlSchemaSimpleContentRestriction.AnyAttribute = xmlSchemaAnyAttribute;
                        }
                    }
                    else
                    {
                        reader.RaiseInvalidElementError();
                    }
                }
            }
            return(xmlSchemaSimpleContentRestriction);
        }
Example #12
0
		/// <summary>
		/// Creates a simple type that matches a regex
		/// </summary>
		/// <param name="Name">Name of the new type</param>
		/// <param name="Pattern">Regex pattern to match</param>
		/// <returns>A simple type which will match the given pattern</returns>
		static XmlSchemaSimpleType CreateSimpleTypeFromRegex(string Name, string Pattern)
		{
			XmlSchemaPatternFacet PatternFacet = new XmlSchemaPatternFacet();
			PatternFacet.Value = Pattern;

			XmlSchemaSimpleTypeRestriction Restriction = new XmlSchemaSimpleTypeRestriction();
			Restriction.BaseTypeName = StringTypeName;
			Restriction.Facets.Add(PatternFacet);

			XmlSchemaSimpleType SimpleType = new XmlSchemaSimpleType();
			SimpleType.Name = Name;
			SimpleType.Content = Restriction;
			return SimpleType;
		}
        //<restriction
        //base = QName
        //id = ID
        //{any attributes with non-schema namespace . . .}>
        //Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))
        //</restriction>
        internal static XmlSchemaSimpleContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContentRestriction restriction = new XmlSchemaSimpleContentRestriction();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            restriction.LineNumber   = reader.LineNumber;
            restriction.LinePosition = reader.LinePosition;
            restriction.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception innerex;
                    restriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for base attribute", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    restriction.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for restriction", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, restriction);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(restriction);
            }

            //Content:  1.annotation?,
            //		    2.simpleType?,
            //			3.(minExclusive |...| enumeration | whiteSpace | pattern)*,
            //			4.(attribute | attributeGroup)*,
            //			5.anyAttribute?
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleContentRestriction.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2; //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        restriction.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "simpleType")
                {
                    level = 3;
                    XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h);
                    if (stype != null)
                    {
                        restriction.baseType = stype;
                    }
                    continue;
                }
                if (level <= 3)
                {
                    if (reader.LocalName == "minExclusive")
                    {
                        level = 3;
                        XmlSchemaMinExclusiveFacet minex = XmlSchemaMinExclusiveFacet.Read(reader, h);
                        if (minex != null)
                        {
                            restriction.facets.Add(minex);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "minInclusive")
                    {
                        level = 3;
                        XmlSchemaMinInclusiveFacet mini = XmlSchemaMinInclusiveFacet.Read(reader, h);
                        if (mini != null)
                        {
                            restriction.facets.Add(mini);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "maxExclusive")
                    {
                        level = 3;
                        XmlSchemaMaxExclusiveFacet maxex = XmlSchemaMaxExclusiveFacet.Read(reader, h);
                        if (maxex != null)
                        {
                            restriction.facets.Add(maxex);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "maxInclusive")
                    {
                        level = 3;
                        XmlSchemaMaxInclusiveFacet maxi = XmlSchemaMaxInclusiveFacet.Read(reader, h);
                        if (maxi != null)
                        {
                            restriction.facets.Add(maxi);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "totalDigits")
                    {
                        level = 3;
                        XmlSchemaTotalDigitsFacet total = XmlSchemaTotalDigitsFacet.Read(reader, h);
                        if (total != null)
                        {
                            restriction.facets.Add(total);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "fractionDigits")
                    {
                        level = 3;
                        XmlSchemaFractionDigitsFacet fraction = XmlSchemaFractionDigitsFacet.Read(reader, h);
                        if (fraction != null)
                        {
                            restriction.facets.Add(fraction);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "length")
                    {
                        level = 3;
                        XmlSchemaLengthFacet length = XmlSchemaLengthFacet.Read(reader, h);
                        if (length != null)
                        {
                            restriction.facets.Add(length);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "minLength")
                    {
                        level = 3;
                        XmlSchemaMinLengthFacet minlen = XmlSchemaMinLengthFacet.Read(reader, h);
                        if (minlen != null)
                        {
                            restriction.facets.Add(minlen);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "maxLength")
                    {
                        level = 3;
                        XmlSchemaMaxLengthFacet maxlen = XmlSchemaMaxLengthFacet.Read(reader, h);
                        if (maxlen != null)
                        {
                            restriction.facets.Add(maxlen);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "enumeration")
                    {
                        level = 3;
                        XmlSchemaEnumerationFacet enumeration = XmlSchemaEnumerationFacet.Read(reader, h);
                        if (enumeration != null)
                        {
                            restriction.facets.Add(enumeration);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "whiteSpace")
                    {
                        level = 3;
                        XmlSchemaWhiteSpaceFacet ws = XmlSchemaWhiteSpaceFacet.Read(reader, h);
                        if (ws != null)
                        {
                            restriction.facets.Add(ws);
                        }
                        continue;
                    }
                    else if (reader.LocalName == "pattern")
                    {
                        level = 3;
                        XmlSchemaPatternFacet pattern = XmlSchemaPatternFacet.Read(reader, h);
                        if (pattern != null)
                        {
                            restriction.facets.Add(pattern);
                        }
                        continue;
                    }
                }
                if (level <= 4)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 4;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 4;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 5 && reader.LocalName == "anyAttribute")
                {
                    level = 6;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        restriction.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(restriction);
        }
 protected override void Visit(XmlSchemaPatternFacet facet)
 {
     AddLeaf(SimpleTypeStructureNodeType.FacetPattern, facet);
 }
Example #15
0
        private RestrictionFacets ConstructRestriction(XmlSchemaObjectCollection facets, XmlNameTable nameTable) {
            RestrictionFacets restriction = new RestrictionFacets();
            RestrictionFlags thisFlags = this.restriction != null ? this.restriction.Flags : 0;
            RestrictionFlags fixedFlags = this.restriction != null ? this.restriction.FixedFlags : 0;
            RestrictionFlags validRestrictionFlags = ValidRestrictionFlags;
            if (variety == XmlSchemaDatatypeVariety.List) {
                validRestrictionFlags = RestrictionFlags.Length|RestrictionFlags.MinLength|RestrictionFlags.MaxLength|RestrictionFlags.Enumeration|RestrictionFlags.WhiteSpace;
                if (minListSize == 0) {
                    validRestrictionFlags |= RestrictionFlags.Pattern;
                }
            }
            StringBuilder regStr = new StringBuilder();
            XmlSchemaFacet pattern_facet = null;
            bool firstP = true;

            foreach (XmlSchemaFacet facet in facets) {
                if (facet.Value == null) {
                    throw new XmlSchemaException(Res.Sch_InvalidFacet, facet);
                }
                XmlNamespaceManager nsmgr = new SchemaNamespaceManager(facet);
                if (facet is XmlSchemaLengthFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.Length);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.Length, Res.Sch_LengthFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.Length, Res.Sch_DupLengthFacet);
                    try {
                        restriction.Length = (int)(decimal)c_nonNegativeInteger.ParseAtomicValue(facet.Value, null, null);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_LengthFacetInvalid, e.Message, facet);
                    }
                    if ((thisFlags & RestrictionFlags.Length) != 0) {
                        if (this.restriction.Length < restriction.Length) {
                            throw new XmlSchemaException(Res.Sch_LengthGtBaseLength, facet);
                        }
                    }
                    SetFlag(restriction, facet, RestrictionFlags.Length);
                }
                else if (facet is XmlSchemaMinLengthFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.MinLength);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MinLength, Res.Sch_MinLengthFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MinLength, Res.Sch_DupMinLengthFacet);
                    try {
                        restriction.MinLength = (int)(decimal)c_nonNegativeInteger.ParseAtomicValue(facet.Value, null, null);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MinLengthFacetInvalid, e.Message, facet);
                    }
                    if ((thisFlags & RestrictionFlags.MinLength) != 0) {
                        if (this.restriction.MinLength > restriction.MinLength) {
                            throw new XmlSchemaException(Res.Sch_MinLengthGtBaseMinLength, facet);
                        }
                    }
                    SetFlag(restriction, facet, RestrictionFlags.MinLength);
                }
                else if (facet is XmlSchemaMaxLengthFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.MaxLength);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MaxLength, Res.Sch_MaxLengthFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MaxLength, Res.Sch_DupMaxLengthFacet);
                    try {
                        restriction.MaxLength = (int)(decimal)c_nonNegativeInteger.ParseAtomicValue(facet.Value, null, null);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MaxLengthFacetInvalid, e.Message, facet);
                    }
                    if ((thisFlags & RestrictionFlags.MaxLength) != 0) {
                        if (this.restriction.MaxLength < restriction.MaxLength) {
                            throw new XmlSchemaException(Res.Sch_MaxLengthGtBaseMaxLength, facet);
                        }
                    }
                    SetFlag(restriction, facet, RestrictionFlags.MaxLength);
                }
                else if (facet is XmlSchemaPatternFacet) {
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.Pattern, Res.Sch_PatternFacetProhibited);
                    if(firstP == true) {
                        regStr.Append("(");
                        regStr.Append(facet.Value);
                        pattern_facet = new XmlSchemaPatternFacet();
                        pattern_facet = facet;
                        firstP = false;
                    }
                    else {
                        regStr.Append(")|(");
                        regStr.Append(facet.Value);
                    }
                    SetFlag(restriction, facet, RestrictionFlags.Pattern);
                }
                else if (facet is XmlSchemaEnumerationFacet) {
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.Enumeration, Res.Sch_EnumerationFacetProhibited);
                    if (restriction.Enumeration == null) {
                        restriction.Enumeration = new ArrayList();
                    }
                    try {
                        //restriction.Enumeration.Add(ParseAtomicValue(facet.Value, nameTable, nsmgr));
                        restriction.Enumeration.Add(ParseValue(facet.Value, nameTable, nsmgr));
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_EnumerationFacetInvalid, e.Message, facet);
                    }
                    SetFlag(restriction, facet, RestrictionFlags.Enumeration);
                }
                else if (facet is XmlSchemaWhiteSpaceFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.WhiteSpace);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.WhiteSpace, Res.Sch_WhiteSpaceFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.WhiteSpace, Res.Sch_DupWhiteSpaceFacet);
                    if (facet.Value == "preserve") {
                        restriction.WhiteSpace = XmlSchemaWhiteSpace.Preserve;
                    }
                    else if (facet.Value == "replace") {
                        restriction.WhiteSpace = XmlSchemaWhiteSpace.Replace;
                    }
                    else if (facet.Value == "collapse") {
                        restriction.WhiteSpace = XmlSchemaWhiteSpace.Collapse;
                    }
                    else {
                        throw new XmlSchemaException(Res.Sch_InvalidWhiteSpace, facet.Value, facet);
                    }
                    if (IsWhitespaceCollapseFixed && (restriction.WhiteSpace != XmlSchemaWhiteSpace.Collapse)) {
                        throw new XmlSchemaException(Res.Sch_InvalidWhiteSpace, facet.Value, facet);
                    }
                    if ((thisFlags & RestrictionFlags.WhiteSpace) != 0) {
                        if (
                            this.restriction.WhiteSpace == XmlSchemaWhiteSpace.Collapse &&
                            (restriction.WhiteSpace == XmlSchemaWhiteSpace.Replace || restriction.WhiteSpace == XmlSchemaWhiteSpace.Preserve)
                        ) {
                            throw new XmlSchemaException(Res.Sch_WhiteSpaceRestriction1, facet);
                        }
                        if (
                            this.restriction.WhiteSpace == XmlSchemaWhiteSpace.Preserve &&
                            restriction.WhiteSpace == XmlSchemaWhiteSpace.Replace
                        ) {
                            throw new XmlSchemaException(Res.Sch_WhiteSpaceRestriction2, facet);
                        }
                    }
                    SetFlag(restriction, facet, RestrictionFlags.WhiteSpace);
                }
                else if (facet is XmlSchemaMaxInclusiveFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.Length);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MaxInclusive, Res.Sch_MaxInclusiveFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MaxInclusive, Res.Sch_DupMaxInclusiveFacet);
                    try {
                        restriction.MaxInclusive = ParseAtomicValue(facet.Value, nameTable, nsmgr);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MaxInclusiveFacetInvalid, e.Message, facet);
                    }
                    CheckValue(restriction.MaxInclusive, facet, thisFlags);
                    SetFlag(restriction, facet, RestrictionFlags.MaxInclusive);
                }
                else if (facet is XmlSchemaMaxExclusiveFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.MaxExclusive);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MaxExclusive, Res.Sch_MaxExclusiveFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MaxExclusive, Res.Sch_DupMaxExclusiveFacet);
                    try {
                        restriction.MaxExclusive = ParseAtomicValue(facet.Value, nameTable, nsmgr);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MaxExclusiveFacetInvalid, e.Message, facet);
                    }
                    CheckValue(restriction.MaxExclusive, facet, thisFlags);
                    SetFlag(restriction, facet, RestrictionFlags.MaxExclusive);
                }
                else if (facet is XmlSchemaMinInclusiveFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.MinInclusive);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MinInclusive, Res.Sch_MinInclusiveFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MinInclusive, Res.Sch_DupMinInclusiveFacet);
                    try {
                        restriction.MinInclusive = ParseAtomicValue(facet.Value, nameTable, nsmgr);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MinInclusiveFacetInvalid, e.Message, facet);
                    }
                    CheckValue(restriction.MinInclusive, facet, thisFlags);
                    SetFlag(restriction, facet, RestrictionFlags.MinInclusive);
                }
                else if (facet is XmlSchemaMinExclusiveFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.MinExclusive);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.MinExclusive, Res.Sch_MinExclusiveFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.MinExclusive, Res.Sch_DupMinExclusiveFacet);
                    try {
                        restriction.MinExclusive = ParseAtomicValue(facet.Value, nameTable, nsmgr);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_MinExclusiveFacetInvalid, e.Message, facet);
                    }
                    CheckValue(restriction.MinExclusive, facet, thisFlags);
                    SetFlag(restriction, facet, RestrictionFlags.MinExclusive);
                }
                else if (facet is XmlSchemaTotalDigitsFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.TotalDigits);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.TotalDigits, Res.Sch_TotalDigitsFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.TotalDigits, Res.Sch_DupTotalDigitsFacet);
                    try {
                        restriction.TotalDigits = (int)(decimal)c_positiveInteger.ParseAtomicValue(facet.Value, null, null);
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_TotalDigitsFacetInvalid, e.Message, facet);
                    }
                    SetFlag(restriction, facet, RestrictionFlags.TotalDigits);
                }
                else if (facet is XmlSchemaFractionDigitsFacet) {
                    CheckFixedFlag(facet, fixedFlags, RestrictionFlags.FractionDigits);
                    CheckProhibitedFlag(facet, validRestrictionFlags,  RestrictionFlags.FractionDigits, Res.Sch_FractionDigitsFacetProhibited);
                    CheckDupFlag(facet, restriction, RestrictionFlags.FractionDigits, Res.Sch_DupFractionDigitsFacet);
                    try {
                        restriction.FractionDigits = (int)(decimal)c_nonNegativeInteger.ParseAtomicValue(facet.Value, null, null);
                        if ((restriction.FractionDigits != 0) && (this.GetType() != typeof(Datatype_decimal))) {
                            throw new XmlSchemaException(Res.Sch_FractionDigitsNotOnDecimal, facet);
                        }
                    }
                    catch (XmlSchemaException xse) {
                        if (xse.SourceSchemaObject == null) {
                            xse.SetSource(facet);
                        }
                        throw xse;
                    }
                    catch (Exception e) {
                        throw new XmlSchemaException(Res.Sch_FractionDigitsFacetInvalid, e.Message, facet);
                    }
                    SetFlag(restriction, facet, RestrictionFlags.FractionDigits);
                }
                else {
                    throw new XmlSchemaException(Res.Sch_UnknownFacet, facet);
                }

            }

            //If facet is XMLSchemaPattern, then the String built inside the loop
            //needs to be converted to a RegEx

            if(firstP == false) {
                if (restriction.Patterns == null) {
                    restriction.Patterns = new ArrayList();
                }
                try {
                    regStr.Append(")");
                    string tempStr = regStr.ToString();
                    if(tempStr.IndexOf("|") != -1) {
                        regStr.Insert(0,"(");
                        regStr.Append(")");
                    }
                   restriction.Patterns.Add(new Regex(Preprocess(regStr.ToString()), RegexOptions.None));

                }catch (Exception e) {
                    throw new XmlSchemaException(Res.Sch_PatternFacetInvalid, e.Message, pattern_facet);
                }
            }

            // Copy from the base
            if (
                (restriction.Flags & RestrictionFlags.Length) == 0 &&
                (thisFlags & RestrictionFlags.Length) != 0
            ) {
                restriction.Length = this.restriction.Length;
                SetFlag(restriction, fixedFlags, RestrictionFlags.Length);
            }
            if (
                (restriction.Flags & RestrictionFlags.MinLength) == 0 &&
                (thisFlags & RestrictionFlags.MinLength) != 0
            ) {
                restriction.MinLength = this.restriction.MinLength;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MinLength);
            }
            if (
                (restriction.Flags & RestrictionFlags.MaxLength) == 0 &&
                (thisFlags & RestrictionFlags.MaxLength) != 0
            ) {
                restriction.MaxLength = this.restriction.MaxLength;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MaxLength);
            }
            if ((thisFlags & RestrictionFlags.Pattern) != 0) {
                if (restriction.Patterns == null) {
                    restriction.Patterns = this.restriction.Patterns;
                }
                else {
                    restriction.Patterns.AddRange(this.restriction.Patterns);
                }
                SetFlag(restriction, fixedFlags, RestrictionFlags.Pattern);
            }


            if ((thisFlags & RestrictionFlags.Enumeration) != 0) {
                if (restriction.Enumeration == null) {
                    restriction.Enumeration = this.restriction.Enumeration;
                }
                SetFlag(restriction, fixedFlags, RestrictionFlags.Enumeration);
            }

            if (
                (restriction.Flags & RestrictionFlags.WhiteSpace) == 0 &&
                (thisFlags & RestrictionFlags.WhiteSpace) != 0
            ) {
                restriction.WhiteSpace = this.restriction.WhiteSpace;
                SetFlag(restriction, fixedFlags, RestrictionFlags.WhiteSpace);
            }
            if (
                (restriction.Flags & RestrictionFlags.MaxInclusive) == 0 &&
                (thisFlags & RestrictionFlags.MaxInclusive) != 0
            ) {
                restriction.MaxInclusive = this.restriction.MaxInclusive;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MaxInclusive);
            }
            if (
                (restriction.Flags & RestrictionFlags.MaxExclusive) == 0 &&
                (thisFlags & RestrictionFlags.MaxExclusive) != 0
            ) {
                restriction.MaxExclusive = this.restriction.MaxExclusive;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MaxExclusive);
            }
            if (
                (restriction.Flags & RestrictionFlags.MinInclusive) == 0 &&
                (thisFlags & RestrictionFlags.MinInclusive) != 0
            ) {
                restriction.MinInclusive = this.restriction.MinInclusive;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MinInclusive);
            }
            if (
                (restriction.Flags & RestrictionFlags.MinExclusive) == 0 &&
                (thisFlags & RestrictionFlags.MinExclusive) != 0
            ) {
                restriction.MinExclusive = this.restriction.MinExclusive;
                SetFlag(restriction, fixedFlags, RestrictionFlags.MinExclusive);
            }
            if (
                (restriction.Flags & RestrictionFlags.TotalDigits) == 0 &&
                (thisFlags & RestrictionFlags.TotalDigits) != 0
            ) {
                restriction.MinExclusive = this.restriction.TotalDigits;
                SetFlag(restriction, fixedFlags, RestrictionFlags.TotalDigits);
            }
            if (
                (restriction.Flags & RestrictionFlags.FractionDigits) == 0 &&
                (thisFlags & RestrictionFlags.FractionDigits) != 0
            ) {
                restriction.FractionDigits = this.restriction.FractionDigits;
                SetFlag(restriction, fixedFlags, RestrictionFlags.FractionDigits);
            }

            // Check combinations
            if (
                (restriction.Flags & RestrictionFlags.Length) != 0 &&
                (restriction.Flags & (RestrictionFlags.MinLength|RestrictionFlags.MaxLength)) != 0
            ) {
                throw new XmlSchemaException(Res.Sch_LengthAndMinMax);
            }
            if (
                (restriction.Flags & RestrictionFlags.MinLength) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxLength) != 0
            ) {
                if (restriction.MinLength > restriction.MaxLength) {
                    throw new XmlSchemaException(Res.Sch_MinLengthGtMaxLength);
                }
            }
            if (
                (restriction.Flags & RestrictionFlags.MaxInclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxExclusive) != 0
            ) {
                throw new XmlSchemaException(Res.Sch_MaxInclusiveExclusive);
            }
            if (
                (restriction.Flags & RestrictionFlags.MinInclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MinExclusive) != 0
            ) {
                throw new XmlSchemaException(Res.Sch_MinInclusiveExclusive);
            }

            if (
                (restriction.Flags & RestrictionFlags.MinInclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxInclusive) != 0
            ) {
                if (Compare(restriction.MinInclusive, restriction.MaxInclusive) > 0) {
                    throw new XmlSchemaException(Res.Sch_MinInclusiveGtMaxInclusive);
                }
            }
            if (
                (restriction.Flags & RestrictionFlags.MinInclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxExclusive) != 0
            ) {
                if (Compare(restriction.MinInclusive, restriction.MaxExclusive) > 0) {
                    throw new XmlSchemaException(Res.Sch_MinInclusiveGtMaxExclusive);
                }
            }
            if (
                (restriction.Flags & RestrictionFlags.MinExclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxExclusive) != 0
            ) {
                if (Compare(restriction.MinExclusive, restriction.MaxExclusive) > 0) {
                    throw new XmlSchemaException(Res.Sch_MinExclusiveGtMaxExclusive);
                }
            }
            if (
                (restriction.Flags & RestrictionFlags.MinExclusive) != 0 &&
                (restriction.Flags & RestrictionFlags.MaxInclusive) != 0
            ) {
                if (Compare(restriction.MinExclusive, restriction.MaxInclusive) > 0) {
                    throw new XmlSchemaException(Res.Sch_MinExclusiveGtMaxInclusive);
                }
            }
            if ((restriction.Flags & (RestrictionFlags.TotalDigits|RestrictionFlags.FractionDigits)) == (RestrictionFlags.TotalDigits|RestrictionFlags.FractionDigits)) {
                if (restriction.FractionDigits > restriction.TotalDigits) {
                    throw new XmlSchemaException(Res.Sch_FractionDigitsGtTotalDigits);
                }
            }
            return restriction;
        }
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     this.firstPattern = true;
     this.regStr = null;
     this.pattern_facet = null;
     this.datatype = baseDatatype;
     this.derivedRestriction = restriction;
     this.baseFlags = (this.datatype.Restriction != null) ? this.datatype.Restriction.Flags : ((RestrictionFlags) 0);
     this.baseFixedFlags = (this.datatype.Restriction != null) ? this.datatype.Restriction.FixedFlags : ((RestrictionFlags) 0);
     this.validRestrictionFlags = this.datatype.ValidRestrictionFlags;
     this.nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     this.builtInEnum = (!(this.datatype is Datatype_union) && !(this.datatype is Datatype_List)) ? this.datatype.TypeCode : XmlTypeCode.None;
     this.builtInType = (this.builtInEnum > XmlTypeCode.None) ? DatatypeImplementation.GetSimpleTypeFromTypeCode(this.builtInEnum).Datatype : this.datatype;
 }
 private void Write25_XmlSchemaPatternFacet(string n, string ns, XmlSchemaPatternFacet o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(XmlSchemaPatternFacet)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.EscapeName = false;
         base.WriteStartElement(n, ns, o, false, o.Namespaces);
         if (needType)
         {
             base.WriteXsiType("XmlSchemaPatternFacet", "http://www.w3.org/2001/XMLSchema");
         }
         base.WriteAttribute("id", "", o.Id);
         XmlAttribute[] unhandledAttributes = o.UnhandledAttributes;
         if (unhandledAttributes != null)
         {
             for (int i = 0; i < unhandledAttributes.Length; i++)
             {
                 XmlAttribute node = unhandledAttributes[i];
                 base.WriteXmlAttribute(node, o);
             }
         }
         base.WriteAttribute("value", "", o.Value);
         if (o.IsFixed)
         {
             base.WriteAttribute("fixed", "", XmlConvert.ToString(o.IsFixed));
         }
         this.Write11_XmlSchemaAnnotation("annotation", "http://www.w3.org/2001/XMLSchema", o.Annotation, false, false);
         base.WriteEndElement(o);
     }
 }
Example #18
0
 internal void CompilePatternFacet(XmlSchemaPatternFacet facet) {
     CheckProhibitedFlag(facet, RestrictionFlags.Pattern, Res.Sch_PatternFacetProhibited);
     if(firstPattern == true) {
         regStr = new StringBuilder();
         regStr.Append("(");
         regStr.Append(facet.Value);
         pattern_facet = facet;
         firstPattern = false;
     }
     else {
         regStr.Append(")|(");
         regStr.Append(facet.Value);
     }
     SetFlag(facet, RestrictionFlags.Pattern);
 }
 internal void CompilePatternFacet(XmlSchemaPatternFacet facet)
 {
     this.CheckProhibitedFlag(facet, RestrictionFlags.Pattern, "Sch_PatternFacetProhibited");
     if (this.firstPattern)
     {
         this.regStr = new StringBuilder();
         this.regStr.Append("(");
         this.regStr.Append(facet.Value);
         this.pattern_facet = facet;
         this.firstPattern = false;
     }
     else
     {
         this.regStr.Append(")|(");
         this.regStr.Append(facet.Value);
     }
     this.SetFlag(facet, RestrictionFlags.Pattern);
 }
Example #20
0
        static TypeScope() {
            AddPrimitive(typeof(string), "string", "String", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.Reference);
            AddPrimitive(typeof(int), "int", "Int32", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(bool), "boolean", "Boolean", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(short), "short", "Int16", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(long), "long", "Int64", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(float), "float", "Single", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(double), "double", "Double", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(decimal), "decimal", "Decimal", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(DateTime), "dateTime", "DateTime", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(XmlQualifiedName), "QName", "XmlQualifiedName", TypeFlags.CanBeAttributeValue | TypeFlags.HasCustomFormatter | TypeFlags.HasIsEmpty | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(byte), "unsignedByte", "Byte", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(SByte), "byte", "SByte", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(UInt16), "unsignedShort", "UInt16", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(UInt32), "unsignedInt", "UInt32", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(UInt64), "unsignedLong", "UInt64", TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);

            // Types without direct mapping (ambigous)
            AddPrimitive(typeof(DateTime), "date", "Date", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(DateTime), "time", "Time", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.XmlEncodingNotRequired);

            AddPrimitive(typeof(string), "Name", "XmlName", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference);
            AddPrimitive(typeof(string), "NCName", "XmlNCName", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference);
            AddPrimitive(typeof(string), "NMTOKEN", "XmlNmToken", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference);
            AddPrimitive(typeof(string), "NMTOKENS", "XmlNmTokens", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference);

            AddPrimitive(typeof(byte[]), "base64Binary", "ByteArrayBase64", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference | TypeFlags.IgnoreDefault | TypeFlags.XmlEncodingNotRequired);
            AddPrimitive(typeof(byte[]), "hexBinary", "ByteArrayHex", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter | TypeFlags.Reference  | TypeFlags.IgnoreDefault | TypeFlags.XmlEncodingNotRequired);

            XmlSchemaPatternFacet guidPattern = new XmlSchemaPatternFacet();
            guidPattern.Value = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";

            AddNonXsdPrimitive(typeof(Guid), "guid", UrtTypes.Namespace, "Guid", new XmlQualifiedName("string", XmlSchema.Namespace), new XmlSchemaFacet[] { guidPattern }, TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.XmlEncodingNotRequired);
            AddNonXsdPrimitive(typeof(char), "char", UrtTypes.Namespace, "Char", new XmlQualifiedName("unsignedShort", XmlSchema.Namespace), new XmlSchemaFacet[0], TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.HasCustomFormatter);

            AddSoapEncodedTypes(Soap.Encoding);

            // Unsuppoted types that we map to string, if in the future we decide 
            // to add support for them we would need to create custom formatters for them
            for (int i = 0; i < unsupportedTypes.Length; i++) {
                AddPrimitive(typeof(string), unsupportedTypes[i], "String", TypeFlags.AmbiguousDataType | TypeFlags.CanBeAttributeValue | TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.Reference);
            }
        }
 protected virtual void Visit(XmlSchemaPatternFacet facet)
 {
 }
		public XsdSimpleRestrictionType (RelaxngDatatype primitive, RelaxngParamList parameters)
		{
			type = new XmlSchemaSimpleType ();
			XmlSchemaSimpleTypeRestriction r =
				new XmlSchemaSimpleTypeRestriction ();
			type.Content = r;
			string ns = primitive.NamespaceURI;
			// Remap XML Schema datatypes namespace -> XML Schema namespace.
			if (ns == "http://www.w3.org/2001/XMLSchema-datatypes")
				ns = XSchema.Namespace;
			r.BaseTypeName = new XmlQualifiedName (primitive.Name, ns);
			foreach (RelaxngParam p in parameters) {
				XmlSchemaFacet f = null;
				string value = p.Value;
				switch (p.Name) {
				case "maxExclusive":
					f = new XmlSchemaMaxExclusiveFacet ();
					break;
				case "maxInclusive":
					f = new XmlSchemaMaxInclusiveFacet ();
					break;
				case "minExclusive":
					f = new XmlSchemaMinExclusiveFacet ();
					break;
				case "minInclusive":
					f = new XmlSchemaMinInclusiveFacet ();
					break;
				case "pattern":
					f = new XmlSchemaPatternFacet ();
					// .NET/Mono Regex has a bug that it does not support "IsLatin-1Supplement"
					// (it somehow breaks at '-').
					value = value.Replace ("\\p{IsLatin-1Supplement}", "[\\x80-\\xFF]");
					break;
				case "whiteSpace":
					f = new XmlSchemaWhiteSpaceFacet ();
					break;
				case "length":
					f = new XmlSchemaLengthFacet ();
					break;
				case "maxLength":
					f = new XmlSchemaMaxLengthFacet ();
					break;
				case "minLength":
					f = new XmlSchemaMinLengthFacet ();
					break;
				case "fractionDigits":
					f = new XmlSchemaFractionDigitsFacet ();
					break;
				case "totalDigits":
					f = new XmlSchemaTotalDigitsFacet ();
					break;
				default:
					throw new RelaxngException (String.Format ("XML Schema facet {0} is not recognized or not supported.", p.Name));
				}
				f.Value = value;
				r.Facets.Add (f);
			}

			// Now we create XmlSchema to handle simple-type
			// based validation (since there is no other way, 
			// because of sucky XmlSchemaSimpleType design).
			schema = new XSchema ();
			XmlSchemaElement el = new XmlSchemaElement ();
			el.Name = "root";
			el.SchemaType = type;
			schema.Items.Add (el);
			schema.Compile (null);
		}
Example #23
0
        internal static XmlSchemaPatternFacet Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaPatternFacet xmlSchemaPatternFacet = new XmlSchemaPatternFacet();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "pattern")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaPatternFacet.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaPatternFacet.LineNumber   = reader.LineNumber;
            xmlSchemaPatternFacet.LinePosition = reader.LinePosition;
            xmlSchemaPatternFacet.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaPatternFacet.Id = reader.Value;
                }
                else if (reader.Name == "value")
                {
                    xmlSchemaPatternFacet.Value = reader.Value;
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for pattern", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaPatternFacet);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaPatternFacet);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "pattern")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaPatternFacet.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaPatternFacet.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaPatternFacet);
        }
		//<pattern
		//  id = ID
		//  value = anySimpleType
		//  {any attributes with non-schema namespace . . .}>
		//  Content: (annotation?)
		//</pattern>
		internal static XmlSchemaPatternFacet Read(XmlSchemaReader reader, ValidationEventHandler h)
		{
			XmlSchemaPatternFacet pattern = new XmlSchemaPatternFacet();
			reader.MoveToElement();

			if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
			{
				error(h,"Should not happen :1: XmlSchemaPatternFacet.Read, name="+reader.Name,null);
				reader.Skip();
				return null;
			}

			pattern.LineNumber = reader.LineNumber;
			pattern.LinePosition = reader.LinePosition;
			pattern.SourceUri = reader.BaseURI;

			while(reader.MoveToNextAttribute())
			{
				if(reader.Name == "id")
				{
					pattern.Id = reader.Value;
				}
				else if(reader.Name == "value")
				{
					pattern.Value = reader.Value;
				}
				else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
				{
					error(h,reader.Name + " is not a valid attribute for "+xmlname,null);
				}
				else
				{
					XmlSchemaUtil.ReadUnhandledAttribute(reader,pattern);
				}
			}
			
			reader.MoveToElement();
			if(reader.IsEmptyElement)
				return pattern;

			//  Content: (annotation?)
			int level = 1;
			while(reader.ReadNextElement())
			{
				if(reader.NodeType == XmlNodeType.EndElement)
				{
					if(reader.LocalName != xmlname)
						error(h,"Should not happen :2: XmlSchemaPatternFacet.Read, name="+reader.Name,null);
					break;
				}
				if(level <= 1 && reader.LocalName == "annotation")
				{
					level = 2;	//Only one annotation
					XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
					if(annotation != null)
						pattern.Annotation = annotation;
					continue;
				}
				reader.RaiseInvalidElementError();
			}			
			return pattern;
		}
Example #25
0
        //<pattern
        //  id = ID
        //  value = anySimpleType
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?)
        //</pattern>
        internal static XmlSchemaPatternFacet Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaPatternFacet pattern = new XmlSchemaPatternFacet();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaPatternFacet.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            pattern.LineNumber   = reader.LineNumber;
            pattern.LinePosition = reader.LinePosition;
            pattern.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    pattern.Id = reader.Value;
                }
                else if (reader.Name == "value")
                {
                    pattern.Value = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for " + xmlname, null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, pattern);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(pattern);
            }

            //  Content: (annotation?)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaPatternFacet.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                          //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        pattern.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(pattern);
        }