상속: SchemaDeclBase, IDtdDefaultAttributeInfo
예제 #1
0
        public static void SetDefaultTypedValue(
            SchemaAttDef attdef,
            IDtdParserAdapter readerAdapter
            )
        {
            try {
                string            value = attdef.DefaultValueExpanded;
                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null)
                {
                    return; // no reason to check
                }
                if (dtype.TokenizedType != XmlTokenizedType.CDATA)
                {
                    value = value.Trim();
                }
                attdef.DefaultValueTyped = dtype.ParseValue(value, readerAdapter.NameTable, readerAdapter.NamespaceResolver);
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch (Exception)  {
#endif
                IValidationEventHandling eventHandling = ((IDtdParserAdapterWithValidation)readerAdapter).ValidationEventHandling;
                if (eventHandling != null)
                {
                    XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString());
                    eventHandling.SendEvent(e, XmlSeverityType.Error);
                }
            }
        }
        internal SchemaAttDef GetAttributeXsd(SchemaElementDecl ed, XmlQualifiedName qname, ref bool skip)
        {
            AttributeMatchState state;
            SchemaAttDef        def = this.GetAttributeXsd(ed, qname, null, out state);

            switch (state)
            {
            case AttributeMatchState.AttributeFound:
            case AttributeMatchState.AnyIdAttributeFound:
            case AttributeMatchState.UndeclaredElementAndAttribute:
            case AttributeMatchState.AnyAttributeLax:
                return(def);

            case AttributeMatchState.UndeclaredAttribute:
                throw new XmlSchemaException("Sch_UndeclaredAttribute", qname.ToString());

            case AttributeMatchState.AnyAttributeSkip:
                skip = true;
                return(def);

            case AttributeMatchState.ProhibitedAnyAttribute:
            case AttributeMatchState.ProhibitedAttribute:
                throw new XmlSchemaException("Sch_ProhibitedAttribute", qname.ToString());
            }
            return(def);
        }
예제 #3
0
 private void ValidateEndStartElement()
 {
     if (base.context.ElementDecl.HasDefaultAttribute)
     {
         for (int i = 0; i < base.context.ElementDecl.DefaultAttDefs.Count; i++)
         {
             SchemaAttDef attdef = (SchemaAttDef)base.context.ElementDecl.DefaultAttDefs[i];
             base.reader.AddDefaultAttribute(attdef);
             if (this.HasIdentityConstraints && !this.attPresence.Contains(attdef.Name))
             {
                 this.AttributeIdentityConstraints(attdef.Name.Name, attdef.Name.Namespace, this.UnWrapUnion(attdef.DefaultValueTyped), attdef.DefaultValueRaw, attdef);
             }
         }
     }
     if (base.context.ElementDecl.HasRequiredAttribute)
     {
         try
         {
             base.context.ElementDecl.CheckAttributes(this.attPresence, base.reader.StandAlone);
         }
         catch (XmlSchemaException exception)
         {
             exception.SetSource(base.reader.BaseURI, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition);
             base.SendValidationEvent(exception);
         }
     }
     if (base.context.ElementDecl.Datatype != null)
     {
         base.checkDatatype    = true;
         base.hasSibling       = false;
         base.textString       = string.Empty;
         base.textValue.Length = 0;
     }
 }
        internal SchemaAttDef GetAttributeXsd(SchemaElementDecl ed, XmlQualifiedName qname, ref bool skip)
        {
            AttributeMatchState attributeMatchState;

            SchemaAttDef attDef = GetAttributeXsd(ed, qname, null, out attributeMatchState);

            switch (attributeMatchState)
            {
            case AttributeMatchState.UndeclaredAttribute:
                throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());

            case AttributeMatchState.ProhibitedAnyAttribute:
            case AttributeMatchState.ProhibitedAttribute:
                throw new XmlSchemaException(Res.Sch_ProhibitedAttribute, qname.ToString());

            case AttributeMatchState.AttributeFound:
            case AttributeMatchState.AnyIdAttributeFound:
            case AttributeMatchState.AnyAttributeLax:
            case AttributeMatchState.UndeclaredElementAndAttribute:
                break;

            case AttributeMatchState.AnyAttributeSkip:
                skip = true;
                break;

            default:
                Debug.Assert(false);
                break;
            }
            return(attDef);
        }
        private void ValidateEndStartElement()
        {
            if (context.ElementDecl.HasDefaultAttribute)
            {
                for (int i = 0; i < context.ElementDecl.DefaultAttDefs.Count; ++i)
                {
                    SchemaAttDef attdef = (SchemaAttDef)context.ElementDecl.DefaultAttDefs[i];
                    reader.AddDefaultAttribute(attdef);
                    // even default attribute i have to move to... but can't exist
                    if (HasIdentityConstraints && !attPresence.Contains(attdef.Name))
                    {
                        AttributeIdentityConstraints(attdef.Name.Name, attdef.Name.Namespace, UnWrapUnion(attdef.DefaultValueTyped), attdef.DefaultValueRaw, attdef);
                    }
                }
            }

            if (context.ElementDecl.HasRequiredAttribute)
            {
                try {
                    context.ElementDecl.CheckAttributes(attPresence, reader.StandAlone);
                }
                catch (XmlSchemaException e) {
                    e.SetSource(reader.BaseURI, PositionInfo.LineNumber, PositionInfo.LinePosition);
                    SendValidationEvent(e);
                }
            }
            if (context.ElementDecl.Datatype != null)
            {
                checkDatatype    = true;
                hasSibling       = false;
                textString       = string.Empty;
                textValue.Length = 0;
            }
        }
 public static void SetDefaultTypedValue(SchemaAttDef attdef, IDtdParserAdapter readerAdapter)
 {
     try
     {
         string            defaultValueExpanded = attdef.DefaultValueExpanded;
         XmlSchemaDatatype datatype             = attdef.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 defaultValueExpanded = defaultValueExpanded.Trim();
             }
             attdef.DefaultValueTyped = datatype.ParseValue(defaultValueExpanded, readerAdapter.NameTable, readerAdapter.NamespaceResolver);
         }
     }
     catch (Exception)
     {
         IValidationEventHandling validationEventHandling = ((IDtdParserAdapterWithValidation)readerAdapter).ValidationEventHandling;
         if (validationEventHandling != null)
         {
             XmlSchemaException exception = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString());
             validationEventHandling.SendEvent(exception, XmlSeverityType.Error);
         }
     }
 }
예제 #7
0
 private void CheckValue(string value, SchemaAttDef attdef)
 {
     try
     {
         base.reader.TypedValueObject = null;
         bool flag = attdef != null;
         XmlSchemaDatatype datatype = flag ? attdef.Datatype : base.context.ElementDecl.Datatype;
         if (datatype != null)
         {
             object pVal = datatype.ParseValue(value, base.NameTable, this.nsManager, true);
             switch (datatype.TokenizedType)
             {
             case XmlTokenizedType.ENTITY:
             case XmlTokenizedType.ID:
             case XmlTokenizedType.IDREF:
                 if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                 {
                     string[] strArray = (string[])pVal;
                     for (int i = 0; i < strArray.Length; i++)
                     {
                         this.ProcessTokenizedType(datatype.TokenizedType, strArray[i]);
                     }
                 }
                 else
                 {
                     this.ProcessTokenizedType(datatype.TokenizedType, (string)pVal);
                 }
                 break;
             }
             SchemaDeclBase base2 = flag ? ((SchemaDeclBase)attdef) : ((SchemaDeclBase)base.context.ElementDecl);
             if (!base2.CheckValue(pVal))
             {
                 if (flag)
                 {
                     base.SendValidationEvent("Sch_FixedAttributeValue", attdef.Name.ToString());
                 }
                 else
                 {
                     base.SendValidationEvent("Sch_FixedElementValue", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace));
                 }
             }
             if (datatype.Variety == XmlSchemaDatatypeVariety.Union)
             {
                 pVal = this.UnWrapUnion(pVal);
             }
             base.reader.TypedValueObject = pVal;
         }
     }
     catch (XmlSchemaException)
     {
         if (attdef != null)
         {
             base.SendValidationEvent("Sch_AttributeValueDataType", attdef.Name.ToString());
         }
         else
         {
             base.SendValidationEvent("Sch_ElementValueDataType", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace));
         }
     }
 }
예제 #8
0
        private void ValidateStartElement()
        {
            if (context.ElementDecl != null)
            {
                if (context.ElementDecl.SchemaType != null)
                {
                    reader.SchemaTypeObject = context.ElementDecl.SchemaType;
                }
                else
                {
                    reader.SchemaTypeObject = context.ElementDecl.Datatype;
                }
                if (reader.IsEmptyElement && !context.IsNill && context.ElementDecl.DefaultValueTyped != null)
                {
                    reader.TypedValueObject = context.ElementDecl.DefaultValueTyped;
                    context.IsNill          = true; // reusing IsNill
                }
                if (this.context.ElementDecl.HasRequiredAttribute)
                {
                    attPresence.Clear();
                }
            }

            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    if ((object)reader.NamespaceURI == (object)SchemaNames.NsXmlNs)
                    {
                        continue;
                    }

                    try {
                        reader.SchemaTypeObject = null;
                        SchemaAttDef attnDef = schemaInfo.GetAttributeXdr(context.ElementDecl, QualifiedName(reader.LocalName, reader.NamespaceURI));
                        if (attnDef != null)
                        {
                            if (context.ElementDecl != null && context.ElementDecl.HasRequiredAttribute)
                            {
                                attPresence.Add(attnDef.Name, attnDef);
                            }
                            reader.SchemaTypeObject = (attnDef.SchemaType != null) ? (object)attnDef.SchemaType : (object)attnDef.Datatype;
                            if (attnDef.Datatype != null)
                            {
                                string attributeValue = reader.Value;
                                // need to check the contents of this attribute to make sure
                                // it is valid according to the specified attribute type.
                                CheckValue(attributeValue, attnDef);
                            }
                        }
                    }
                    catch (XmlSchemaException e) {
                        e.SetSource(reader.BaseURI, PositionInfo.LineNumber, PositionInfo.LinePosition);
                        SendValidationEvent(e);
                    }
                } while(reader.MoveToNextAttribute());
                reader.MoveToElement();
            }
        }
 // add a new SchemaAttDef to the SchemaElementDecl
 public void AddAttDef(SchemaAttDef attdef)
 {
     attdefs.Add(attdef.Name, attdef);
     if (attdef.Presence == SchemaDeclBase.Use.Required)
     {
         hasRequiredAttribute = true;
     }
 }
 private void ValidateStartElement()
 {
     if (base.context.ElementDecl != null)
     {
         if (base.context.ElementDecl.SchemaType != null)
         {
             base.reader.SchemaTypeObject = base.context.ElementDecl.SchemaType;
         }
         else
         {
             base.reader.SchemaTypeObject = base.context.ElementDecl.Datatype;
         }
         if ((base.reader.IsEmptyElement && !base.context.IsNill) && (base.context.ElementDecl.DefaultValueTyped != null))
         {
             base.reader.TypedValueObject = base.context.ElementDecl.DefaultValueTyped;
             base.context.IsNill          = true;
         }
         if (base.context.ElementDecl.HasRequiredAttribute)
         {
             this.attPresence.Clear();
         }
     }
     if (base.reader.MoveToFirstAttribute())
     {
         do
         {
             if (base.reader.NamespaceURI != base.SchemaNames.NsXmlNs)
             {
                 try
                 {
                     base.reader.SchemaTypeObject = null;
                     SchemaAttDef attributeXdr = base.schemaInfo.GetAttributeXdr(base.context.ElementDecl, this.QualifiedName(base.reader.LocalName, base.reader.NamespaceURI));
                     if (attributeXdr != null)
                     {
                         if ((base.context.ElementDecl != null) && base.context.ElementDecl.HasRequiredAttribute)
                         {
                             this.attPresence.Add(attributeXdr.Name, attributeXdr);
                         }
                         base.reader.SchemaTypeObject = (attributeXdr.SchemaType != null) ? ((object)attributeXdr.SchemaType) : ((object)attributeXdr.Datatype);
                         if (attributeXdr.Datatype != null)
                         {
                             string str = base.reader.Value;
                             this.CheckValue(str, attributeXdr);
                         }
                     }
                 }
                 catch (XmlSchemaException exception)
                 {
                     exception.SetSource(base.reader.BaseURI, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition);
                     base.SendValidationEvent(exception);
                 }
             }
         }while (base.reader.MoveToNextAttribute());
         base.reader.MoveToElement();
     }
 }
        internal XmlSchemaAttribute GetAttribute(XmlQualifiedName qname)
        {
            SchemaAttDef def = this.attributeDecls[qname];

            if (def != null)
            {
                return(def.SchemaAttribute);
            }
            return(null);
        }
        internal XmlSchemaAttribute GetAttribute(XmlQualifiedName qname)
        {
            SchemaAttDef attdef = (SchemaAttDef)attributeDecls[qname];

            if (attdef != null)
            {
                return(attdef.SchemaAttribute);
            }
            return(null);
        }
예제 #13
0
 // add a new SchemaAttDef to the SchemaElementDecl
 internal void AddAttDef(SchemaAttDef attdef)
 {
     _attdefs.Add(attdef.Name, attdef);
     if (attdef.Presence == SchemaDeclBase.Use.Default || attdef.Presence == SchemaDeclBase.Use.Fixed)
     { //Not adding RequiredFixed here
         if (_defaultAttdefs == null)
         {
             _defaultAttdefs = new List<IDtdDefaultAttributeInfo>();
         }
         _defaultAttdefs.Add(attdef);
     }
 }
 public static void CheckDefaultValue(string value, SchemaAttDef attdef, SchemaInfo sinfo, XmlNamespaceManager nsManager, XmlNameTable NameTable, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNo, int linePos)
 {
     try
     {
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 value = value.Trim();
             }
             if (value.Length != 0)
             {
                 object           pVal          = datatype.ParseValue(value, NameTable, nsManager);
                 XmlTokenizedType tokenizedType = datatype.TokenizedType;
                 if (tokenizedType == XmlTokenizedType.ENTITY)
                 {
                     if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                     {
                         string[] strArray = (string[])pVal;
                         for (int i = 0; i < strArray.Length; i++)
                         {
                             BaseValidator.ProcessEntity(sinfo, strArray[i], sender, eventhandler, baseUri, lineNo, linePos);
                         }
                     }
                     else
                     {
                         BaseValidator.ProcessEntity(sinfo, (string)pVal, sender, eventhandler, baseUri, lineNo, linePos);
                     }
                 }
                 else if ((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(pVal))
                 {
                     XmlSchemaException ex = new XmlSchemaException("Sch_EnumerationValue", pVal.ToString(), baseUri, lineNo, linePos);
                     if (eventhandler == null)
                     {
                         throw ex;
                     }
                     eventhandler(sender, new ValidationEventArgs(ex));
                 }
                 attdef.DefaultValueTyped = pVal;
             }
         }
     }
     catch
     {
         XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString(), baseUri, lineNo, linePos);
         if (eventhandler == null)
         {
             throw exception2;
         }
         eventhandler(sender, new ValidationEventArgs(exception2));
     }
 }
예제 #15
0
 // add a new SchemaAttDef to the SchemaElementDecl
 internal void AddAttDef(SchemaAttDef attdef)
 {
     _attdefs.Add(attdef.Name, attdef);
     if (attdef.Presence == SchemaDeclBase.Use.Default || attdef.Presence == SchemaDeclBase.Use.Fixed)
     { //Not adding RequiredFixed here
         if (_defaultAttdefs == null)
         {
             _defaultAttdefs = new List <IDtdDefaultAttributeInfo>();
         }
         _defaultAttdefs.Add(attdef);
     }
 }
 public static void CheckDefaultValue(string value, SchemaAttDef attdef, SchemaInfo sinfo, XmlNamespaceManager nsManager, XmlNameTable NameTable, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNo, int linePos)
 {
     try
     {
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 value = value.Trim();
             }
             if (value.Length != 0)
             {
                 object pVal = datatype.ParseValue(value, NameTable, nsManager);
                 XmlTokenizedType tokenizedType = datatype.TokenizedType;
                 if (tokenizedType == XmlTokenizedType.ENTITY)
                 {
                     if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                     {
                         string[] strArray = (string[]) pVal;
                         for (int i = 0; i < strArray.Length; i++)
                         {
                             BaseValidator.ProcessEntity(sinfo, strArray[i], sender, eventhandler, baseUri, lineNo, linePos);
                         }
                     }
                     else
                     {
                         BaseValidator.ProcessEntity(sinfo, (string) pVal, sender, eventhandler, baseUri, lineNo, linePos);
                     }
                 }
                 else if ((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(pVal))
                 {
                     XmlSchemaException ex = new XmlSchemaException("Sch_EnumerationValue", pVal.ToString(), baseUri, lineNo, linePos);
                     if (eventhandler == null)
                     {
                         throw ex;
                     }
                     eventhandler(sender, new ValidationEventArgs(ex));
                 }
                 attdef.DefaultValueTyped = pVal;
             }
         }
     }
     catch
     {
         XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString(), baseUri, lineNo, linePos);
         if (eventhandler == null)
         {
             throw exception2;
         }
         eventhandler(sender, new ValidationEventArgs(exception2));
     }
 }
예제 #17
0
        private void ValidateStartElement()
        {
            if (context.ElementDecl != null)
            {
                Reader.SchemaTypeObject = context.ElementDecl.SchemaType;

                if (Reader.IsEmptyElement && context.ElementDecl.DefaultValueTyped != null)
                {
                    Reader.TypedValueObject = context.ElementDecl.DefaultValueTyped;
                    context.IsNill          = true; // reusing IsNill - what is this flag later used for??
                }
                if (context.ElementDecl.HasRequiredAttribute)
                {
                    _attPresence.Clear();
                }
            }

            if (Reader.MoveToFirstAttribute())
            {
                do
                {
                    try
                    {
                        reader.SchemaTypeObject = null;
                        SchemaAttDef attnDef = context.ElementDecl.GetAttDef(new XmlQualifiedName(reader.LocalName, reader.Prefix));
                        if (attnDef != null)
                        {
                            if (context.ElementDecl != null && context.ElementDecl.HasRequiredAttribute)
                            {
                                _attPresence.Add(attnDef.Name, attnDef);
                            }
                            Reader.SchemaTypeObject = attnDef.SchemaType;

                            if (attnDef.Datatype != null && !reader.IsDefault)
                            { //Since XmlTextReader adds default attributes, do not check again
                                // set typed value
                                CheckValue(Reader.Value, attnDef);
                            }
                        }
                        else
                        {
                            SendValidationEvent(SR.Sch_UndeclaredAttribute, reader.Name);
                        }
                    }
                    catch (XmlSchemaException e)
                    {
                        e.SetSource(Reader.BaseURI, PositionInfo.LineNumber, PositionInfo.LinePosition);
                        SendValidationEvent(e);
                    }
                } while (Reader.MoveToNextAttribute());
                Reader.MoveToElement();
            }
        }
        public static void CheckDefaultValue(
            SchemaAttDef attdef,
            SchemaInfo sinfo,
            IDtdParserAdapter readerAdapter
            )
        {
            try {
                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null)
                {
                    return; // no reason to check
                }
                object typedValue = attdef.DefaultValueTyped;

                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY)
                {
                    Uri    baseUri    = readerAdapter.BaseUri;
                    string baseUriStr = (baseUri == null) ? string.Empty : baseUri.ToString();
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List)
                    {
                        string[] ss = (string[])typedValue;
                        foreach (string s in ss)
                        {
                            ProcessEntity(sinfo, s, readerAdapter, readerAdapter.EventHandler, baseUriStr, attdef.ValueLineNum, attdef.ValueLinePos);
                        }
                    }
                    else
                    {
                        ProcessEntity(sinfo, (string)typedValue, readerAdapter, readerAdapter.EventHandler, baseUriStr, attdef.ValueLineNum, attdef.ValueLinePos);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION)
                {
                    if (!attdef.CheckEnumeration(typedValue))
                    {
                        XmlSchemaException e = new XmlSchemaException(Res.Sch_EnumerationValue, typedValue.ToString(), readerAdapter.BaseUri.ToString(), attdef.ValueLineNum, attdef.ValueLinePos);
                        readerAdapter.SendValidationEvent(XmlSeverityType.Error, e);
                    }
                }
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch (Exception)  {
#endif
                XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString());
                readerAdapter.SendValidationEvent(XmlSeverityType.Error, e);
            }
        }
예제 #19
0
 // add a new SchemaAttDef to the SchemaElementDecl
 internal void AddAttDef(SchemaAttDef attdef)
 {
     _attdefs.Add(attdef.Name, attdef);
     if (attdef.Presence == SchemaDeclBase.Use.Required || attdef.Presence == SchemaDeclBase.Use.RequiredFixed)
     {
         _hasRequiredAttribute = true;
     }
     if (attdef.Presence == SchemaDeclBase.Use.Default || attdef.Presence == SchemaDeclBase.Use.Fixed)
     { //Not adding RequiredFixed here
         _defaultAttdefs ??= new List <IDtdDefaultAttributeInfo>();
         _defaultAttdefs.Add(attdef);
     }
 }
예제 #20
0
            internal void Reset() {
                _Name = XmlQualifiedName.Empty;
                _Prefix = null;
		        _TypeName = XmlQualifiedName.Empty;
                _TypePrefix = null;
                _Default = null;
                _Revises = null;
                _MaxOccurs = 1;
                _MinOccurs = 1;
                _Checking = false;
                _ElementDecl = null;
                _Next = null;
                _Attdef = null;
            }
 private void ValidateStartElement()
 {
     if (base.context.ElementDecl != null)
     {
         base.Reader.SchemaTypeObject = base.context.ElementDecl.SchemaType;
         if (base.Reader.IsEmptyElement && (base.context.ElementDecl.DefaultValueTyped != null))
         {
             base.Reader.TypedValueObject = base.context.ElementDecl.DefaultValueTyped;
             base.context.IsNill          = true;
         }
         if (base.context.ElementDecl.HasRequiredAttribute)
         {
             this.attPresence.Clear();
         }
     }
     if (base.Reader.MoveToFirstAttribute())
     {
         do
         {
             try
             {
                 base.reader.SchemaTypeObject = null;
                 SchemaAttDef attDef = base.context.ElementDecl.GetAttDef(new XmlQualifiedName(base.reader.LocalName, base.reader.Prefix));
                 if (attDef != null)
                 {
                     if ((base.context.ElementDecl != null) && base.context.ElementDecl.HasRequiredAttribute)
                     {
                         this.attPresence.Add(attDef.Name, attDef);
                     }
                     base.Reader.SchemaTypeObject = attDef.SchemaType;
                     if ((attDef.Datatype != null) && !base.reader.IsDefault)
                     {
                         this.CheckValue(base.Reader.Value, attDef);
                     }
                 }
                 else
                 {
                     base.SendValidationEvent("Sch_UndeclaredAttribute", base.reader.Name);
                 }
             }
             catch (XmlSchemaException exception)
             {
                 exception.SetSource(base.Reader.BaseURI, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition);
                 base.SendValidationEvent(exception);
             }
         }while (base.Reader.MoveToNextAttribute());
         base.Reader.MoveToElement();
     }
 }
 internal void AddAttDef(SchemaAttDef attdef)
 {
     this.attdefs.Add(attdef.Name, attdef);
     if ((attdef.Presence == SchemaDeclBase.Use.Required) || (attdef.Presence == SchemaDeclBase.Use.RequiredFixed))
     {
         this.hasRequiredAttribute = true;
     }
     if ((attdef.Presence == SchemaDeclBase.Use.Default) || (attdef.Presence == SchemaDeclBase.Use.Fixed))
     {
         if (this.defaultAttdefs == null)
         {
             this.defaultAttdefs = new List<IDtdDefaultAttributeInfo>();
         }
         this.defaultAttdefs.Add(attdef);
     }
 }
예제 #23
0
 // add a new SchemaAttDef to the SchemaElementDecl
 public void AddAttDef(SchemaAttDef attdef)
 {
     attdefs.Add(attdef.Name, attdef);
     if (attdef.Presence == SchemaDeclBase.Use.Required || attdef.Presence == SchemaDeclBase.Use.RequiredFixed)
     {
         hasRequiredAttribute = true;
     }
     if (attdef.Presence == SchemaDeclBase.Use.Default || attdef.Presence == SchemaDeclBase.Use.Fixed)   //Not adding RequiredFixed here
     {
         if (tmpDefaultAttdefs == null)
         {
             tmpDefaultAttdefs = new ArrayList();
         }
         tmpDefaultAttdefs.Add(attdef);
     }
 }
예제 #24
0
 internal void AddAttDef(SchemaAttDef attdef)
 {
     this.attdefs.Add(attdef.Name, attdef);
     if ((attdef.Presence == SchemaDeclBase.Use.Required) || (attdef.Presence == SchemaDeclBase.Use.RequiredFixed))
     {
         this.hasRequiredAttribute = true;
     }
     if ((attdef.Presence == SchemaDeclBase.Use.Default) || (attdef.Presence == SchemaDeclBase.Use.Fixed))
     {
         if (this.defaultAttdefs == null)
         {
             this.defaultAttdefs = new List <IDtdDefaultAttributeInfo>();
         }
         this.defaultAttdefs.Add(attdef);
     }
 }
예제 #25
0
        // add a new SchemaAttDef to the SchemaElementDecl
        internal void AddAttDef(SchemaAttDef attdef)
        {
            attdefs.Add(attdef.Name, attdef);
#if !SILVERLIGHT
            if (attdef.Presence == SchemaDeclBase.Use.Required || attdef.Presence == SchemaDeclBase.Use.RequiredFixed)
            {
                hasRequiredAttribute = true;
            }
#endif
            if (attdef.Presence == SchemaDeclBase.Use.Default || attdef.Presence == SchemaDeclBase.Use.Fixed)   //Not adding RequiredFixed here
            {
                if (defaultAttdefs == null)
                {
                    defaultAttdefs = new List <IDtdDefaultAttributeInfo>();
                }
                defaultAttdefs.Add(attdef);
            }
        }
 public static void CheckDefaultValue(SchemaAttDef attdef, SchemaInfo sinfo, IValidationEventHandling eventHandling, string baseUriStr)
 {
     try
     {
         if (baseUriStr == null)
         {
             baseUriStr = string.Empty;
         }
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             object defaultValueTyped = attdef.DefaultValueTyped;
             XmlTokenizedType tokenizedType = datatype.TokenizedType;
             if (tokenizedType == XmlTokenizedType.ENTITY)
             {
                 if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                 {
                     string[] strArray = (string[]) defaultValueTyped;
                     for (int i = 0; i < strArray.Length; i++)
                     {
                         BaseValidator.ProcessEntity(sinfo, strArray[i], eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                     }
                 }
                 else
                 {
                     BaseValidator.ProcessEntity(sinfo, (string) defaultValueTyped, eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 }
             }
             else if (((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(defaultValueTyped)) && (eventHandling != null))
             {
                 XmlSchemaException exception = new XmlSchemaException("Sch_EnumerationValue", defaultValueTyped.ToString(), baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 eventHandling.SendEvent(exception, XmlSeverityType.Error);
             }
         }
     }
     catch (Exception)
     {
         if (eventHandling != null)
         {
             XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString());
             eventHandling.SendEvent(exception2, XmlSeverityType.Error);
         }
     }
 }
 public static void CheckDefaultValue(SchemaAttDef attdef, SchemaInfo sinfo, IValidationEventHandling eventHandling, string baseUriStr)
 {
     try
     {
         if (baseUriStr == null)
         {
             baseUriStr = string.Empty;
         }
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             object           defaultValueTyped = attdef.DefaultValueTyped;
             XmlTokenizedType tokenizedType     = datatype.TokenizedType;
             if (tokenizedType == XmlTokenizedType.ENTITY)
             {
                 if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                 {
                     string[] strArray = (string[])defaultValueTyped;
                     for (int i = 0; i < strArray.Length; i++)
                     {
                         BaseValidator.ProcessEntity(sinfo, strArray[i], eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                     }
                 }
                 else
                 {
                     BaseValidator.ProcessEntity(sinfo, (string)defaultValueTyped, eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 }
             }
             else if (((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(defaultValueTyped)) && (eventHandling != null))
             {
                 XmlSchemaException exception = new XmlSchemaException("Sch_EnumerationValue", defaultValueTyped.ToString(), baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 eventHandling.SendEvent(exception, XmlSeverityType.Error);
             }
         }
     }
     catch (Exception)
     {
         if (eventHandling != null)
         {
             XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString());
             eventHandling.SendEvent(exception2, XmlSeverityType.Error);
         }
     }
 }
예제 #28
0
파일: validator.cs 프로젝트: ArildF/masters
        internal Validator(XmlNameTable nameTable, SchemaNames schemaNames, XmlValidatingReader reader) {
            this.nameTable = nameTable;
            this.schemaNames = schemaNames;
            this.reader = reader;
            positionInfo = PositionInfo.GetPositionInfo(reader);
            nsManager = reader.NamespaceManager;
            if (nsManager == null) {
                nsManager = new XmlNamespaceManager(nameTable);
                isProcessContents = true;
            }
            SchemaInfo = new SchemaInfo(schemaNames);

            validationStack = new HWStack(STACK_INCREMENT);
            textValue = new StringBuilder();
            this.name = XmlQualifiedName.Empty;
            attPresence = new Hashtable();
            context = null;
            attnDef = null;
        }
        internal SchemaAttDef GetAttributeXdr(SchemaElementDecl ed, XmlQualifiedName qname)
        {
            SchemaAttDef attdef = null;

            if (ed != null)
            {
                attdef = ed.GetAttDef(qname);;
                if (attdef == null)
                {
                    if (!ed.ContentValidator.IsOpen || qname.Namespace.Length == 0)
                    {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                    }
                    if (!attributeDecls.TryGetValue(qname, out attdef) && targetNamespaces.ContainsKey(qname.Namespace))
                    {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                    }
                }
            }
            return(attdef);
        }
예제 #30
0
파일: DtdParser.cs 프로젝트: chcosta/corefx
        private void ParseAttlistDecl()
        {
            if (GetToken(true) != Token.QName)
            {
                goto UnexpectedError;
            }

            // element name
            XmlQualifiedName elementName = GetNameQualified(true);
            SchemaElementDecl elementDecl;
            if (!_schemaInfo.ElementDecls.TryGetValue(elementName, out elementDecl))
            {
                if (!_schemaInfo.UndeclaredElementDecls.TryGetValue(elementName, out elementDecl))
                {
                    elementDecl = new SchemaElementDecl(elementName, elementName.Namespace);
                    _schemaInfo.UndeclaredElementDecls.Add(elementName, elementDecl);
                }
            }

            SchemaAttDef attrDef = null;
            for (;;)
            {
                switch (GetToken(false))
                {
                    case Token.QName:
                        XmlQualifiedName attrName = GetNameQualified(true);
                        attrDef = new SchemaAttDef(attrName, attrName.Namespace);
                        attrDef.IsDeclaredInExternal = !ParsingInternalSubset;
                        attrDef.LineNumber = (int)LineNo;
                        attrDef.LinePosition = (int)LinePos - (_curPos - _tokenStartPos);
                        break;
                    case Token.GreaterThan:
#if !SILVERLIGHT
                        if (_v1Compat)
                        {
                            // check xml:space and xml:lang
                            // BUG BUG: For backward compatibility, we check the correct type and values of the
                            // xml:space attribute only on the last attribute in the list.
                            // See Webdata bugs #97457 and #93935.
                            if (attrDef != null && attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals("xml") && attrDef.Name.Name == "space")
                            {
                                attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                                if (attrDef.Datatype.TokenizedType != XmlTokenizedType.ENUMERATION)
                                {
                                    Throw(SR.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition);
                                }
                                if (_validate)
                                {
                                    attrDef.CheckXmlSpace(_readerAdapterWithValidation.ValidationEventHandling);
                                }
                            }
                        }
#endif
                        return;
                    default:
                        goto UnexpectedError;
                }

                bool attrDefAlreadyExists = (elementDecl.GetAttDef(attrDef.Name) != null);

                ParseAttlistType(attrDef, elementDecl, attrDefAlreadyExists);
                ParseAttlistDefault(attrDef, attrDefAlreadyExists);

                // check xml:space and xml:lang
                if (attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals("xml"))
                {
                    if (attrDef.Name.Name == "space")
                    {
#if !SILVERLIGHT
                        if (_v1Compat)
                        {
                            // BUG BUG: For backward compatibility, we check the correct type and values of the
                            // xml:space attribute only on the last attribute in the list, and mark it as reserved 
                            // only its value is correct (=prevent XmlTextReader from fhrowing on invalid value). 
                            // See Webdata bugs #98168, #97457 and #93935.
                            string val = attrDef.DefaultValueExpanded.Trim();
                            if (val.Equals("preserve") || val.Equals("default"))
                            {
                                attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                            }
                        }
                        else
                        {
#endif
                            attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                            if (attrDef.TokenizedType != XmlTokenizedType.ENUMERATION)
                            {
                                Throw(SR.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition);
                            }
#if !SILVERLIGHT
                            if (_validate)
                            {
                                attrDef.CheckXmlSpace(_readerAdapterWithValidation.ValidationEventHandling);
                            }
                        }
#endif
                    }
                    else if (attrDef.Name.Name == "lang")
                    {
                        attrDef.Reserved = SchemaAttDef.Reserve.XmlLang;
                    }
                }

                // add attribute to element decl
                if (!attrDefAlreadyExists)
                {
                    elementDecl.AddAttDef(attrDef);
                }
            }

        UnexpectedError:
            OnUnexpectedError();
        }
 private void CheckValue(string value, SchemaAttDef attdef)
 {
     try
     {
         base.reader.TypedValueObject = null;
         bool flag = attdef != null;
         XmlSchemaDatatype datatype = flag ? attdef.Datatype : base.context.ElementDecl.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 value = value.Trim();
             }
             if (value.Length != 0)
             {
                 object pVal = datatype.ParseValue(value, base.NameTable, this.nsManager);
                 base.reader.TypedValueObject = pVal;
                 switch (datatype.TokenizedType)
                 {
                 case XmlTokenizedType.ENTITY:
                 case XmlTokenizedType.ID:
                 case XmlTokenizedType.IDREF:
                     if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                     {
                         string[] strArray = (string[])pVal;
                         for (int i = 0; i < strArray.Length; i++)
                         {
                             this.ProcessTokenizedType(datatype.TokenizedType, strArray[i]);
                         }
                     }
                     else
                     {
                         this.ProcessTokenizedType(datatype.TokenizedType, (string)pVal);
                     }
                     break;
                 }
                 SchemaDeclBase base2 = flag ? ((SchemaDeclBase)attdef) : ((SchemaDeclBase)base.context.ElementDecl);
                 if ((base2.MaxLength != 0xffffffffL) && (value.Length > base2.MaxLength))
                 {
                     base.SendValidationEvent("Sch_MaxLengthConstraintFailed", value);
                 }
                 if ((base2.MinLength != 0xffffffffL) && (value.Length < base2.MinLength))
                 {
                     base.SendValidationEvent("Sch_MinLengthConstraintFailed", value);
                 }
                 if ((base2.Values != null) && !base2.CheckEnumeration(pVal))
                 {
                     if (datatype.TokenizedType == XmlTokenizedType.NOTATION)
                     {
                         base.SendValidationEvent("Sch_NotationValue", pVal.ToString());
                     }
                     else
                     {
                         base.SendValidationEvent("Sch_EnumerationValue", pVal.ToString());
                     }
                 }
                 if (!base2.CheckValue(pVal))
                 {
                     if (flag)
                     {
                         base.SendValidationEvent("Sch_FixedAttributeValue", attdef.Name.ToString());
                     }
                     else
                     {
                         base.SendValidationEvent("Sch_FixedElementValue", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace));
                     }
                 }
             }
         }
     }
     catch (XmlSchemaException)
     {
         if (attdef != null)
         {
             base.SendValidationEvent("Sch_AttributeValueDataType", attdef.Name.ToString());
         }
         else
         {
             base.SendValidationEvent("Sch_ElementValueDataType", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace));
         }
     }
 }
예제 #32
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        private void XDR_CheckAttributeDefault(DeclBaseInfo decl, SchemaAttDef pAttdef)
        {
            if (decl._Default != null || pAttdef.DefaultValueTyped != null)
            {
                if (decl._Default != null)
                {
                    pAttdef.DefaultValueRaw = pAttdef.DefaultValueExpanded = (string)decl._Default;
                    CheckDefaultAttValue(pAttdef);
                }
            }

            SetAttributePresence(pAttdef, 1 == decl._MinOccurs);
        }
예제 #33
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private void CheckDefaultAttValue(SchemaAttDef attDef)
 {
     string str = (attDef.DefaultValueRaw).Trim();
     XdrValidator.CheckDefaultValue(str, attDef, _SchemaInfo, _CurNsMgr, _NameTable, null, _validationEventHandler, _reader.BaseURI, _positionInfo.LineNumber, _positionInfo.LinePosition);
 }
 private object CheckAttributeValue(object value, SchemaAttDef attdef)
 {
     object typedValue = null;
     SchemaDeclBase decl = attdef;
     XmlSchemaDatatype datatype = attdef.Datatype;
     string s = value as string;
     Exception innerException = null;
     if (s != null)
     {
         innerException = datatype.TryParseValue(s, this.nameTable, this.nsResolver, out typedValue);
         if (innerException == null)
         {
             goto Label_0050;
         }
         goto Label_0078;
     }
     innerException = datatype.TryParseValue(value, this.nameTable, this.nsResolver, out typedValue);
     if (innerException != null)
     {
         goto Label_0078;
     }
 Label_0050:
     if (!decl.CheckValue(typedValue))
     {
         this.attrValid = false;
         this.SendValidationEvent("Sch_FixedAttributeValue", attdef.Name.ToString());
     }
     return typedValue;
 Label_0078:
     this.attrValid = false;
     if (s == null)
     {
         s = XmlSchemaDatatype.ConcatenatedToString(value);
     }
     this.SendValidationEvent("Sch_AttributeValueDataTypeDetailed", new string[] { attdef.Name.ToString(), s, this.GetTypeName(decl), innerException.Message }, innerException);
     return null;
 }
예제 #35
0
        internal bool AddDefaultAttributeNonDtd(SchemaAttDef attrDef)
        {
            // atomize names - Xsd Validator does not need to have the same nametable
            string localName = _nameTable.Add(attrDef.Name.Name);
            string prefix = _nameTable.Add(attrDef.Prefix);
            string ns = _nameTable.Add(attrDef.Name.Namespace);

            // atomize namespace - Xsd Validator does not need to have the same nametable
            if (prefix.Length == 0 && ns.Length > 0)
            {
                prefix = _namespaceManager.LookupPrefix(ns);

                Debug.Assert(prefix != null);
                if (prefix == null)
                {
                    prefix = string.Empty;
                }
            }

            // find out if the attribute is already there
            for (int i = _index + 1; i < _index + 1 + _attrCount; i++)
            {
                if ((object)_nodes[i].localName == (object)localName &&
                    (((object)_nodes[i].prefix == (object)prefix) || ((object)_nodes[i].ns == (object)ns && ns != null)))
                {
                    return false;
                }
            }

            // attribute does not exist -> we need to add it
            NodeData attr = AddDefaultAttributeInternal(localName, ns, prefix, attrDef.DefaultValueExpanded,
                                                         attrDef.LineNumber, attrDef.LinePosition,
                                                         attrDef.ValueLineNumber, attrDef.ValueLinePosition, attrDef.Reserved != SchemaAttDef.Reserve.None);
            Debug.Assert(attr != null);

            attr.schemaType = (attrDef.SchemaType == null) ? (object)attrDef.Datatype : (object)attrDef.SchemaType;
            attr.typedValue = attrDef.DefaultValueTyped;
            return true;
        }
예제 #36
0
        private async Task ParseAttlistDeclAsync() {
            if (await GetTokenAsync(true).ConfigureAwait(false) != Token.QName) {
                goto UnexpectedError;
            }

            // element name
            XmlQualifiedName elementName = GetNameQualified(true);
            SchemaElementDecl elementDecl;
            if (!schemaInfo.ElementDecls.TryGetValue(elementName, out elementDecl)) {
                if (!schemaInfo.UndeclaredElementDecls.TryGetValue(elementName, out elementDecl)) {
                    elementDecl = new SchemaElementDecl(elementName, elementName.Namespace);
                    schemaInfo.UndeclaredElementDecls.Add(elementName, elementDecl);
                }
            }

            SchemaAttDef attrDef = null;
            for (; ; ) {
                switch (await GetTokenAsync(false).ConfigureAwait(false)) {
                    case Token.QName:
                        XmlQualifiedName attrName = GetNameQualified(true);
                        attrDef = new SchemaAttDef(attrName, attrName.Namespace);
                        attrDef.IsDeclaredInExternal = !ParsingInternalSubset;
                        attrDef.LineNumber = (int)LineNo;
                        attrDef.LinePosition = (int)LinePos - (curPos - tokenStartPos);
                        break;
                    case Token.GreaterThan:
#if !SILVERLIGHT
                        if ( v1Compat ) {
                            // check xml:space and xml:lang
                            // 


                            if ( attrDef != null && attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals( "xml" ) && attrDef.Name.Name == "space" ) {
                                attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                                if ( attrDef.Datatype.TokenizedType != XmlTokenizedType.ENUMERATION ) {
                                    Throw( Res.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition );
                                }
                                if ( validate ) {
                                    attrDef.CheckXmlSpace( readerAdapterWithValidation.ValidationEventHandling );
                                }
                            }
                        }
#endif
                        return;
                    default:
                        goto UnexpectedError;
                }

                bool attrDefAlreadyExists = (elementDecl.GetAttDef(attrDef.Name) != null);

                await ParseAttlistTypeAsync(attrDef, elementDecl, attrDefAlreadyExists).ConfigureAwait(false);
                await ParseAttlistDefaultAsync(attrDef, attrDefAlreadyExists).ConfigureAwait(false);

                // check xml:space and xml:lang
                if (attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals("xml")) {
                    if ( attrDef.Name.Name == "space" ) {
#if !SILVERLIGHT
                        if ( v1Compat ) {
                            // 



                            string val = attrDef.DefaultValueExpanded.Trim();
                            if ( val.Equals( "preserve" ) || val.Equals( "default" ) ) {
                                attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                            }
                        }
                        else {
#endif
                            attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                            if ( attrDef.TokenizedType != XmlTokenizedType.ENUMERATION ) {
                                Throw( Res.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition );
                            }
#if !SILVERLIGHT
                            if ( validate ) {
                                attrDef.CheckXmlSpace( readerAdapterWithValidation.ValidationEventHandling );
                            }
                        }
#endif
                    }
                    else if ( attrDef.Name.Name == "lang" ) {
                        attrDef.Reserved = SchemaAttDef.Reserve.XmlLang;
                    }
                }

                // add attribute to element decl
                if (!attrDefAlreadyExists) {
                    elementDecl.AddAttDef(attrDef);
                }
            }

        UnexpectedError:
            OnUnexpectedError();
        }
 private void SetDefaultFixed(XmlSchemaAttribute xa, SchemaAttDef decl) {
     if (xa.DefaultValue != null || xa.FixedValue != null) {
         if (xa.DefaultValue != null) {
             decl.Presence = SchemaDeclBase.Use.Default; 
             decl.DefaultValueRaw = decl.DefaultValueExpanded = xa.DefaultValue;
         }
         else {
             if (xa.Use == XmlSchemaUse.Required) {
                 decl.Presence = SchemaDeclBase.Use.RequiredFixed;
             }
             else {
                 decl.Presence = SchemaDeclBase.Use.Fixed; 
             }
             decl.DefaultValueRaw = decl.DefaultValueExpanded = xa.FixedValue;
         }
         if(decl.Datatype != null) {
             if (decl.Datatype.TypeCode == XmlTypeCode.Id) {
                 SendValidationEvent(Res.Sch_DefaultIdValue, xa);
             }
             else {
                 decl.DefaultValueTyped = decl.Datatype.ParseValue(decl.DefaultValueRaw, NameTable, new SchemaNamespaceManager(xa), true);
             }
         }
     }
     else {
         switch (xa.Use) {
             case XmlSchemaUse.None: 
             case XmlSchemaUse.Optional: 
                 decl.Presence = SchemaDeclBase.Use.Implied; 
                 break;
             case XmlSchemaUse.Required: 
                 decl.Presence = SchemaDeclBase.Use.Required; 
                 break;
             case XmlSchemaUse.Prohibited:
                 break;
         }
     }
 }
예제 #38
0
        public static void CheckDefaultValue(
            string value,
            SchemaAttDef attdef,
            SchemaInfo sinfo,
            XmlNamespaceManager nsManager,
            XmlNameTable NameTable,
            object sender,
            ValidationEventHandler eventhandler,
            string baseUri,
            int lineNo,
            int linePos
            )
        {
            try
            {
                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null)
                {
                    return; // no reason to check
                }

                if (dtype.TokenizedType != XmlTokenizedType.CDATA)
                {
                    value = value.Trim();
                }
                if (value.Length == 0)
                {
                    return; // don't need to check
                }
                object typedValue = dtype.ParseValue(value, NameTable, nsManager);

                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY)
                {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List)
                    {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i)
                        {
                            ProcessEntity(sinfo, ss[i], sender, eventhandler, baseUri, lineNo, linePos);
                        }
                    }
                    else
                    {
                        ProcessEntity(sinfo, (string)typedValue, sender, eventhandler, baseUri, lineNo, linePos);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION)
                {
                    if (!attdef.CheckEnumeration(typedValue))
                    {
                        XmlSchemaException e = new XmlSchemaException(SR.Sch_EnumerationValue, typedValue.ToString(), baseUri, lineNo, linePos);
                        if (eventhandler != null)
                        {
                            eventhandler(sender, new ValidationEventArgs(e));
                        }
                        else
                        {
                            throw e;
                        }
                    }
                }
                attdef.DefaultValueTyped = typedValue;
            }
#if DEBUG
            catch (XmlSchemaException ex)
            {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch
            {
#endif
                XmlSchemaException e = new XmlSchemaException(SR.Sch_AttributeDefaultDataType, attdef.Name.ToString(), baseUri, lineNo, linePos);
                if (eventhandler != null)
                {
                    eventhandler(sender, new ValidationEventArgs(e));
                }
                else
                {
                    throw e;
                }
            }
        }
        internal SchemaAttDef GetAttributeXsd(SchemaElementDecl ed, XmlQualifiedName qname, XmlSchemaObject partialValidationType, out AttributeMatchState attributeMatchState)
        {
            SchemaAttDef attdef = null;

            attributeMatchState = AttributeMatchState.UndeclaredAttribute;
            if (ed != null)
            {
                attdef = ed.GetAttDef(qname);
                if (attdef != null)
                {
                    attributeMatchState = AttributeMatchState.AttributeFound;
                    return(attdef);
                }
                XmlSchemaAnyAttribute any = ed.AnyAttribute;
                if (any != null)
                {
                    if (!any.NamespaceList.Allows(qname))
                    {
                        attributeMatchState = AttributeMatchState.ProhibitedAnyAttribute;
                    }
                    else if (any.ProcessContentsCorrect != XmlSchemaContentProcessing.Skip)
                    {
                        if (attributeDecls.TryGetValue(qname, out attdef))
                        {
                            if (attdef.Datatype.TypeCode == XmlTypeCode.Id)   //anyAttribute match whose type is ID
                            {
                                attributeMatchState = AttributeMatchState.AnyIdAttributeFound;
                            }
                            else
                            {
                                attributeMatchState = AttributeMatchState.AttributeFound;
                            }
                        }
                        else if (any.ProcessContentsCorrect == XmlSchemaContentProcessing.Lax)
                        {
                            attributeMatchState = AttributeMatchState.AnyAttributeLax;
                        }
                    }
                    else
                    {
                        attributeMatchState = AttributeMatchState.AnyAttributeSkip;
                    }
                }
                else if (ed.ProhibitedAttributes.ContainsKey(qname))
                {
                    attributeMatchState = AttributeMatchState.ProhibitedAttribute;
                }
            }
            else if (partialValidationType != null)
            {
                XmlSchemaAttribute attr = partialValidationType as XmlSchemaAttribute;
                if (attr != null)
                {
                    if (qname.Equals(attr.QualifiedName))
                    {
                        attdef = attr.AttDef;
                        attributeMatchState = AttributeMatchState.AttributeFound;
                    }
                    else
                    {
                        attributeMatchState = AttributeMatchState.AttributeNameMismatch;
                    }
                }
                else
                {
                    attributeMatchState = AttributeMatchState.ValidateAttributeInvalidCall;
                }
            }
            else
            {
                if (attributeDecls.TryGetValue(qname, out attdef))
                {
                    attributeMatchState = AttributeMatchState.AttributeFound;
                }
                else
                {
                    attributeMatchState = AttributeMatchState.UndeclaredElementAndAttribute;
                }
            }
            return(attdef);
        }
예제 #40
0
        internal SchemaAttDef GetAttribute(SchemaElementDecl ed, XmlQualifiedName qname, ref bool skip)
        {
            SchemaAttDef attdef = null;

            if (ed != null)   // local attribute or XSD
            {
                skip   = false;
                attdef = ed.GetAttDef(qname);
                if (attdef == null)
                {
                    // In DTD, every attribute must be declared.
                    if (schemaType == SchemaType.DTD)
                    {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                    }
                    else if (schemaType == SchemaType.XDR)
                    {
                        if (ed.Content.IsOpen)
                        {
                            attdef = (SchemaAttDef)attributeDecls[qname];
                            if ((attdef == null) && ((qname.Namespace == String.Empty) || HasSchema(qname.Namespace)))
                            {
                                throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                            }
                        }
                        else
                        {
                            throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                        }
                    }
                    else   //XML Schema
                    {
                        XmlSchemaAnyAttribute any = ed.AnyAttribute;
                        if (any != null)
                        {
                            if (any.NamespaceList.Allows(qname))
                            {
                                if (any.ProcessContentsCorrect != XmlSchemaContentProcessing.Skip)
                                {
                                    attdef = (SchemaAttDef)attributeDecls[qname];
                                    if (attdef == null && any.ProcessContentsCorrect == XmlSchemaContentProcessing.Strict)
                                    {
                                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                                    }
                                }
                                else
                                {
                                    skip = true;
                                }
                            }
                            else
                            {
                                throw new XmlSchemaException(Res.Sch_ProhibitedAttribute, qname.ToString());
                            }
                        }
                        else if (ed.ProhibitedAttributes[qname] != null)
                        {
                            throw new XmlSchemaException(Res.Sch_ProhibitedAttribute, qname.ToString());
                        }
                        else
                        {
                            throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                        }
                    }
                }
            }
            else   // global attribute
            {
                if (!skip)
                {
                    attdef = (SchemaAttDef)attributeDecls[qname];
                    if ((attdef == null) && HasSchema(qname.Namespace))
                    {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                    }
                }
            }
            return(attdef);
        }
        private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo) {
            if (lName == null) {
                throw new ArgumentNullException("localName");
            }
            if (ns == null) {
                throw new ArgumentNullException("namespaceUri");
            }

            ValidatorState toState = validationStack.Length > 1 ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute;
            CheckStateTransition(toState, MethodNames[(int)toState]);

            object typedVal = null;
            attrValid = true;
            XmlSchemaValidity localValidity = XmlSchemaValidity.NotKnown;
            XmlSchemaAttribute localAttribute = null;
            XmlSchemaSimpleType localMemberType = null;

            ns = nameTable.Add(ns);
            if(Ref.Equal(ns,NsXmlNs)) {
                return null;
            }

            SchemaAttDef attributeDef = null;
            SchemaElementDecl currentElementDecl = context.ElementDecl;
            XmlQualifiedName attQName = new XmlQualifiedName(lName, ns);
            if (attPresence[attQName] != null) { //this attribute already checked as it is duplicate;
                SendValidationEvent(Res.Sch_DuplicateAttribute, attQName.ToString());
                if (schemaInfo != null) {
                    schemaInfo.Clear();
                }
                return null;
            }

            if (!Ref.Equal(ns,NsXsi)) { //
                XmlSchemaObject pvtAttribute = currentState == ValidatorState.TopLevelAttribute ? partialValidationType : null;
                AttributeMatchState attributeMatchState;
                attributeDef = compiledSchemaInfo.GetAttributeXsd(currentElementDecl, attQName, pvtAttribute, out attributeMatchState);

                switch (attributeMatchState) {
                    case AttributeMatchState.UndeclaredElementAndAttribute:
                        if((attributeDef = CheckIsXmlAttribute(attQName)) != null) { //Try for xml attribute
                            goto case AttributeMatchState.AttributeFound;
                        }
                        if (currentElementDecl == null
                            && processContents == XmlSchemaContentProcessing.Strict
                            && attQName.Namespace.Length != 0
                            && compiledSchemaInfo.Contains(attQName.Namespace)
                        ) {
                            attrValid = false;
                            SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString());
                        }
                        else if (processContents != XmlSchemaContentProcessing.Skip) {
                            SendValidationEvent(Res.Sch_NoAttributeSchemaFound, attQName.ToString(), XmlSeverityType.Warning);
                        }
                        break;

                    case AttributeMatchState.UndeclaredAttribute:
                        if((attributeDef = CheckIsXmlAttribute(attQName)) != null) {
                            goto case AttributeMatchState.AttributeFound;
                        }
                        else {
                            attrValid = false;
                            SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString());
                        }
                        break;

                    case AttributeMatchState.ProhibitedAnyAttribute:
                        if((attributeDef = CheckIsXmlAttribute(attQName)) != null) {
                            goto case AttributeMatchState.AttributeFound;
                        }
                        else {
                            attrValid = false;
                            SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString());
                        }
                        break;

                    case AttributeMatchState.ProhibitedAttribute:
                        attrValid = false;
                        SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString());
                        break;

                    case AttributeMatchState.AttributeNameMismatch:
                        attrValid = false;
                        SendValidationEvent(Res.Sch_SchemaAttributeNameMismatch, new string[] { attQName.ToString(), ((XmlSchemaAttribute)pvtAttribute).QualifiedName.ToString()});
                        break;

                    case AttributeMatchState.ValidateAttributeInvalidCall:
                        Debug.Assert(currentState == ValidatorState.TopLevelAttribute); //Re-set state back to start on error with partial validation type
                        currentState = ValidatorState.Start;
                        attrValid = false;
                        SendValidationEvent(Res.Sch_ValidateAttributeInvalidCall, string.Empty);
                        break;

                    case AttributeMatchState.AnyIdAttributeFound:
                        if (wildID == null) {
                            wildID = attributeDef;
                            Debug.Assert(currentElementDecl != null);
                            XmlSchemaComplexType ct = currentElementDecl.SchemaType as XmlSchemaComplexType;
                            Debug.Assert(ct != null);
                            if (ct.ContainsIdAttribute(false)) {
                                SendValidationEvent(Res.Sch_AttrUseAndWildId, string.Empty);
                            }
                            else {
                                goto case AttributeMatchState.AttributeFound;
                            }
                        }
                        else { //More than one attribute per element cannot match wildcard if both their types are derived from ID
                            SendValidationEvent(Res.Sch_MoreThanOneWildId, string.Empty);
                        }
                        break;

                    case AttributeMatchState.AttributeFound:
                        Debug.Assert(attributeDef != null);
                        localAttribute = attributeDef.SchemaAttribute;
                        if (currentElementDecl != null) { //Have to add to hashtable to check whether to add default attributes
                            attPresence.Add(attQName, attributeDef);
                        }
                        object attValue;
                        if (attributeValueGetter != null) {
                            attValue = attributeValueGetter();
                        }
                        else {
                            attValue = attributeStringValue;
                        }
                        typedVal = CheckAttributeValue(attValue, attributeDef);
                        XmlSchemaDatatype datatype = attributeDef.Datatype;
                        if (datatype.Variety == XmlSchemaDatatypeVariety.Union && typedVal != null) { //Unpack the union
                            XsdSimpleValue simpleValue = typedVal as XsdSimpleValue;
                            Debug.Assert(simpleValue != null);

                            localMemberType = simpleValue.XmlType;
                            datatype = simpleValue.XmlType.Datatype;
                            typedVal = simpleValue.TypedValue;
                        }
                        CheckTokenizedTypes(datatype, typedVal, true);
                        if (HasIdentityConstraints) {
                            AttributeIdentityConstraints(attQName.Name, attQName.Namespace, typedVal, attValue.ToString(), datatype);
                        }
                        break;

                    case AttributeMatchState.AnyAttributeLax:
                        SendValidationEvent(Res.Sch_NoAttributeSchemaFound, attQName.ToString(), XmlSeverityType.Warning);
                        break;

                    case AttributeMatchState.AnyAttributeSkip:
                        break;

                    default:
                        break;
                }
            }
            else { //Attribute from xsi namespace
                lName = nameTable.Add(lName);
                if (Ref.Equal(lName, xsiTypeString) || Ref.Equal(lName, xsiNilString) || Ref.Equal(lName, xsiSchemaLocationString) || Ref.Equal(lName, xsiNoNamespaceSchemaLocationString)) {
                    attPresence.Add(attQName, SchemaAttDef.Empty);
                }
                else {
                    attrValid = false;
                    SendValidationEvent(Res.Sch_NotXsiAttribute, attQName.ToString());
                }
            }

            if (!attrValid) {
                localValidity = XmlSchemaValidity.Invalid;
            }
            else if (attributeDef != null) {
                localValidity = XmlSchemaValidity.Valid;
            }
            if (schemaInfo != null) {
                schemaInfo.SchemaAttribute = localAttribute;
                schemaInfo.SchemaType = localAttribute == null ? null : localAttribute.AttributeSchemaType;
                schemaInfo.MemberType = localMemberType;
                schemaInfo.IsDefault = false;
                schemaInfo.Validity = localValidity;
            }
            if (ProcessSchemaHints) {
                if (validatedNamespaces[ns] == null) {
                    validatedNamespaces.Add(ns, ns);
                }
            }
            return typedVal;
        }
 private void ClearPSVI() {
     if (textValue != null) {
         textValue.Length = 0;
     }
     attPresence.Clear(); //Clear attributes hashtable for every element
     wildID = null; //clear it for every element
 }
예제 #43
0
        private void ParseAttlistType( SchemaAttDef attrDef, SchemaElementDecl elementDecl ) {
            Token token = GetToken( true );

            if ( token != Token.CDATA ) {
                elementDecl.HasNonCDataAttribute = true;
            }
            
            if ( IsAttributeValueType( token ) ) {
                attrDef.Datatype = XmlSchemaDatatype.FromXmlTokenizedType( (XmlTokenizedType)(int)token );
                attrDef.SchemaType = XmlSchemaType.GetBuiltInSimpleType( attrDef.Datatype.TypeCode );

                switch ( token ) {
                    case Token.NOTATION:
                        break;
                    case Token.ID:
                        if ( validate && elementDecl.IsIdDeclared ) {
                            SchemaAttDef idAttrDef = elementDecl.GetAttDef( attrDef.Name );
                            if ( idAttrDef == null || idAttrDef.Datatype.TokenizedType != XmlTokenizedType.ID ) {
                                SendValidationEvent( XmlSeverityType.Error, Res.Sch_IdAttrDeclared, elementDecl.Name.ToString() );
                            }
                        }
                        elementDecl.IsIdDeclared = true;
                        return;
                    default:
                        return;
                }
                // check notation constrains
                if ( validate ) {
                    if ( elementDecl.IsNotationDeclared ) {
                        SendValidationEvent( curPos - 8, XmlSeverityType.Error, Res.Sch_DupNotationAttribute, elementDecl.Name.ToString() ); // 8 == strlen("NOTATION")
                    }
                    else {
                        if ( elementDecl.ContentValidator != null && 
                            elementDecl.ContentValidator.ContentType == XmlSchemaContentType.Empty ) {
                            SendValidationEvent( curPos - 8, XmlSeverityType.Error, Res.Sch_NotationAttributeOnEmptyElement, elementDecl.Name.ToString() );// 8 == strlen("NOTATION")
                        }
                        elementDecl.IsNotationDeclared = true;
                    }
                }

                if ( GetToken( true ) != Token.LeftParen ) {
                    goto UnexpectedError;
                }

                // parse notation list
                if ( GetToken( false ) != Token.Name ) {
                    goto UnexpectedError;
                }
                for (;;) {
                    string notationName = GetNameString();
                    if ( schemaInfo.Notations[notationName] == null ) {
                        if ( undeclaredNotations == null ) {
                            undeclaredNotations = new Hashtable();
                        }
                        UndeclaredNotation un = new UndeclaredNotation( notationName, LineNo, LinePos - notationName.Length );
                        UndeclaredNotation loggedUn = (UndeclaredNotation)undeclaredNotations[notationName];
                        if ( loggedUn != null ) {
                            un.next = loggedUn.next;
                            loggedUn.next = un;
                        }
                        else {
                            undeclaredNotations.Add( notationName, un );
                        }
                    }
                    if ( validate && !v1Compat && attrDef.Values != null && attrDef.Values.Contains( notationName ) ) {
                        SendValidationEvent( XmlSeverityType.Error, new XmlSchemaException( Res.Xml_AttlistDuplNotationValue, notationName, BaseUriStr, (int)LineNo, (int)LinePos ) );
                    }
                    attrDef.AddValue( notationName );

                    switch ( GetToken( false ) ) {
                        case Token.Or:
                            if ( GetToken( false ) != Token.Name ) {
                                goto UnexpectedError;
                            }
                            continue;
                        case Token.RightParen:
                            return;
                        default:
                            goto UnexpectedError;
                    }
                }
            }
            else if ( token == Token.LeftParen ) {
                attrDef.Datatype = XmlSchemaDatatype.FromXmlTokenizedType( XmlTokenizedType.ENUMERATION );
                attrDef.SchemaType = XmlSchemaType.GetBuiltInSimpleType( attrDef.Datatype.TypeCode );

                // parse nmtoken list
                if ( GetToken( false ) != Token.Nmtoken ) 
                    goto UnexpectedError;
                attrDef.AddValue( GetNameString() );

                for (;;) {
                    switch ( GetToken( false ) ) {
                        case Token.Or:
                            if ( GetToken( false ) != Token.Nmtoken ) 
                                goto UnexpectedError;
                            string nmtoken = GetNmtokenString();
                            if ( validate && !v1Compat && attrDef.Values != null && attrDef.Values.Contains( nmtoken ) ) {
                                SendValidationEvent( XmlSeverityType.Error, new XmlSchemaException( Res.Xml_AttlistDuplEnumValue, nmtoken, BaseUriStr, (int)LineNo, (int)LinePos ) );
                            }
                            attrDef.AddValue( nmtoken );
                            break;
                        case Token.RightParen:
                            return;
                        default:
                            goto UnexpectedError;
                    }
                }
            }
            else {
                goto UnexpectedError;
            }

        UnexpectedError:
            OnUnexpectedError();
        }
예제 #44
0
        private void CheckValue(
            string              value,
            SchemaAttDef        attdef
        ) {
            try {
                reader.TypedValueObject = null;
                bool isAttn = attdef != null;
                XmlSchemaDatatype dtype = isAttn ? attdef.Datatype : context.ElementDecl.Datatype;
                if (dtype == null) {
                    return; // no reason to check
                }
                
                if (dtype.TokenizedType != XmlTokenizedType.CDATA) {
                    value = value.Trim();
                }
                if (value.Length == 0) {
                    return; // don't need to check
                }
            

                object typedValue = dtype.ParseValue(value, NameTable, nsManager);
                reader.TypedValueObject = typedValue;
                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY || ttype == XmlTokenizedType.ID || ttype == XmlTokenizedType.IDREF) {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List) {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i) {
                            ProcessTokenizedType(dtype.TokenizedType, ss[i]);
                        }
                    }
                    else {
                        ProcessTokenizedType(dtype.TokenizedType, (string)typedValue);
                    }
                }

                SchemaDeclBase decl = isAttn ? (SchemaDeclBase)attdef : (SchemaDeclBase)context.ElementDecl;

                if (decl.MaxLength != uint.MaxValue) {
                    if(value.Length > decl.MaxLength) {
                        SendValidationEvent(Res.Sch_MaxLengthConstraintFailed, value);
                    }
                }
                if (decl.MinLength != uint.MaxValue) {
                    if(value.Length < decl.MinLength) {
                        SendValidationEvent(Res.Sch_MinLengthConstraintFailed, value);
                    }
                }
                if (decl.Values != null && !decl.CheckEnumeration(typedValue)) {
                    if (dtype.TokenizedType == XmlTokenizedType.NOTATION) {
                        SendValidationEvent(Res.Sch_NotationValue, typedValue.ToString());
                    }
                    else {
                        SendValidationEvent(Res.Sch_EnumerationValue, typedValue.ToString());
                    }

                }
                if (!decl.CheckValue(typedValue)) {
                    if (isAttn) {
                        SendValidationEvent(Res.Sch_FixedAttributeValue, attdef.Name.ToString());
                    }
                    else {
                        SendValidationEvent(Res.Sch_FixedElementValue, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                    }
                }
            }
            catch (XmlSchemaException) {
                if (attdef != null) {
                    SendValidationEvent(Res.Sch_AttributeValueDataType, attdef.Name.ToString());
                }
                else {
                    SendValidationEvent(Res.Sch_ElementValueDataType, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                }
            }
        }
         private void CompileAttribute(XmlSchemaAttribute xa) {
            if (xa.IsProcessing) {
                SendValidationEvent(Res.Sch_AttributeCircularRef, xa);
                return;
            }
            if (xa.AttDef != null) { //already compiled?
                return;
            }
            xa.IsProcessing = true;
            SchemaAttDef decl = null;
            try {
                if (!xa.RefName.IsEmpty) {
                    XmlSchemaAttribute a = (XmlSchemaAttribute)attributes[xa.RefName];
                    if (a == null) {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, xa.RefName.ToString(), xa);
                    }     
                    CompileAttribute(a);
                    if (a.AttDef == null) {
                        throw new XmlSchemaException(Res.Sch_RefInvalidAttribute, xa.RefName.ToString(), xa);
                    }
                    decl = a.AttDef.Clone();
                    XmlSchemaDatatype datatype = decl.Datatype;

                    if (datatype != null) {
                        if (a.FixedValue == null && a.DefaultValue == null) {
                            SetDefaultFixed(xa, decl);
                        }
                        else if (a.FixedValue != null) {
                            if (xa.DefaultValue != null) {
                                throw new XmlSchemaException(Res.Sch_FixedDefaultInRef, xa.RefName.ToString(), xa);
                            }
                            else if (xa.FixedValue != null ) {
                                object refFixedValue = datatype.ParseValue(xa.FixedValue, NameTable, new SchemaNamespaceManager(xa), true);
                                if ( !datatype.IsEqual(decl.DefaultValueTyped, refFixedValue)) {
                                    throw new XmlSchemaException(Res.Sch_FixedInRef, xa.RefName.ToString(), xa);
                                }
                            }
                        }
                    }
                    xa.SetAttributeType(a.AttributeSchemaType);
                }
                else {
                    decl = new SchemaAttDef(xa.QualifiedName);
                    if (xa.SchemaType != null) {
                        CompileSimpleType(xa.SchemaType);
                        xa.SetAttributeType(xa.SchemaType);
                        decl.SchemaType = xa.SchemaType;
                        decl.Datatype = xa.SchemaType.Datatype;
                    }
                    else if (!xa.SchemaTypeName.IsEmpty) {
                        XmlSchemaSimpleType simpleType = GetSimpleType(xa.SchemaTypeName);
                        if (simpleType != null) {
                            xa.SetAttributeType(simpleType);
                            decl.Datatype = simpleType.Datatype;
                            decl.SchemaType = simpleType;
                        }
                        else {
                            throw new XmlSchemaException(Res.Sch_UndeclaredSimpleType, xa.SchemaTypeName.ToString(), xa);   
                        }
                    }
                    else {
                        decl.SchemaType = DatatypeImplementation.AnySimpleType;
                        decl.Datatype = DatatypeImplementation.AnySimpleType.Datatype;
                        xa.SetAttributeType(DatatypeImplementation.AnySimpleType);
                    }
                    //} //Removed this here since the following should be done only if RefName is Empty
                    if (decl.Datatype != null) {
                        decl.Datatype.VerifySchemaValid(notations, xa);
                    }
                    SetDefaultFixed(xa, decl);
                } //End of Else for !RefName.IsEmpty

                decl.SchemaAttribute = xa; //So this is available for PSVI
                xa.AttDef = decl;
            } 
            catch (XmlSchemaException e) {
                if (e.SourceSchemaObject == null) {
                    e.SetSource(xa);
                }
                SendValidationEvent(e);
                xa.AttDef = SchemaAttDef.Empty;
            } 
            finally {
                xa.IsProcessing = false;
            }
        }
예제 #46
0
        public static void CheckDefaultValue(
            string              value,
            SchemaAttDef        attdef,
            SchemaInfo          sinfo,
            XmlNamespaceManager     nsManager,
            XmlNameTable        NameTable,
            object              sender,
            ValidationEventHandler  eventhandler,
            string              baseUri,
            int                 lineNo,
            int                 linePos
        ) {
            try {

                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null) {
                    return; // no reason to check
                }
                
                if (dtype.TokenizedType != XmlTokenizedType.CDATA) {
                    value = value.Trim();
                }
                if (value.Length == 0) {
                    return; // don't need to check
                }
                object typedValue = dtype.ParseValue(value, NameTable, nsManager);

                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY) {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List) {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i) {
                            ProcessEntity(sinfo, ss[i], sender, eventhandler, baseUri, lineNo, linePos);
                        }
                    }
                    else {
                        ProcessEntity(sinfo, (string)typedValue, sender, eventhandler, baseUri, lineNo, linePos);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION) {
                    if (!attdef.CheckEnumeration(typedValue)) {
                        XmlSchemaException e = new XmlSchemaException(Res.Sch_EnumerationValue, typedValue.ToString(), baseUri, lineNo, linePos);
                        if (eventhandler != null) {
                            eventhandler(sender, new ValidationEventArgs(e));
                        }
                        else {
                            throw e;
                        }
                    }
                }
                attdef.DefaultValueTyped = typedValue;
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch  {
#endif
                XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString(), baseUri, lineNo, linePos);
                if (eventhandler != null) {
                    eventhandler(sender, new ValidationEventArgs(e));
                }
                else {
                    throw e;
                }
            }
        }
        private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo)
        {
            if (lName == null)
            {
                throw new ArgumentNullException("localName");
            }
            if (ns == null)
            {
                throw new ArgumentNullException("namespaceUri");
            }
            ValidatorState toState = (this.validationStack.Length > 1) ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute;
            this.CheckStateTransition(toState, MethodNames[(int) toState]);
            object typedValue = null;
            this.attrValid = true;
            XmlSchemaValidity notKnown = XmlSchemaValidity.NotKnown;
            XmlSchemaAttribute schemaAttribute = null;
            XmlSchemaSimpleType xmlType = null;
            ns = this.nameTable.Add(ns);
            if (Ref.Equal(ns, this.NsXmlNs))
            {
                return null;
            }
            SchemaAttDef def = null;
            SchemaElementDecl elementDecl = this.context.ElementDecl;
            XmlQualifiedName key = new XmlQualifiedName(lName, ns);
            if (this.attPresence[key] != null)
            {
                this.SendValidationEvent("Sch_DuplicateAttribute", key.ToString());
                if (schemaInfo != null)
                {
                    schemaInfo.Clear();
                }
                return null;
            }
            if (Ref.Equal(ns, this.NsXsi))
            {
                lName = this.nameTable.Add(lName);
                if ((Ref.Equal(lName, this.xsiTypeString) || Ref.Equal(lName, this.xsiNilString)) || (Ref.Equal(lName, this.xsiSchemaLocationString) || Ref.Equal(lName, this.xsiNoNamespaceSchemaLocationString)))
                {
                    this.attPresence.Add(key, SchemaAttDef.Empty);
                }
                else
                {
                    this.attrValid = false;
                    this.SendValidationEvent("Sch_NotXsiAttribute", key.ToString());
                }
            }
            else
            {
                AttributeMatchState state2;
                object obj4;
                XmlSchemaObject partialValidationType = (this.currentState == ValidatorState.TopLevelAttribute) ? this.partialValidationType : null;
                def = this.compiledSchemaInfo.GetAttributeXsd(elementDecl, key, partialValidationType, out state2);
                switch (state2)
                {
                    case AttributeMatchState.AttributeFound:
                        break;

                    case AttributeMatchState.AnyIdAttributeFound:
                        if (this.wildID != null)
                        {
                            this.SendValidationEvent("Sch_MoreThanOneWildId", string.Empty);
                        }
                        else
                        {
                            this.wildID = def;
                            XmlSchemaComplexType schemaType = elementDecl.SchemaType as XmlSchemaComplexType;
                            if (!schemaType.ContainsIdAttribute(false))
                            {
                                break;
                            }
                            this.SendValidationEvent("Sch_AttrUseAndWildId", string.Empty);
                        }
                        goto Label_0409;

                    case AttributeMatchState.UndeclaredElementAndAttribute:
                        def = this.CheckIsXmlAttribute(key);
                        if (def != null)
                        {
                            break;
                        }
                        if (((elementDecl != null) || (this.processContents != XmlSchemaContentProcessing.Strict)) || ((key.Namespace.Length == 0) || !this.compiledSchemaInfo.Contains(key.Namespace)))
                        {
                            if (this.processContents != XmlSchemaContentProcessing.Skip)
                            {
                                this.SendValidationEvent("Sch_NoAttributeSchemaFound", key.ToString(), XmlSeverityType.Warning);
                            }
                        }
                        else
                        {
                            this.attrValid = false;
                            this.SendValidationEvent("Sch_UndeclaredAttribute", key.ToString());
                        }
                        goto Label_0409;

                    case AttributeMatchState.UndeclaredAttribute:
                        def = this.CheckIsXmlAttribute(key);
                        if (def != null)
                        {
                            break;
                        }
                        this.attrValid = false;
                        this.SendValidationEvent("Sch_UndeclaredAttribute", key.ToString());
                        goto Label_0409;

                    case AttributeMatchState.AnyAttributeLax:
                        this.SendValidationEvent("Sch_NoAttributeSchemaFound", key.ToString(), XmlSeverityType.Warning);
                        goto Label_0409;

                    case AttributeMatchState.ProhibitedAnyAttribute:
                        def = this.CheckIsXmlAttribute(key);
                        if (def != null)
                        {
                            break;
                        }
                        this.attrValid = false;
                        this.SendValidationEvent("Sch_ProhibitedAttribute", key.ToString());
                        goto Label_0409;

                    case AttributeMatchState.ProhibitedAttribute:
                        this.attrValid = false;
                        this.SendValidationEvent("Sch_ProhibitedAttribute", key.ToString());
                        goto Label_0409;

                    case AttributeMatchState.AttributeNameMismatch:
                        this.attrValid = false;
                        this.SendValidationEvent("Sch_SchemaAttributeNameMismatch", new string[] { key.ToString(), ((XmlSchemaAttribute) partialValidationType).QualifiedName.ToString() });
                        goto Label_0409;

                    case AttributeMatchState.ValidateAttributeInvalidCall:
                        this.currentState = ValidatorState.Start;
                        this.attrValid = false;
                        this.SendValidationEvent("Sch_ValidateAttributeInvalidCall", string.Empty);
                        goto Label_0409;

                    default:
                        goto Label_0409;
                }
                schemaAttribute = def.SchemaAttribute;
                if (elementDecl != null)
                {
                    this.attPresence.Add(key, def);
                }
                if (attributeValueGetter != null)
                {
                    obj4 = attributeValueGetter();
                }
                else
                {
                    obj4 = attributeStringValue;
                }
                typedValue = this.CheckAttributeValue(obj4, def);
                XmlSchemaDatatype dtype = def.Datatype;
                if ((dtype.Variety == XmlSchemaDatatypeVariety.Union) && (typedValue != null))
                {
                    XsdSimpleValue value2 = typedValue as XsdSimpleValue;
                    xmlType = value2.XmlType;
                    dtype = value2.XmlType.Datatype;
                    typedValue = value2.TypedValue;
                }
                this.CheckTokenizedTypes(dtype, typedValue, true);
                if (this.HasIdentityConstraints)
                {
                    this.AttributeIdentityConstraints(key.Name, key.Namespace, typedValue, obj4.ToString(), dtype);
                }
            }
        Label_0409:
            if (!this.attrValid)
            {
                notKnown = XmlSchemaValidity.Invalid;
            }
            else if (def != null)
            {
                notKnown = XmlSchemaValidity.Valid;
            }
            if (schemaInfo != null)
            {
                schemaInfo.SchemaAttribute = schemaAttribute;
                schemaInfo.SchemaType = (schemaAttribute == null) ? null : schemaAttribute.AttributeSchemaType;
                schemaInfo.MemberType = xmlType;
                schemaInfo.IsDefault = false;
                schemaInfo.Validity = notKnown;
            }
            if (this.ProcessSchemaHints && (this.validatedNamespaces[ns] == null))
            {
                this.validatedNamespaces.Add(ns, ns);
            }
            return typedValue;
        }
예제 #48
0
        private void ParseAttlistDefault(SchemaAttDef attrDef, bool ignoreErrors)
        {
            switch (GetToken(true))
            {
                case Token.REQUIRED:
                    attrDef.Presence = SchemaDeclBase.Use.Required;
                    return;
                case Token.IMPLIED:
                    attrDef.Presence = SchemaDeclBase.Use.Implied;
                    return;
                case Token.FIXED:
                    attrDef.Presence = SchemaDeclBase.Use.Fixed;
                    if (GetToken(true) != Token.Literal)
                    {
                        goto UnexpectedError;
                    }
                    break;
                case Token.Literal:
                    break;
                default:
                    goto UnexpectedError;
            }


            if (attrDef.TokenizedType != XmlTokenizedType.CDATA)
            {
                // non-CDATA attribute type normalization - strip spaces
                attrDef.DefaultValueExpanded = GetValueWithStrippedSpaces();
            }
            else
            {
                attrDef.DefaultValueExpanded = GetValue();
            }
            attrDef.ValueLineNumber = (int)_literalLineInfo.lineNo;
            attrDef.ValueLinePosition = (int)_literalLineInfo.linePos + 1;

            return;

        UnexpectedError:
            OnUnexpectedError();
        }
 private void ClearPSVI()
 {
     if (this.textValue != null)
     {
         this.textValue.Length = 0;
     }
     this.attPresence.Clear();
     this.wildID = null;
 }
        private void ValidateStartElement()
        {
            if (context.ElementDecl != null)
            {
                if (context.ElementDecl.IsAbstract)
                {
                    SendValidationEvent(Res.Sch_AbstractElement, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                }

                reader.SchemaTypeObject = context.ElementDecl.SchemaType;

                if (reader.IsEmptyElement && !context.IsNill && context.ElementDecl.DefaultValueTyped != null)
                {
                    reader.TypedValueObject = UnWrapUnion(context.ElementDecl.DefaultValueTyped);
                    context.IsNill          = true; // reusing IsNill
                }
                else
                {
                    reader.TypedValueObject = null; //Typed value cleanup
                }
                if (this.context.ElementDecl.HasRequiredAttribute || HasIdentityConstraints)
                {
                    attPresence.Clear();
                }
            }

            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    if ((object)reader.NamespaceURI == (object)NsXmlNs)
                    {
                        continue;
                    }
                    if ((object)reader.NamespaceURI == (object)NsXsi)
                    {
                        continue;
                    }

                    try {
                        reader.SchemaTypeObject = null;
                        XmlQualifiedName attQName     = new XmlQualifiedName(reader.LocalName, reader.NamespaceURI);
                        bool             skipContents = (processContents == XmlSchemaContentProcessing.Skip);
                        SchemaAttDef     attnDef      = schemaInfo.GetAttributeXsd(context.ElementDecl, attQName, ref skipContents);

                        if (attnDef != null)
                        {
                            if (context.ElementDecl != null && (context.ElementDecl.HasRequiredAttribute || this.startIDConstraint != -1))
                            {
                                attPresence.Add(attnDef.Name, attnDef);
                            }
                            Debug.Assert(attnDef.SchemaType != null);
                            reader.SchemaTypeObject = attnDef.SchemaType;
                            if (attnDef.Datatype != null)
                            {
                                // need to check the contents of this attribute to make sure
                                // it is valid according to the specified attribute type.
                                CheckValue(reader.Value, attnDef);
                            }
                            if (HasIdentityConstraints)
                            {
                                AttributeIdentityConstraints(reader.LocalName, reader.NamespaceURI, reader.TypedValueObject, reader.Value, attnDef);
                            }
                        }
                        else if (!skipContents)
                        {
                            if (context.ElementDecl == null &&
                                processContents == XmlSchemaContentProcessing.Strict &&
                                attQName.Namespace.Length != 0 &&
                                schemaInfo.Contains(attQName.Namespace)
                                )
                            {
                                SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString());
                            }
                            else
                            {
                                SendValidationEvent(Res.Sch_NoAttributeSchemaFound, attQName.ToString(), XmlSeverityType.Warning);
                            }
                        }
                    }
                    catch (XmlSchemaException e) {
                        e.SetSource(reader.BaseURI, PositionInfo.LineNumber, PositionInfo.LinePosition);
                        SendValidationEvent(e);
                    }
                } while(reader.MoveToNextAttribute());
                reader.MoveToElement();
            }
        }
예제 #51
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        private static void XDR_BeginAttribute(XdrBuilder builder)
        {
            if (builder._BaseDecl._TypeName.IsEmpty)
            {
                builder.SendValidationEvent(SR.Sch_MissAttribute);
            }

            SchemaAttDef attdef = null;
            XmlQualifiedName qname = builder._BaseDecl._TypeName;
            string prefix = builder._BaseDecl._Prefix;

            // local?
            if (builder._ElementDef._AttDefList != null)
            {
                attdef = (SchemaAttDef)builder._ElementDef._AttDefList[qname];
            }

            // global?
            if (attdef == null)
            {
                // if there is no URN in this name then the name is local to the
                // schema, but the global attribute was still URN qualified, so
                // we need to qualify this name now.
                XmlQualifiedName gname = qname;
                if (prefix.Length == 0)
                    gname = new XmlQualifiedName(qname.Name, builder._TargetNamespace);
                SchemaAttDef ad;
                if (builder._SchemaInfo.AttributeDecls.TryGetValue(gname, out ad))
                {
                    attdef = (SchemaAttDef)ad.Clone();
                    attdef.Name = qname;
                }
                else if (prefix.Length != 0)
                {
                    builder.SendValidationEvent(SR.Sch_UndeclaredAttribute, XmlQualifiedName.ToString(qname.Name, prefix));
                }
            }

            if (attdef != null)
            {
                builder.XDR_CheckAttributeDefault(builder._BaseDecl, attdef);
            }
            else
            {
                // will process undeclared types later
                attdef = new SchemaAttDef(qname, prefix);
                DeclBaseInfo decl = new DeclBaseInfo();
                decl._Checking = true;
                decl._Attdef = attdef;
                decl._TypeName = builder._BaseDecl._TypeName;
                decl._ElementDecl = builder._ElementDef._ElementDecl;
                decl._MinOccurs = builder._BaseDecl._MinOccurs;
                decl._Default = builder._BaseDecl._Default;

                // add undefined attribute types
                decl._Next = builder._UndefinedAttributeTypes;
                builder._UndefinedAttributeTypes = decl;
            }

            builder._ElementDef._ElementDecl.AddAttDef(attdef);
        }
예제 #52
0
        private void ParseAttlistType(SchemaAttDef attrDef, SchemaElementDecl elementDecl, bool ignoreErrors)
        {
            Token token = GetToken(true);

            if (token != Token.CDATA)
            {
                elementDecl.HasNonCDataAttribute = true;
            }

            if (IsAttributeValueType(token))
            {
                attrDef.TokenizedType = (XmlTokenizedType)(int)token;

                switch (token)
                {
                    case Token.NOTATION:
                        break;
                    case Token.ID:
                        elementDecl.IsIdDeclared = true;
                        return;
                    default:
                        return;
                }

                if (GetToken(true) != Token.LeftParen)
                {
                    goto UnexpectedError;
                }

                // parse notation list
                if (GetToken(false) != Token.Name)
                {
                    goto UnexpectedError;
                }
                for (; ;)
                {
                    string notationName = GetNameString();

                    switch (GetToken(false))
                    {
                        case Token.Or:
                            if (GetToken(false) != Token.Name)
                            {
                                goto UnexpectedError;
                            }
                            continue;
                        case Token.RightParen:
                            return;
                        default:
                            goto UnexpectedError;
                    }
                }
            }
            else if (token == Token.LeftParen)
            {
                attrDef.TokenizedType = XmlTokenizedType.ENUMERATION;

                // parse nmtoken list
                if (GetToken(false) != Token.Nmtoken)
                    goto UnexpectedError;

                for (; ;)
                {
                    switch (GetToken(false))
                    {
                        case Token.Or:
                            if (GetToken(false) != Token.Nmtoken)
                                goto UnexpectedError;
                            string nmtoken = GetNmtokenString();
                            break;
                        case Token.RightParen:
                            return;
                        default:
                            goto UnexpectedError;
                    }
                }
            }
            else
            {
                goto UnexpectedError;
            }

        UnexpectedError:
            OnUnexpectedError();
        }
예제 #53
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private void SetAttributePresence(SchemaAttDef pAttdef, bool fRequired)
 {
     if (SchemaDeclBase.Use.Fixed != pAttdef.Presence)
     {
         if (fRequired || SchemaDeclBase.Use.Required == pAttdef.Presence)
         {
             // If it is required and it has a default value then it is a FIXED attribute.
             if (pAttdef.DefaultValueTyped != null)
                 pAttdef.Presence = SchemaDeclBase.Use.Fixed;
             else
                 pAttdef.Presence = SchemaDeclBase.Use.Required;
         }
         else if (pAttdef.DefaultValueTyped != null)
         {
             pAttdef.Presence = SchemaDeclBase.Use.Default;
         }
         else
         {
             pAttdef.Presence = SchemaDeclBase.Use.Implied;
         }
     }
 }
        private void CheckValue(
            string value,
            SchemaAttDef attdef
            )
        {
            try {
                reader.TypedValueObject = null;
                bool isAttn             = attdef != null;
                XmlSchemaDatatype dtype = isAttn ? attdef.Datatype : context.ElementDecl.Datatype;
                if (dtype == null)
                {
                    return; // no reason to check
                }

                object typedValue = dtype.ParseValue(value, NameTable, nsManager, true);

                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY || ttype == XmlTokenizedType.ID || ttype == XmlTokenizedType.IDREF)
                {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List)
                    {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i)
                        {
                            ProcessTokenizedType(dtype.TokenizedType, ss[i]);
                        }
                    }
                    else
                    {
                        ProcessTokenizedType(dtype.TokenizedType, (string)typedValue);
                    }
                }

                SchemaDeclBase decl = isAttn ? (SchemaDeclBase)attdef : (SchemaDeclBase)context.ElementDecl;
                if (!decl.CheckValue(typedValue))
                {
                    if (isAttn)
                    {
                        SendValidationEvent(Res.Sch_FixedAttributeValue, attdef.Name.ToString());
                    }
                    else
                    {
                        SendValidationEvent(Res.Sch_FixedElementValue, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                    }
                }
                if (dtype.Variety == XmlSchemaDatatypeVariety.Union)
                {
                    typedValue = UnWrapUnion(typedValue);
                }
                reader.TypedValueObject = typedValue;
            }
            catch (XmlSchemaException) {
                if (attdef != null)
                {
                    SendValidationEvent(Res.Sch_AttributeValueDataType, attdef.Name.ToString());
                }
                else
                {
                    SendValidationEvent(Res.Sch_ElementValueDataType, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                }
            }
        }
 internal bool AddDefaultAttribute( SchemaAttDef attdef ) {
     return coreReaderImpl.AddDefaultAttributeNonDtd( attdef );
 }
        // facilitate modifying
        private void AttributeIdentityConstraints(string name, string ns, object obj, string sobj, SchemaAttDef attdef)
        {
            for (int ci = this.startIDConstraint; ci < this.validationStack.Length; ci++)
            {
                // no constraint for this level
                if (((ValidationState)(this.validationStack[ci])).Constr == null)
                {
                    continue;
                }

                // else
                ConstraintStruct[] constraints = ((ValidationState)this.validationStack[ci]).Constr;
                for (int i = 0; i < constraints.Length; ++i)
                {
                    // axisFields is not null, but may be empty
                    for (int j = 0; j < constraints[i].axisFields.Count; ++j)
                    {
                        LocatedActiveAxis laxis = (LocatedActiveAxis)constraints[i].axisFields[j];

                        // check field from here
                        if (laxis.MoveToAttribute(name, ns))
                        {
                            Debug.WriteLine("Attribute Field Match!");
                            //attribute is only simpletype, so needn't checking...
                            // can fill value here, yeah!!
                            Debug.WriteLine("Attribute Field Filling Value!");
                            Debug.WriteLine("Name: " + name + "\t|\tURI: " + ns + "\t|\tValue: " + obj + "\n");
                            if (laxis.Ks[laxis.Column] != null)
                            {
                                // should be evaluated to either an empty node-set or a node-set with exactly one member
                                // two matches...
                                SendValidationEvent(Res.Sch_FieldSingleValueExpected, name);
                            }
                            else if ((attdef != null) && (attdef.Datatype != null))
                            {
                                laxis.Ks[laxis.Column] = new TypedObject(obj, sobj, attdef.Datatype);
                            }
                        }
                    }
                }
            }
        }
예제 #57
0
파일: DtdParser.cs 프로젝트: chcosta/corefx
        private void ParseAttlistType(SchemaAttDef attrDef, SchemaElementDecl elementDecl, bool ignoreErrors)
        {
            Token token = GetToken(true);

            if (token != Token.CDATA)
            {
                elementDecl.HasNonCDataAttribute = true;
            }

            if (IsAttributeValueType(token))
            {
                attrDef.TokenizedType = (XmlTokenizedType)(int)token;
#if !SILVERLIGHT
                attrDef.SchemaType = XmlSchemaType.GetBuiltInSimpleType(attrDef.Datatype.TypeCode);
#endif

                switch (token)
                {
                    case Token.NOTATION:
                        break;
                    case Token.ID:
#if !SILVERLIGHT
                        if (_validate && elementDecl.IsIdDeclared)
                        {
                            SchemaAttDef idAttrDef = elementDecl.GetAttDef(attrDef.Name);
                            if ((idAttrDef == null || idAttrDef.Datatype.TokenizedType != XmlTokenizedType.ID) && !ignoreErrors)
                            {
                                SendValidationEvent(XmlSeverityType.Error, SR.Sch_IdAttrDeclared, elementDecl.Name.ToString());
                            }
                        }
#endif
                        elementDecl.IsIdDeclared = true;
                        return;
                    default:
                        return;
                }
#if !SILVERLIGHT
                // check notation constrains
                if (_validate)
                {
                    if (elementDecl.IsNotationDeclared && !ignoreErrors)
                    {
                        SendValidationEvent(_curPos - 8, XmlSeverityType.Error, SR.Sch_DupNotationAttribute, elementDecl.Name.ToString()); // 8 == strlen("NOTATION")
                    }
                    else
                    {
                        if (elementDecl.ContentValidator != null &&
                            elementDecl.ContentValidator.ContentType == XmlSchemaContentType.Empty &&
                            !ignoreErrors)
                        {
                            SendValidationEvent(_curPos - 8, XmlSeverityType.Error, SR.Sch_NotationAttributeOnEmptyElement, elementDecl.Name.ToString());// 8 == strlen("NOTATION")
                        }
                        elementDecl.IsNotationDeclared = true;
                    }
                }
#endif

                if (GetToken(true) != Token.LeftParen)
                {
                    goto UnexpectedError;
                }

                // parse notation list
                if (GetToken(false) != Token.Name)
                {
                    goto UnexpectedError;
                }
                for (;;)
                {
                    string notationName = GetNameString();
#if !SILVERLIGHT
                    if (!_schemaInfo.Notations.ContainsKey(notationName))
                    {
                        AddUndeclaredNotation(notationName);
                    }
                    if (_validate && !_v1Compat && attrDef.Values != null && attrDef.Values.Contains(notationName) && !ignoreErrors)
                    {
                        SendValidationEvent(XmlSeverityType.Error, new XmlSchemaException(SR.Xml_AttlistDuplNotationValue, notationName, BaseUriStr, (int)LineNo, (int)LinePos));
                    }
                    attrDef.AddValue(notationName);
#endif

                    switch (GetToken(false))
                    {
                        case Token.Or:
                            if (GetToken(false) != Token.Name)
                            {
                                goto UnexpectedError;
                            }
                            continue;
                        case Token.RightParen:
                            return;
                        default:
                            goto UnexpectedError;
                    }
                }
            }
            else if (token == Token.LeftParen)
            {
                attrDef.TokenizedType = XmlTokenizedType.ENUMERATION;
#if !SILVERLIGHT
                attrDef.SchemaType = XmlSchemaType.GetBuiltInSimpleType(attrDef.Datatype.TypeCode);
#endif

                // parse nmtoken list
                if (GetToken(false) != Token.Nmtoken)
                    goto UnexpectedError;
#if !SILVERLIGHT
                attrDef.AddValue(GetNameString());
#endif

                for (;;)
                {
                    switch (GetToken(false))
                    {
                        case Token.Or:
                            if (GetToken(false) != Token.Nmtoken)
                                goto UnexpectedError;
                            string nmtoken = GetNmtokenString();
#if !SILVERLIGHT
                            if (_validate && !_v1Compat && attrDef.Values != null && attrDef.Values.Contains(nmtoken) && !ignoreErrors)
                            {
                                SendValidationEvent(XmlSeverityType.Error, new XmlSchemaException(SR.Xml_AttlistDuplEnumValue, nmtoken, BaseUriStr, (int)LineNo, (int)LinePos));
                            }
                            attrDef.AddValue(nmtoken);
#endif
                            break;
                        case Token.RightParen:
                            return;
                        default:
                            goto UnexpectedError;
                    }
                }
            }
            else
            {
                goto UnexpectedError;
            }

        UnexpectedError:
            OnUnexpectedError();
        }
예제 #58
0
파일: DtdParser.cs 프로젝트: chcosta/corefx
        private void ParseAttlistDefault(SchemaAttDef attrDef, bool ignoreErrors)
        {
            switch (GetToken(true))
            {
                case Token.REQUIRED:
                    attrDef.Presence = SchemaDeclBase.Use.Required;
                    return;
                case Token.IMPLIED:
                    attrDef.Presence = SchemaDeclBase.Use.Implied;
                    return;
                case Token.FIXED:
                    attrDef.Presence = SchemaDeclBase.Use.Fixed;
                    if (GetToken(true) != Token.Literal)
                    {
                        goto UnexpectedError;
                    }
                    break;
                case Token.Literal:
                    break;
                default:
                    goto UnexpectedError;
            }

#if !SILVERLIGHT
            if (_validate && attrDef.Datatype.TokenizedType == XmlTokenizedType.ID && !ignoreErrors)
            {
                SendValidationEvent(_curPos, XmlSeverityType.Error, SR.Sch_AttListPresence, string.Empty);
            }
#endif

            if (attrDef.TokenizedType != XmlTokenizedType.CDATA)
            {
                // non-CDATA attribute type normalization - strip spaces
                attrDef.DefaultValueExpanded = GetValueWithStrippedSpaces();
            }
            else
            {
                attrDef.DefaultValueExpanded = GetValue();
            }
            attrDef.ValueLineNumber = (int)_literalLineInfo.lineNo;
            attrDef.ValueLinePosition = (int)_literalLineInfo.linePos + 1;

#if !SILVERLIGHT
            DtdValidator.SetDefaultTypedValue(attrDef, _readerAdapter);
#endif
            return;

        UnexpectedError:
            OnUnexpectedError();
        }
        private void CompileAttribute(XmlSchemaAttribute xa)
        {
            if (xa.IsProcessing)
            {
                base.SendValidationEvent("Sch_AttributeCircularRef", xa);
            }
            else if (xa.AttDef == null)
            {
                xa.IsProcessing = true;
                SchemaAttDef def = null;
                try
                {
                    if (!xa.RefName.IsEmpty)
                    {
                        XmlSchemaAttribute attribute = (XmlSchemaAttribute) this.schema.Attributes[xa.RefName];
                        if (attribute == null)
                        {
                            throw new XmlSchemaException("Sch_UndeclaredAttribute", xa.RefName.ToString(), xa);
                        }
                        this.CompileAttribute(attribute);
                        if (attribute.AttDef == null)
                        {
                            throw new XmlSchemaException("Sch_RefInvalidAttribute", xa.RefName.ToString(), xa);
                        }
                        def = attribute.AttDef.Clone();
                        if (def.Datatype != null)
                        {
                            if (attribute.FixedValue != null)
                            {
                                if (xa.DefaultValue != null)
                                {
                                    throw new XmlSchemaException("Sch_FixedDefaultInRef", xa.RefName.ToString(), xa);
                                }
                                if (xa.FixedValue != null)
                                {
                                    if (xa.FixedValue != attribute.FixedValue)
                                    {
                                        throw new XmlSchemaException("Sch_FixedInRef", xa.RefName.ToString(), xa);
                                    }
                                }
                                else
                                {
                                    def.Presence = SchemaDeclBase.Use.Fixed;
                                    def.DefaultValueRaw = def.DefaultValueExpanded = attribute.FixedValue;
                                    def.DefaultValueTyped = def.Datatype.ParseValue(def.DefaultValueRaw, base.NameTable, new SchemaNamespaceManager(xa), true);
                                }
                            }
                            else if (((attribute.DefaultValue != null) && (xa.DefaultValue == null)) && (xa.FixedValue == null))
                            {
                                def.Presence = SchemaDeclBase.Use.Default;
                                def.DefaultValueRaw = def.DefaultValueExpanded = attribute.DefaultValue;
                                def.DefaultValueTyped = def.Datatype.ParseValue(def.DefaultValueRaw, base.NameTable, new SchemaNamespaceManager(xa), true);
                            }
                        }
                        xa.SetAttributeType(attribute.AttributeSchemaType);
                    }
                    else
                    {
                        def = new SchemaAttDef(xa.QualifiedName);
                        if (xa.SchemaType != null)
                        {
                            this.CompileSimpleType(xa.SchemaType);
                            xa.SetAttributeType(xa.SchemaType);
                            def.SchemaType = xa.SchemaType;
                            def.Datatype = xa.SchemaType.Datatype;
                        }
                        else if (!xa.SchemaTypeName.IsEmpty)
                        {
                            XmlSchemaSimpleType simpleType = this.GetSimpleType(xa.SchemaTypeName);
                            if (simpleType == null)
                            {
                                throw new XmlSchemaException("Sch_UndeclaredSimpleType", xa.SchemaTypeName.ToString(), xa);
                            }
                            xa.SetAttributeType(simpleType);
                            def.Datatype = simpleType.Datatype;
                            def.SchemaType = simpleType;
                        }
                        else
                        {
                            def.SchemaType = DatatypeImplementation.AnySimpleType;
                            def.Datatype = DatatypeImplementation.AnySimpleType.Datatype;
                            xa.SetAttributeType(DatatypeImplementation.AnySimpleType);
                        }
                    }
                    if (def.Datatype != null)
                    {
                        def.Datatype.VerifySchemaValid(this.schema.Notations, xa);
                    }
                    if ((xa.DefaultValue != null) || (xa.FixedValue != null))
                    {
                        if (xa.DefaultValue != null)
                        {
                            def.Presence = SchemaDeclBase.Use.Default;
                            def.DefaultValueRaw = def.DefaultValueExpanded = xa.DefaultValue;
                        }
                        else
                        {
                            def.Presence = SchemaDeclBase.Use.Fixed;
                            def.DefaultValueRaw = def.DefaultValueExpanded = xa.FixedValue;
                        }
                        if (def.Datatype != null)
                        {
                            def.DefaultValueTyped = def.Datatype.ParseValue(def.DefaultValueRaw, base.NameTable, new SchemaNamespaceManager(xa), true);
                        }
                    }
                    else
                    {
                        switch (xa.Use)
                        {
                            case XmlSchemaUse.None:
                            case XmlSchemaUse.Optional:
                                def.Presence = SchemaDeclBase.Use.Implied;
                                break;

                            case XmlSchemaUse.Required:
                                def.Presence = SchemaDeclBase.Use.Required;
                                break;
                        }
                    }
                    def.SchemaAttribute = xa;
                    xa.AttDef = def;
                }
                catch (XmlSchemaException exception)
                {
                    if (exception.SourceSchemaObject == null)
                    {
                        exception.SetSource(xa);
                    }
                    base.SendValidationEvent(exception);
                    xa.AttDef = SchemaAttDef.Empty;
                }
                finally
                {
                    xa.IsProcessing = false;
                }
            }
        }
        private object CheckAttributeValue(object value, SchemaAttDef attdef) {
            object typedValue = null;
            SchemaDeclBase decl = attdef as SchemaDeclBase;

            XmlSchemaDatatype dtype = attdef.Datatype;
            Debug.Assert(dtype != null);
            string stringValue = value as string;
            Exception exception = null;

            if (stringValue != null) { //
                exception = dtype.TryParseValue(stringValue, nameTable, nsResolver, out typedValue);
                if (exception != null) goto Error;
            }
            else { //Calling object ParseValue for checking facets
                exception = dtype.TryParseValue(value, nameTable, nsResolver, out typedValue);
                if (exception != null) goto Error;
            }
            if (!decl.CheckValue(typedValue)) {
                attrValid = false;
                SendValidationEvent(Res.Sch_FixedAttributeValue, attdef.Name.ToString());
            }
            return typedValue;

        Error:
            attrValid = false;
            if (stringValue == null) {
                stringValue = XmlSchemaDatatype.ConcatenatedToString(value);
            }
            SendValidationEvent(Res.Sch_AttributeValueDataTypeDetailed, new string[] { attdef.Name.ToString(), stringValue, GetTypeName(decl), exception.Message }, exception);
            return null;
        }