internal virtual Exception CheckLexicalFacets(ref string parsedString, object value, NameTable nameTable, XNamespaceResolver resolver, SimpleTypeValidator type)
        {
            Exception exception;

            Xml.Schema.Linq.RestrictionFacets facets = type.RestrictionFacets;
            if ((facets == null ? false : facets.HasLexicalFacets))
            {
                Xml.Schema.Linq.RestrictionFlags    flags     = facets.Flags;
                Xml.Schema.Linq.XmlSchemaWhiteSpace wsPattern = Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.WhiteSpace) != 0)
                {
                    if (facets.WhiteSpace == Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse)
                    {
                        wsPattern = Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse;
                    }
                    else if (facets.WhiteSpace == Xml.Schema.Linq.XmlSchemaWhiteSpace.Preserve)
                    {
                        wsPattern = Xml.Schema.Linq.XmlSchemaWhiteSpace.Preserve;
                    }
                }
                exception = this.CheckLexicalFacets(ref parsedString, type, facets.Patterns, wsPattern);
            }
            else
            {
                exception = null;
            }
            return(exception);
        }
 internal void CheckWhitespaceFacets(ref string s, SimpleTypeValidator type, Xml.Schema.Linq.XmlSchemaWhiteSpace wsPattern)
 {
     Xml.Schema.Linq.RestrictionFacets restriction = type.RestrictionFacets;
     if (type.Variety == XmlSchemaDatatypeVariety.List)
     {
         s = s.Trim();
     }
     else if (type.Variety == XmlSchemaDatatypeVariety.Atomic)
     {
         XmlSchemaDatatype datatype = type.DataType;
         if (datatype.GetBuiltInWSFacet() == Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse)
         {
             s = Xml.Schema.Linq.XmlComplianceUtil.NonCDataNormalize(s);
         }
         else if (datatype.GetBuiltInWSFacet() == Xml.Schema.Linq.XmlSchemaWhiteSpace.Replace)
         {
             s = Xml.Schema.Linq.XmlComplianceUtil.CDataNormalize(s);
         }
         else if (restriction != null & (int)(restriction.Flags & Xml.Schema.Linq.RestrictionFlags.WhiteSpace) != 0)
         {
             if (restriction.WhiteSpace == Xml.Schema.Linq.XmlSchemaWhiteSpace.Replace)
             {
                 s = Xml.Schema.Linq.XmlComplianceUtil.CDataNormalize(s);
             }
             else if (restriction.WhiteSpace == Xml.Schema.Linq.XmlSchemaWhiteSpace.Collapse)
             {
                 s = Xml.Schema.Linq.XmlComplianceUtil.NonCDataNormalize(s);
             }
         }
     }
 }
Exemple #3
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;
            }
        }
Exemple #4
0
 public CompiledFacets(XmlSchemaDatatype dt)
 {
     this.whiteSpace = dt.GetBuiltInWSFacet();
 }
 internal virtual Exception CheckLexicalFacets(ref string parsedString, SimpleTypeValidator type, ArrayList patterns, Xml.Schema.Linq.XmlSchemaWhiteSpace wsPattern)
 {
     this.CheckWhitespaceFacets(ref parsedString, type, wsPattern);
     return(this.CheckPatternFacets(patterns, parsedString));
 }