Inheritance: SchemaDeclBase, IDtdAttributeListInfo
        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);
        }
Esempio n. 2
0
 public static SchemaElementDecl CreateAnyTypeElementDecl() {
     SchemaElementDecl anyTypeElementDecl = new SchemaElementDecl();
     anyTypeElementDecl.Content = new CompiledContentModel(null);
     anyTypeElementDecl.Content.ContentType = CompiledContentModel.Type.Any;
     anyTypeElementDecl.Datatype = XmlSchemaDatatype.AnyType;
     return anyTypeElementDecl;
 }
        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);
        }
 private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents)
 {
     XmlSchemaComplexType type = new XmlSchemaComplexType();
     type.SetQualifiedName(DatatypeImplementation.QnAnyType);
     XmlSchemaAny item = new XmlSchemaAny {
         MinOccurs = 0M,
         MaxOccurs = 79228162514264337593543950335M,
         ProcessContents = processContents
     };
     item.BuildNamespaceList(null);
     XmlSchemaSequence sequence = new XmlSchemaSequence();
     sequence.Items.Add(item);
     type.SetContentTypeParticle(sequence);
     type.SetContentType(XmlSchemaContentType.Mixed);
     type.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
     type.ElementDecl.SchemaType = type;
     ParticleContentValidator validator = new ParticleContentValidator(XmlSchemaContentType.Mixed);
     validator.Start();
     validator.OpenGroup();
     validator.AddNamespaceList(item.NamespaceList, item);
     validator.AddStar();
     validator.CloseGroup();
     ContentValidator validator2 = validator.Finish(true);
     type.ElementDecl.ContentValidator = validator2;
     XmlSchemaAnyAttribute attribute = new XmlSchemaAnyAttribute {
         ProcessContents = processContents
     };
     attribute.BuildNamespaceList(null);
     type.SetAttributeWildcard(attribute);
     type.ElementDecl.AnyAttribute = attribute;
     return type;
 }
        private SchemaElementDecl ThoroughGetElementDecl()
        {
            if (base.reader.Depth == 0)
            {
                this.LoadSchema(string.Empty);
            }
            if (base.reader.MoveToFirstAttribute())
            {
                do
                {
                    string namespaceURI = base.reader.NamespaceURI;
                    string localName    = base.reader.LocalName;
                    if (Ref.Equal(namespaceURI, base.SchemaNames.NsXmlNs))
                    {
                        this.LoadSchema(base.reader.Value);
                        if (this.isProcessContents)
                        {
                            this.nsManager.AddNamespace((base.reader.Prefix.Length == 0) ? string.Empty : base.reader.LocalName, base.reader.Value);
                        }
                    }
                    if (Ref.Equal(namespaceURI, base.SchemaNames.QnDtDt.Namespace) && Ref.Equal(localName, base.SchemaNames.QnDtDt.Name))
                    {
                        base.reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(base.reader.Value);
                    }
                }while (base.reader.MoveToNextAttribute());
                base.reader.MoveToElement();
            }
            SchemaElementDecl elementDecl = base.schemaInfo.GetElementDecl(base.elementName);

            if ((elementDecl == null) && base.schemaInfo.TargetNamespaces.ContainsKey(base.context.Namespace))
            {
                base.SendValidationEvent("Sch_UndeclaredElement", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace));
            }
            return(elementDecl);
        }
        internal static SchemaElementDecl CreateAnyTypeElementDecl()
        {
            SchemaElementDecl anyTypeElementDecl = new SchemaElementDecl();

            anyTypeElementDecl.Datatype = DatatypeImplementation.AnySimpleType.Datatype !;
            return(anyTypeElementDecl);
        }
        public static SchemaElementDecl CreateAnyTypeElementDecl()
        {
            SchemaElementDecl anyTypeElementDecl = new SchemaElementDecl();

            anyTypeElementDecl.Content             = new CompiledContentModel(null);
            anyTypeElementDecl.Content.ContentType = CompiledContentModel.Type.Any;
            anyTypeElementDecl.Datatype            = XmlSchemaDatatype.AnyType;
            return(anyTypeElementDecl);
        }
        internal XmlSchemaElement GetType(XmlQualifiedName qname)
        {
            SchemaElementDecl ed = GetElementDecl(qname);

            if (ed != null)
            {
                return(ed.SchemaElement);
            }
            return(null);
        }
        internal XmlSchemaElement GetType(XmlQualifiedName qname)
        {
            SchemaElementDecl elementDecl = this.GetElementDecl(qname);

            if (elementDecl != null)
            {
                return(elementDecl.SchemaElement);
            }
            return(null);
        }
 static XmlSchemaComplexType()
 {
     untypedAnyType.SetQualifiedName(new XmlQualifiedName("untypedAny", "http://www.w3.org/2003/11/xpath-datatypes"));
     untypedAnyType.IsMixed = true;
     untypedAnyType.SetContentTypeParticle(anyTypeLax.ContentTypeParticle);
     untypedAnyType.SetContentType(XmlSchemaContentType.Mixed);
     untypedAnyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
     untypedAnyType.ElementDecl.SchemaType = untypedAnyType;
     untypedAnyType.ElementDecl.ContentValidator = AnyTypeContentValidator;
 }
        public XmlSchemaElement GetElement(XmlQualifiedName qname)
        {
            SchemaElementDecl ed = GetElementDecl(qname);

            if (ed != null)
            {
                return(ed.SchemaElement);
            }
            return(null);
        }
Esempio n. 12
0
        static XmlSchemaComplexType()
        {
            anyType = new XmlSchemaComplexType();
            anyType.SetContentType(XmlSchemaContentType.Mixed);
            anyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();

            anyAttribute.BuildNamespaceList(null);
            anyType.SetAttributeWildcard(anyAttribute);
            anyType.ElementDecl.AnyAttribute = anyAttribute;
        }
Esempio n. 13
0
        internal SchemaElementDecl GetElementDecl(XmlQualifiedName qname, SchemaElementDecl ed)
        {
            SchemaElementDecl ed1 = null;

            if ((ed != null) && (ed.LocalElements != null))
            {
                ed1 = (SchemaElementDecl)ed.LocalElements[qname];
            }
            if (ed1 == null && elementDecls != null)
            {
                ed1 = (SchemaElementDecl)elementDecls[qname];
            }
            return(ed1);
        }
Esempio n. 14
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;
            }
Esempio n. 15
0
        //const byte dupDeclMask = 0x08;

        private static XmlSchemaComplexType CreateUntypedAnyType()
        {
            // Create xdt:untypedAny
            var untypedAny = new XmlSchemaComplexType();

            untypedAny.SetQualifiedName(new XmlQualifiedName("untypedAny", XmlReservedNs.NsXQueryDataType));
            untypedAny.IsMixed = true;
            untypedAny.SetContentTypeParticle(s_anyTypeLax.ContentTypeParticle);
            untypedAny.SetContentType(XmlSchemaContentType.Mixed);

            untypedAny.ElementDecl                  = SchemaElementDecl.CreateAnyTypeElementDecl();
            untypedAny.ElementDecl.SchemaType       = untypedAny;
            untypedAny.ElementDecl.ContentValidator = AnyTypeContentValidator;

            return(untypedAny);
        }
Esempio n. 16
0
        //const byte dupDeclMask = 0x08;

        static XmlSchemaComplexType()
        {
            anyTypeLax  = CreateAnyType(XmlSchemaContentProcessing.Lax);
            anyTypeSkip = CreateAnyType(XmlSchemaContentProcessing.Skip);

            // Create xdt:untypedAny
            untypedAnyType = new XmlSchemaComplexType();
            untypedAnyType.SetQualifiedName(new XmlQualifiedName("untypedAny", XmlReservedNs.NsXQueryDataType));
            untypedAnyType.IsMixed = true;
            untypedAnyType.SetContentTypeParticle(anyTypeLax.ContentTypeParticle);
            untypedAnyType.SetContentType(XmlSchemaContentType.Mixed);

            untypedAnyType.ElementDecl                  = SchemaElementDecl.CreateAnyTypeElementDecl();
            untypedAnyType.ElementDecl.SchemaType       = untypedAnyType;
            untypedAnyType.ElementDecl.ContentValidator = AnyTypeContentValidator;
        }
Esempio n. 17
0
        private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents)
        {
            XmlSchemaComplexType localAnyType = new XmlSchemaComplexType();

            localAnyType.SetQualifiedName(DatatypeImplementation.QnAnyType);

            XmlSchemaAny anyElement = new XmlSchemaAny();

            anyElement.MinOccurs = decimal.Zero;
            anyElement.MaxOccurs = decimal.MaxValue;

            anyElement.ProcessContents = processContents;
            anyElement.BuildNamespaceList(null);
            XmlSchemaSequence seq = new XmlSchemaSequence();

            seq.Items.Add(anyElement);

            localAnyType.SetContentTypeParticle(seq);
            localAnyType.SetContentType(XmlSchemaContentType.Mixed);

            localAnyType.ElementDecl            = SchemaElementDecl.CreateAnyTypeElementDecl();
            localAnyType.ElementDecl.SchemaType = localAnyType;

            //Create contentValidator for Any
            ParticleContentValidator contentValidator = new ParticleContentValidator(XmlSchemaContentType.Mixed);

            contentValidator.Start();
            contentValidator.OpenGroup();
            contentValidator.AddNamespaceList(anyElement.NamespaceList !, anyElement);
            contentValidator.AddStar();
            contentValidator.CloseGroup();
            ContentValidator anyContentValidator = contentValidator.Finish(true);

            localAnyType.ElementDecl.ContentValidator = anyContentValidator;

            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();

            anyAttribute.ProcessContents = processContents;
            anyAttribute.BuildNamespaceList(null);
            localAnyType.SetAttributeWildcard(anyAttribute);
            localAnyType.ElementDecl.AnyAttribute = anyAttribute;
            return(localAnyType);
        }
        private SchemaElementDecl FastGetElementDecl(object particle)
        {
            SchemaElementDecl elementDecl = null;

            if (particle != null)
            {
                XmlSchemaElement element = particle as XmlSchemaElement;
                if (element != null)
                {
                    elementDecl = element.ElementDecl;
                }
                else
                {
                    XmlSchemaAny any = (XmlSchemaAny)particle;
                    processContents = any.ProcessContentsCorrect;
                }
            }
            return(elementDecl);
        }
        private void ProcessElement()
        {
            SchemaElementDecl elementDecl = base.schemaInfo.GetElementDecl(base.elementName);

            this.Push(base.elementName);
            if (elementDecl != null)
            {
                base.context.ElementDecl = elementDecl;
                this.ValidateStartElement();
                this.ValidateEndStartElement();
                base.context.NeedValidateChildren = true;
                elementDecl.ContentValidator.InitValidation(base.context);
            }
            else
            {
                base.SendValidationEvent("Sch_UndeclaredElement", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace));
                base.context.ElementDecl = null;
            }
        }
Esempio n. 20
0
        private void ProcessElement()
        {
            SchemaElementDecl elementDecl = schemaInfo.GetElementDecl(elementName);

            Push(elementName);
            if (elementDecl != null)
            {
                context.ElementDecl = elementDecl;
                ValidateStartElement();
                ValidateEndStartElement();
                context.NeedValidateChildren = true;
                elementDecl.ContentValidator.InitValidation(context);
            }
            else
            {
                SendValidationEvent(Res.Sch_UndeclaredElement, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                context.ElementDecl = null;
            }
        }
Esempio n. 21
0
        // SxS: This method processes resource names read from the source document and does not expose
        // any resources to the caller. It is fine to suppress the SxS warning.
        private SchemaElementDecl ThoroughGetElementDecl()
        {
            if (reader.Depth == 0)
            {
                LoadSchema(string.Empty);
            }
            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    string objectNs   = reader.NamespaceURI;
                    string objectName = reader.LocalName;
                    if (Ref.Equal(objectNs, SchemaNames.NsXmlNs))
                    {
                        LoadSchema(reader.Value);
                        if (_isProcessContents)
                        {
                            _nsManager.AddNamespace(reader.Prefix.Length == 0 ? string.Empty : reader.LocalName, reader.Value);
                        }
                    }
                    if (
                        Ref.Equal(objectNs, SchemaNames.QnDtDt.Namespace) &&
                        Ref.Equal(objectName, SchemaNames.QnDtDt.Name)
                        )
                    {
                        reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(reader.Value);
                    }
                } while (reader.MoveToNextAttribute());
                reader.MoveToElement();
            }
            SchemaElementDecl elementDecl = schemaInfo.GetElementDecl(elementName);

            if (elementDecl == null)
            {
                if (schemaInfo.TargetNamespaces.ContainsKey(context.Namespace))
                {
                    SendValidationEvent(SR.Sch_UndeclaredElement, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                }
            }
            return(elementDecl);
        }
        private void ProcessElement(object particle)
        {
            XmlQualifiedName  xsiType;
            string            xsiNil;
            SchemaElementDecl elementDecl = FastGetElementDecl(particle);

            Push(elementName);
            if (bManageNamespaces)
            {
                nsManager.PushScope();
            }
            ProcessXsiAttributes(out xsiType, out xsiNil);
            if (processContents != XmlSchemaContentProcessing.Skip)
            {
                if (elementDecl == null || !xsiType.IsEmpty || xsiNil != null)
                {
                    elementDecl = ThoroughGetElementDecl(elementDecl, xsiType, xsiNil);
                }
                if (elementDecl == null)
                {
                    if (HasSchema && processContents == XmlSchemaContentProcessing.Strict)
                    {
                        SendValidationEvent(Res.Sch_UndeclaredElement, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                    }
                    else
                    {
                        SendValidationEvent(Res.Sch_NoElementSchemaFound, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace), XmlSeverityType.Warning);
                    }
                }
            }

            context.ElementDecl = elementDecl;
            ValidateStartElementIdentityConstraints();
            ValidateStartElement();
            if (context.ElementDecl != null)
            {
                ValidateEndStartElement();
                context.NeedValidateChildren = processContents != XmlSchemaContentProcessing.Skip;
                context.ElementDecl.ContentValidator.InitValidation(context);
            }
        }
        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);
        }
Esempio n. 24
0
        private void ProcessElement(object particle)
        {
            XmlQualifiedName  name;
            string            str;
            SchemaElementDecl elementDecl = this.FastGetElementDecl(particle);

            this.Push(base.elementName);
            if (this.bManageNamespaces)
            {
                this.nsManager.PushScope();
            }
            this.ProcessXsiAttributes(out name, out str);
            if (this.processContents != XmlSchemaContentProcessing.Skip)
            {
                if (((elementDecl == null) || !name.IsEmpty) || (str != null))
                {
                    elementDecl = this.ThoroughGetElementDecl(elementDecl, name, str);
                }
                if (elementDecl == null)
                {
                    if (this.HasSchema && (this.processContents == XmlSchemaContentProcessing.Strict))
                    {
                        base.SendValidationEvent("Sch_UndeclaredElement", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace));
                    }
                    else
                    {
                        base.SendValidationEvent("Sch_NoElementSchemaFound", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace), XmlSeverityType.Warning);
                    }
                }
            }
            base.context.ElementDecl = elementDecl;
            this.ValidateStartElementIdentityConstraints();
            this.ValidateStartElement();
            if (base.context.ElementDecl != null)
            {
                this.ValidateEndStartElement();
                base.context.NeedValidateChildren = this.processContents != XmlSchemaContentProcessing.Skip;
                base.context.ElementDecl.ContentValidator.InitValidation(base.context);
            }
        }
Esempio n. 25
0
        private static void XDR_BuildElement_Type(XdrBuilder builder, object obj, string prefix)
        {
            XmlQualifiedName qname = (XmlQualifiedName)obj;

            if (!builder._SchemaInfo.ElementDecls.ContainsKey(qname))
            {
                SchemaElementDecl ed = (SchemaElementDecl)builder._UndeclaredElements[qname];
                if (ed == null)
                {
                    ed = new SchemaElementDecl(qname, prefix);
                    builder._UndeclaredElements.Add(qname, ed);
                }
            }

            builder._ElementDef._HasType = true;
            if (builder._ElementDef._ExistTerminal)
                builder.AddOrder();
            else
                builder._ElementDef._ExistTerminal = true;

            builder._contentValidator.AddName(qname, null);
        }
 private void CheckRequiredAttributes(SchemaElementDecl currentElementDecl)
 {
     foreach (SchemaAttDef def in currentElementDecl.AttDefs.Values)
     {
         if ((this.attPresence[def.Name] == null) && ((def.Presence == SchemaDeclBase.Use.Required) || (def.Presence == SchemaDeclBase.Use.RequiredFixed)))
         {
             this.SendValidationEvent("Sch_MissRequiredAttribute", def.Name.ToString());
         }
     }
 }
 private void CompileSimpleType(XmlSchemaSimpleType simpleType) {
     if (simpleType.IsProcessing) {
         throw new XmlSchemaException(Res.Sch_TypeCircularRef, simpleType);
     }
     if (simpleType.ElementDecl != null) { // already compiled
         return;
     }
     simpleType.IsProcessing = true;
     try {
         if (simpleType.Content is XmlSchemaSimpleTypeList) {
             XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList)simpleType.Content;
             XmlSchemaDatatype datatype;
             simpleType.SetBaseSchemaType(DatatypeImplementation.AnySimpleType); 
             if (list.ItemTypeName.IsEmpty) {
                 CompileSimpleType(list.ItemType);
                 list.BaseItemType = list.ItemType;
                 datatype = list.ItemType.Datatype;
             }
             else {
                 XmlSchemaSimpleType type = GetSimpleType(list.ItemTypeName);
                 if (type != null) {
                     if ((type.FinalResolved & XmlSchemaDerivationMethod.List) != 0) {
                         SendValidationEvent(Res.Sch_BaseFinalList, simpleType);
                     }
                     list.BaseItemType = type;
                     datatype = type.Datatype;
                 }
                 else {
                     throw new XmlSchemaException(Res.Sch_UndeclaredSimpleType, list.ItemTypeName.ToString(), list);   
                 }
             }
             simpleType.SetDatatype(datatype.DeriveByList(simpleType));
             simpleType.SetDerivedBy(XmlSchemaDerivationMethod.List);
         }
         else if (simpleType.Content is XmlSchemaSimpleTypeRestriction) {
             XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)simpleType.Content;
             XmlSchemaDatatype datatype;
             if (restriction.BaseTypeName.IsEmpty) {
                 CompileSimpleType(restriction.BaseType);
                 simpleType.SetBaseSchemaType(restriction.BaseType);
                 datatype = restriction.BaseType.Datatype;
             }
             else if (simpleType.Redefined != null && restriction.BaseTypeName == simpleType.Redefined.QualifiedName) {
                 CompileSimpleType((XmlSchemaSimpleType)simpleType.Redefined);
                 simpleType.SetBaseSchemaType(simpleType.Redefined.BaseXmlSchemaType);
                 datatype = simpleType.Redefined.Datatype;
             }
             else {
                 if (restriction.BaseTypeName.Equals(DatatypeImplementation.QnAnySimpleType)) {
                     XmlSchema parentSchema = Preprocessor.GetParentSchema(simpleType);
                     if (parentSchema.TargetNamespace != XmlSchema.Namespace) { //If it is not SForS, then error
                         throw new XmlSchemaException(Res.Sch_InvalidSimpleTypeRestriction, restriction.BaseTypeName.ToString(), simpleType);   
                     }
                 }
                 XmlSchemaSimpleType type = GetSimpleType(restriction.BaseTypeName);
                 if (type != null) {
                     if ((type.FinalResolved & XmlSchemaDerivationMethod.Restriction) != 0) {
                         SendValidationEvent(Res.Sch_BaseFinalRestriction, simpleType);
                     }
                     simpleType.SetBaseSchemaType(type);
                     datatype = type.Datatype;
                 }
                 else {
                     throw new XmlSchemaException(Res.Sch_UndeclaredSimpleType, restriction.BaseTypeName.ToString(), restriction);   
                 }
             }
             simpleType.SetDatatype(datatype.DeriveByRestriction(restriction.Facets, NameTable, simpleType));
             simpleType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
         }
         else { //simpleType.Content is XmlSchemaSimpleTypeUnion
             XmlSchemaSimpleType[] baseTypes = CompileBaseMemberTypes(simpleType);
             simpleType.SetBaseSchemaType(DatatypeImplementation.AnySimpleType);
             simpleType.SetDatatype(XmlSchemaDatatype.DeriveByUnion(baseTypes, simpleType));
             simpleType.SetDerivedBy(XmlSchemaDerivationMethod.Union);
         }
     } 
     catch (XmlSchemaException e) {
         if (e.SourceSchemaObject == null) {
             e.SetSource(simpleType);
         }
         SendValidationEvent(e);
         simpleType.SetDatatype(DatatypeImplementation.AnySimpleType.Datatype);
     } 
     finally {
         SchemaElementDecl decl = new SchemaElementDecl();
         decl.ContentValidator = ContentValidator.TextOnly;
         decl.SchemaType = simpleType;
         decl.Datatype = simpleType.Datatype;
         simpleType.ElementDecl = decl;
         simpleType.IsProcessing = false;
     }
 }
Esempio n. 28
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();
        }
Esempio n. 29
0
 private SchemaElementDecl ThoroughGetElementDecl(SchemaElementDecl elementDecl, XmlQualifiedName xsiType, string xsiNil)
 {
     if (elementDecl == null)
     {
         elementDecl = base.schemaInfo.GetElementDecl(base.elementName);
     }
     if (elementDecl != null)
     {
         if (xsiType.IsEmpty)
         {
             if (elementDecl.IsAbstract)
             {
                 base.SendValidationEvent("Sch_AbstractElement", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace));
                 elementDecl = null;
             }
         }
         else if ((xsiNil != null) && xsiNil.Equals("true"))
         {
             base.SendValidationEvent("Sch_XsiNilAndType");
         }
         else
         {
             SchemaElementDecl decl;
             if (!base.schemaInfo.ElementDeclsByType.TryGetValue(xsiType, out decl) && (xsiType.Namespace == this.NsXs))
             {
                 XmlSchemaSimpleType simpleTypeFromXsdType = DatatypeImplementation.GetSimpleTypeFromXsdType(new XmlQualifiedName(xsiType.Name, this.NsXs));
                 if (simpleTypeFromXsdType != null)
                 {
                     decl = simpleTypeFromXsdType.ElementDecl;
                 }
             }
             if (decl == null)
             {
                 base.SendValidationEvent("Sch_XsiTypeNotFound", xsiType.ToString());
                 elementDecl = null;
             }
             else if (!XmlSchemaType.IsDerivedFrom(decl.SchemaType, elementDecl.SchemaType, elementDecl.Block))
             {
                 base.SendValidationEvent("Sch_XsiTypeBlockedEx", new string[] { xsiType.ToString(), XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace) });
                 elementDecl = null;
             }
             else
             {
                 elementDecl = decl;
             }
         }
         if ((elementDecl != null) && elementDecl.IsNillable)
         {
             if (xsiNil != null)
             {
                 base.context.IsNill = XmlConvert.ToBoolean(xsiNil);
                 if (base.context.IsNill && (elementDecl.DefaultValueTyped != null))
                 {
                     base.SendValidationEvent("Sch_XsiNilAndFixed");
                 }
             }
             return(elementDecl);
         }
         if (xsiNil != null)
         {
             base.SendValidationEvent("Sch_InvalidXsiNill");
         }
     }
     return(elementDecl);
 }
Esempio n. 30
0
        private void CompileElement(XmlSchemaElement xe) {
            if (xe.Validating) {
                SendValidationEvent(Res.Sch_ElementCircularRef, xe);
                return;
            }
            if (xe.ElementDecl != null) {
                return;
            }
            xe.Validating = true;
            SchemaElementDecl decl = null;
            try {
                if (!xe.RefName.IsEmpty) {
                    XmlSchemaElement e = (XmlSchemaElement)this.schema.Elements[xe.RefName];
                    if (e == null) {
                        throw new XmlSchemaException(Res.Sch_UndeclaredElement, xe.RefName.ToString(), xe);
                    }  
                    CompileElement(e);
                    if (e.ElementDecl == null) {
                        throw new XmlSchemaException(Res.Sch_RefInvalidElement, xe.RefName.ToString(), xe);
                    }
                    xe.SetElementType(e.ElementType);
                    decl = e.ElementDecl.Clone();
                }
                else {
                    if (xe.SchemaType != null) {
                        xe.SetElementType(xe.SchemaType);
                    }
                    else if (!xe.SchemaTypeName.IsEmpty) {
                        XmlSchemaDatatype datatype;
                        xe.SetElementType(GetAnySchemaType(xe.SchemaTypeName, out datatype));
                        if (xe.ElementType == null) {
                            throw new XmlSchemaException(Res.Sch_UndeclaredType, xe.SchemaTypeName.ToString(), xe);   
                        }
                    }
                    else  if (!xe.SubstitutionGroup.IsEmpty) {
                        XmlSchemaElement examplar = (XmlSchemaElement)this.schema.Elements[xe.SubstitutionGroup];
                        if (examplar == null) {
                            throw new XmlSchemaException(Res.Sch_UndeclaredEquivClass, xe.SubstitutionGroup.Name.ToString(), xe);   
                        }
                        CompileElement(examplar);
                        xe.SetElementType(examplar.ElementType);
                        decl = examplar.ElementDecl.Clone();
                    }
                    else {
                        xe.SetElementType(XmlSchemaDatatype.AnyType);
                        decl = SchemaElementDecl.CreateAnyTypeElementDecl();
                    }
            
                    if (decl == null) {
                        Debug.Assert(xe.ElementType != null);
                        if (xe.ElementType is XmlSchemaComplexType) {
                            XmlSchemaComplexType complexType = (XmlSchemaComplexType)xe.ElementType;
                            CompileComplexType(complexType);
                            if (complexType.ElementDecl != null) {
                                decl = complexType.ElementDecl.Clone();
                                decl.LocalElements = complexType.LocalElementDecls;
                            }
                        } 
                        else if (xe.ElementType is XmlSchemaSimpleType) {
                            XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)xe.ElementType;
                            CompileSimpleType(simpleType);
                            if (simpleType.ElementDecl != null) {
                                decl = simpleType.ElementDecl.Clone();
                            }
                        } 
                        else {
                            decl = new SchemaElementDecl((XmlSchemaDatatype)xe.ElementType, this.schemaNames);
                        }
                    }
                    decl.Name = xe.QualifiedName;
                    decl.IsAbstract = xe.IsAbstract;
                    XmlSchemaComplexType ct = xe.ElementType as XmlSchemaComplexType;
                    if (ct != null) {
                        decl.IsAbstract |= ct.IsAbstract; 
                    }
                    decl.IsNillable = xe.IsNillable;
                    decl.Block |= xe.BlockResolved;
                }
                if (decl.Datatype != null) {
                    decl.Datatype.VerifySchemaValid(this.schema, xe);
                }

                if (xe.DefaultValue != null || xe.FixedValue != null) {
                    if (decl.Content.ContentType == CompiledContentModel.Type.Text) {
                        if (xe.DefaultValue != null) {
                            decl.Presence = SchemaDeclBase.Use.Default; 
                            decl.DefaultValueTyped = decl.Datatype.ParseValue(xe.DefaultValue, this.nameTable, this.namespaceManager);
                        }
                        else {
                            decl.Presence = SchemaDeclBase.Use.Fixed; 
                            decl.DefaultValueTyped = decl.Datatype.ParseValue(xe.FixedValue, this.nameTable, this.namespaceManager);
                        }
                    }
                    else if (decl.Content.ContentType != CompiledContentModel.Type.Mixed || !decl.Content.IsEmptiable) {
                        throw new XmlSchemaException(Res.Sch_ElementCannotHaveValue, xe);
                    }            
                }
                if (xe.HasConstraints) {
                    XmlSchemaObjectCollection constraints = xe.Constraints;
                    CompiledIdentityConstraint[] compiledConstraints = new CompiledIdentityConstraint[constraints.Count];
                    int idx = 0;
                    foreach(XmlSchemaIdentityConstraint constraint in constraints) {
                        CompileIdentityConstraint (constraint);
                        compiledConstraints[idx ++] = constraint.CompiledConstraint;
                    }
                    decl.Constraints = compiledConstraints;
                }
                xe.ElementDecl = decl;
            } 
            catch (XmlSchemaException e) {
                if (e.SourceSchemaObject == null) {
                    e.SetSource(xe);
                }
                SendValidationEvent(e);
                xe.ElementDecl = SchemaElementDecl.Empty;
            } 
            finally {
                xe.Validating = false;
            }
        }
 private void CompileComplexType(XmlSchemaComplexType complexType)
 {
     if (complexType.ElementDecl == null)
     {
         if (complexType.IsProcessing)
         {
             base.SendValidationEvent("Sch_TypeCircularRef", complexType);
         }
         else
         {
             complexType.IsProcessing = true;
             if (complexType.ContentModel != null)
             {
                 if (complexType.ContentModel is XmlSchemaSimpleContent)
                 {
                     XmlSchemaSimpleContent contentModel = (XmlSchemaSimpleContent) complexType.ContentModel;
                     complexType.SetContentType(XmlSchemaContentType.TextOnly);
                     if (contentModel.Content is XmlSchemaSimpleContentExtension)
                     {
                         this.CompileSimpleContentExtension(complexType, (XmlSchemaSimpleContentExtension) contentModel.Content);
                     }
                     else
                     {
                         this.CompileSimpleContentRestriction(complexType, (XmlSchemaSimpleContentRestriction) contentModel.Content);
                     }
                 }
                 else
                 {
                     XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent) complexType.ContentModel;
                     if (complexContent.Content is XmlSchemaComplexContentExtension)
                     {
                         this.CompileComplexContentExtension(complexType, complexContent, (XmlSchemaComplexContentExtension) complexContent.Content);
                     }
                     else
                     {
                         this.CompileComplexContentRestriction(complexType, complexContent, (XmlSchemaComplexContentRestriction) complexContent.Content);
                     }
                 }
             }
             else
             {
                 complexType.SetBaseSchemaType(XmlSchemaComplexType.AnyType);
                 this.CompileLocalAttributes(XmlSchemaComplexType.AnyType, complexType, complexType.Attributes, complexType.AnyAttribute, XmlSchemaDerivationMethod.Restriction);
                 complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
                 complexType.SetContentTypeParticle(this.CompileContentTypeParticle(complexType.Particle, true));
                 complexType.SetContentType(this.GetSchemaContentType(complexType, null, complexType.ContentTypeParticle));
             }
             bool flag = false;
             foreach (XmlSchemaAttribute attribute in complexType.AttributeUses.Values)
             {
                 if (attribute.Use != XmlSchemaUse.Prohibited)
                 {
                     XmlSchemaDatatype datatype = attribute.Datatype;
                     if ((datatype != null) && (datatype.TokenizedType == XmlTokenizedType.ID))
                     {
                         if (flag)
                         {
                             base.SendValidationEvent("Sch_TwoIdAttrUses", complexType);
                         }
                         else
                         {
                             flag = true;
                         }
                     }
                 }
             }
             SchemaElementDecl decl = new SchemaElementDecl {
                 ContentValidator = this.CompileComplexContent(complexType),
                 SchemaType = complexType,
                 IsAbstract = complexType.IsAbstract,
                 Datatype = complexType.Datatype,
                 Block = complexType.BlockResolved,
                 AnyAttribute = complexType.AttributeWildcard
             };
             foreach (XmlSchemaAttribute attribute2 in complexType.AttributeUses.Values)
             {
                 if (attribute2.Use == XmlSchemaUse.Prohibited)
                 {
                     if (!decl.ProhibitedAttributes.ContainsKey(attribute2.QualifiedName))
                     {
                         decl.ProhibitedAttributes.Add(attribute2.QualifiedName, attribute2.QualifiedName);
                     }
                 }
                 else if ((!decl.AttDefs.ContainsKey(attribute2.QualifiedName) && (attribute2.AttDef != null)) && ((attribute2.AttDef.Name != XmlQualifiedName.Empty) && (attribute2.AttDef != SchemaAttDef.Empty)))
                 {
                     decl.AddAttDef(attribute2.AttDef);
                 }
             }
             complexType.ElementDecl = decl;
             complexType.IsProcessing = false;
         }
     }
 }
 internal void Reset()
 {
     this._Name = XmlQualifiedName.Empty;
     this._Prefix = null;
     this._TypeName = XmlQualifiedName.Empty;
     this._TypePrefix = null;
     this._Default = null;
     this._Revises = null;
     this._MaxOccurs = 1;
     this._MinOccurs = 1;
     this._Checking = false;
     this._ElementDecl = null;
     this._Next = null;
     this._Attdef = null;
 }
 private static void XDR_BuildElement_Type(XdrBuilder builder, object obj, string prefix)
 {
     XmlQualifiedName key = (XmlQualifiedName) obj;
     if (!builder._SchemaInfo.ElementDecls.ContainsKey(key) && (((SchemaElementDecl) builder._UndeclaredElements[key]) == null))
     {
         SchemaElementDecl decl = new SchemaElementDecl(key, prefix);
         builder._UndeclaredElements.Add(key, decl);
     }
     builder._ElementDef._HasType = true;
     if (builder._ElementDef._ExistTerminal)
     {
         builder.AddOrder();
     }
     else
     {
         builder._ElementDef._ExistTerminal = true;
     }
     builder._contentValidator.AddName(key, null);
 }
        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();
        }
Esempio n. 35
0
        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:
                        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")
                    {
                        attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                        if (attrDef.TokenizedType != XmlTokenizedType.ENUMERATION)
                        {
                            Throw(SR.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition);
                        }
                    }
                    else if (attrDef.Name.Name == "lang")
                    {
                        attrDef.Reserved = SchemaAttDef.Reserve.XmlLang;
                    }
                }

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

        UnexpectedError:
            OnUnexpectedError();
        }
Esempio n. 36
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;
#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();
        }
Esempio n. 37
0
        private void ParseElementDecl()
        {
            // element name
            if (GetToken(true) != Token.QName)
            {
                goto UnexpectedError;
            }

            // get schema decl for element
            SchemaElementDecl elementDecl = null;
            XmlQualifiedName name = GetNameQualified(true);

            if (_schemaInfo.ElementDecls.TryGetValue(name, out elementDecl))
            {
            }
            else
            {
                if (_schemaInfo.UndeclaredElementDecls.TryGetValue(name, out elementDecl))
                {
                    _schemaInfo.UndeclaredElementDecls.Remove(name);
                }
                else
                {
                    elementDecl = new SchemaElementDecl(name, name.Namespace);
                }
                _schemaInfo.ElementDecls.Add(name, elementDecl);
            }
            elementDecl.IsDeclaredInExternal = !ParsingInternalSubset;

            // content spec
            switch (GetToken(true))
            {
                case Token.EMPTY:
                case Token.ANY:
                    break;
                case Token.LeftParen:
                    switch (GetToken(false))
                    {
                        case Token.PCDATA:
                            ParseElementMixedContentNoValidation();
                            break;
                        case Token.None:
                            ParseElementOnlyContentNoValidation();
                            break;
                        default:
                            goto UnexpectedError;
                    }
                    break;
                default:
                    goto UnexpectedError;
            }
            if (GetToken(false) != Token.GreaterThan)
            {
                ThrowUnexpectedToken(_curPos, ">");
            }
            return;

        UnexpectedError:
            OnUnexpectedError();
        }
Esempio n. 38
0
 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;
 }
        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);
        }
Esempio n. 40
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;
        }
Esempio n. 41
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);
        }
Esempio n. 42
0
        private void ProcessElement() {
            int count = reader.AttributeCount;
            XmlQualifiedName xsiType = XmlQualifiedName.Empty;
            if (reader.Depth == 0 && SchemaInfo.SchemaType != SchemaType.DTD && validationFlag != ValidationType.DTD && validationFlag != ValidationType.None) {
                LoadSchema(string.Empty, null);
            }

            string[] xsiSchemaLocation = null;
            string xsiNoNamespaceSchemaLocation = null;
            string xsiNil = null;
            if (SchemaInfo.SchemaType != SchemaType.DTD && validationFlag != ValidationType.DTD && validationFlag != ValidationType.None) {
                for (int i = 0; i < count ; i++) {
                    reader.MoveToAttribute(i);
                    string objectNs = reader.NamespaceURI;
                    string objectName = reader.LocalName;
                    if (Ref.Equal(objectNs, schemaNames.NsXmlNs)) {
                        LoadSchema(reader.Value, null);
                        if (isProcessContents) {
                            nsManager.AddNamespace(reader.Prefix == string.Empty ? string.Empty : reader.LocalName, reader.Value);
                        }
                    }
                    else if ((validationFlag != ValidationType.XDR) && Ref.Equal(objectNs, schemaNames.NsXsi)) {
                        if (Ref.Equal(objectName, schemaNames.XsiSchemaLocation)) {
                            xsiSchemaLocation = (string[])dtStringArray.ParseValue(reader.Value, nameTable, nsManager);
                        }
                        else if (Ref.Equal(objectName, schemaNames.XsiNoNamespaceSchemaLocation)) {
                            xsiNoNamespaceSchemaLocation = reader.Value;
                        }
                        else if (Ref.Equal(objectName, schemaNames.XsiType)) {
                            xsiType = (XmlQualifiedName)dtQName.ParseValue(reader.Value, nameTable, nsManager);
                        }
                        else if (Ref.Equal(objectName, schemaNames.XsiNil)) {
                            xsiNil = reader.Value;
                        }
                        SchemaInfo.SchemaType = SchemaType.XSD;
                    }
                    else if (
                        SchemaInfo.SchemaType != SchemaType.XSD &&
                        Ref.Equal(objectNs, schemaNames.QnDtDt.Namespace) &&
                        Ref.Equal(objectName, schemaNames.QnDtDt.Name)
                    ) {
                        reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(reader.Value);
                        SchemaInfo.SchemaType = SchemaType.XDR;
                    }
                }
            }
            if (count > 0) {
                reader.MoveToElement();
            }
            if (xsiNoNamespaceSchemaLocation != null) {

                LoadSchema(string.Empty, xsiNoNamespaceSchemaLocation);
            }
            if (xsiSchemaLocation != null) {
                for (int i = 0; i < xsiSchemaLocation.Length - 1; i += 2) {
                    LoadSchema((string)xsiSchemaLocation[i], (string)xsiSchemaLocation[i + 1]);
                }
            }

            if (HasSchema) {
                if (processContents == XmlSchemaContentProcessing.Skip) {
                    nextElement = null;
                }
                else {
                    nextElement = SchemaInfo.GetElementDecl(this.name, (context != null) ? context.ElementDecl : null);
                    if (nextElement != null) {
                        if (xsiType.IsEmpty) {
                            if (nextElement.IsAbstract) {
                                SendValidationEvent(Res.Sch_AbstractElement, this.name.ToString());
                                nextElement = null;
                            }
                        }
                        else if(xsiNil != null && xsiNil.Equals("true")) {
                            SendValidationEvent(Res.Sch_XsiNilAndType);
                        }
                        else {
                            SchemaElementDecl nextElementXsi = (SchemaElementDecl)SchemaInfo.ElementDeclsByType[xsiType];
                            if (nextElementXsi == null && xsiType.Namespace == schemaNames.NsXsd) {
                                XmlSchemaDatatype datatype = XmlSchemaDatatype.FromTypeName(xsiType.Name);
                                if (datatype != null) {
                                    nextElementXsi = new SchemaElementDecl(datatype, this.schemaNames);
                                }
                            }
                            if (nextElementXsi == null) {
                                SendValidationEvent(Res.Sch_XsiTypeNotFound, xsiType.ToString());
                                nextElement = null;
                            }
                            else if (!XmlSchemaType.IsDerivedFrom(
                                (nextElementXsi.SchemaType == null ? (object)nextElementXsi.Datatype : (object)nextElementXsi.SchemaType),
                                (nextElement.SchemaType == null ? (object)nextElement.Datatype : (object)nextElement.SchemaType),
                                nextElement.Block
                            )) {
                                SendValidationEvent(Res.Sch_XsiTypeBlocked, this.name.ToString());
                                nextElement = null;
                            }
                            else {
                                nextElement = nextElementXsi;
                            }

                        }
                    }
                }

                PushElementDecl(this.name.Namespace, reader.Prefix, reader.Depth);
                if (context.ElementDecl != null || SchemaInfo.SchemaType == SchemaType.XSD) {
                    if (context.ElementDecl != null && context.ElementDecl.IsNillable) {
                        if (xsiNil != null) {
                            context.IsNill = XmlConvert.ToBoolean(xsiNil);
                            if (context.IsNill && context.ElementDecl.DefaultValueTyped != null) {
                                SendValidationEvent(Res.Sch_XsiNilAndFixed);
                            }
                        }
                    }
                    else if (xsiNil != null) {
                        SendValidationEvent(Res.Sch_InvalidXsiNill);
                    }

                    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 || this.startIDConstraint != -1) {
                            attPresence.Clear();
                        }
                    }

                    //foreach constraint in stack (including the current one)
                    if (this.startIDConstraint != -1) {
                        for (int i = this.startIDConstraint; i < this.validationStack.Length; i ++) {
                            // no constraint for this level
                            if (((ValidationState)(this.validationStack[i])).Constr == null) {
                                continue;
                            }

                            // else
                            foreach (ConstraintStruct conuct in ((ValidationState)(this.validationStack[i])).Constr) {
                                // check selector from here
                                if (conuct.axisSelector.MoveToStartElement(reader.LocalName, reader.NamespaceURI)) {
                                    // selector selects new node, activate a new set of fields
                                    Debug.WriteLine("Selector Match!");
                                    Debug.WriteLine("Name: " + reader.LocalName + "\t|\tURI: " + reader.NamespaceURI + "\n");
                                    KeySequence ks = new KeySequence (conuct.TableDim, positionInfo.LineNumber, positionInfo.LinePosition);
                                    int row = conuct.AddToTable (ks);                   // new line in table assigned to this set of fields
                                    int column = 0;
                                    foreach (Asttree field in conuct.constraint.Fields) {
                                        LocatedActiveAxis laxis = new LocatedActiveAxis (field, row, column ++);
                                        conuct.axisFields.Add (laxis);
                                    }
                                }

                                // axisFields is not null, but may be empty
                                foreach (LocatedActiveAxis laxis in conuct.axisFields) {
                                    // check field from here
                                    if (laxis.MoveToStartElement(reader.LocalName, reader.NamespaceURI)) {
                                        Debug.WriteLine("Element Field Match!");
                                        // checking simpleType / simpleContent
                                        if (nextElement != null) {      // nextElement can be null when xml/xsd are not valid
                                            if (nextElement.Datatype == null) {
                                                SendValidationEvent (Res.Sch_FieldSimpleTypeExpected, reader.LocalName);
                                            }
                                            else {
                                                // can't fill value here, wait till later....
                                                // fill type : xsdType
                                                laxis.isMatched = true;
                                                // since it's simpletyped element, the endchildren will come consequently... don't worry
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }

                    for (int i = 0; i < count ; i++) {
                        reader.MoveToAttribute(i);
                        if ((SchemaInfo.SchemaType == SchemaType.XSD || SchemaInfo.SchemaType == SchemaType.XDR) && (object)reader.NamespaceURI == (object)schemaNames.NsXmlNs) {
                            continue;
                        }
                        if (SchemaInfo.SchemaType == SchemaType.XSD && (object)reader.NamespaceURI == (object)schemaNames.NsXsi) {
                            continue;
                        }
                        this.name = QualifiedName(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        try {
                            bool skip;
                            attnDef = SchemaInfo.GetAttribute(context.ElementDecl, this.name, out skip);
                            if (attnDef != null) {
                                if (context.ElementDecl != null && (context.ElementDecl.HasRequiredAttribute || this.startIDConstraint != -1)) {
                                    attPresence.Add(attnDef.Name, attnDef);
                                }
                                reader.SchemaTypeObject = (attnDef.SchemaType != null) ? (object)attnDef.SchemaType : (object)attnDef.Datatype;
                                if (attnDef.Datatype != null) {

                                    // VC constraint:
                                    // The standalone document declaration must have the value "no" if any external markup declarations
                                    // contain declarations of attributes with values subject to normalization, where the attribute appears in
                                    // the document with a value which will change as a result of normalization,

                                    string attributeValue = reader.Value;
                                    if (reader.StandAlone && attnDef.IsDeclaredInExternal && attributeValue != reader.RawValue) {
                                        SendValidationEvent(Res.Sch_StandAloneNormalization, reader.Name);
                                    }

                                    // need to check the contents of this attribute to make sure
                                    // it is valid according to the specified attribute type.
                                    CheckValue(attributeValue, attnDef);
                                }
                            }
                            else if (ValidationFlag == ValidationType.Schema && !skip) {
                                SendValidationEvent(Res.Sch_NoAttributeSchemaFound, this.name.ToString(), XmlSeverityType.Warning);
                            }
                        }
                        catch (XmlSchemaException e) {
                            e.SetSource(reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition);
                            SendValidationEvent(e);
                        }

                        // for all constraint in the stack, i have to check this thing
                        IDCCheckAttr(reader.LocalName, reader.NamespaceURI, reader.TypedValueObject, reader.Value, attnDef);
                    }

                    if (count > 0) {
                        reader.MoveToElement();
                    }

                    // Add default attributes
                    if ( nextElement != null) {
                        foreach (SchemaAttDef attdef in nextElement.AttDefs.Values) {
                            if (attdef.Presence == SchemaDeclBase.Use.Default ||
                                attdef.Presence == SchemaDeclBase.Use.Fixed) {
                                // VC constraint:
                                // Standalone must be = "no" when any external markup declarations contain declarations of attributes
                                // with default values, if elements to which these attributes apply appear in the document without
                                // specifications of values for these attributes

                                // for default attribute i have to check too...
                                if (reader.AddDefaultAttribute(attdef) && reader.StandAlone && attdef.IsDeclaredInExternal) {
                                    SendValidationEvent(Res.Sch_UnSpecifiedDefaultAttributeInExternalStandalone, attdef.Name.Name);
                                }

                                // even default attribute i have to move to... but can't exist
                                if (! attPresence.Contains(attdef.Name)) {
                                    IDCCheckAttr(attdef.Name.Name, attdef.Name.Namespace, attdef.DefaultValueTyped, attdef.DefaultValueRaw, attdef);
                                }
                            }
                        }
                    }
                }
                BeginChildren();
                if (reader.IsEmptyElement) {
                    EndChildren();
                }
            }
            else {
                //couldnt find any schema for this element
                if( ValidationFlag == ValidationType.DTD && 0 == reader.Depth) {
                    // this warning only needs to be on the documentElement
                    SendValidationEvent(Res.Xml_NoDTDPresent, this.name.ToString(), XmlSeverityType.Warning);
                }
                else if(ValidationFlag == ValidationType.Schema) {
                    SendValidationEvent(Res.Sch_NoElementSchemaFound, this.name.ToString(),XmlSeverityType.Warning);

                    for (int i = 0; i < count ; i++) {
                        reader.MoveToAttribute(i);
                        if ((object)reader.NamespaceURI == (object)schemaNames.NsXmlNs
                            ||(ValidationType.Schema == ValidationFlag && (object)reader.NamespaceURI == (object)schemaNames.NsXsi)) {
                            continue;
                        }
                        this.name = QualifiedName(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        SendValidationEvent(Res.Sch_NoAttributeSchemaFound, this.name.ToString(), XmlSeverityType.Warning);
                    }
                    reader.MoveToElement();
                }
            }

        }
 private SchemaElementDecl ThoroughGetElementDecl(SchemaElementDecl elementDecl, XmlQualifiedName xsiType, string xsiNil)
 {
     if (elementDecl == null)
     {
         elementDecl = schemaInfo.GetElementDecl(elementName);
     }
     if (elementDecl != null)
     {
         if (xsiType.IsEmpty)
         {
             if (elementDecl.IsAbstract)
             {
                 SendValidationEvent(Res.Sch_AbstractElement, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                 elementDecl = null;
             }
         }
         else if (xsiNil != null && xsiNil.Equals("true"))
         {
             SendValidationEvent(Res.Sch_XsiNilAndType);
         }
         else
         {
             SchemaElementDecl elementDeclXsi;
             if (!schemaInfo.ElementDeclsByType.TryGetValue(xsiType, out elementDeclXsi) && xsiType.Namespace == NsXs)
             {
                 XmlSchemaSimpleType simpleType = DatatypeImplementation.GetSimpleTypeFromXsdType(new XmlQualifiedName(xsiType.Name, NsXs));
                 if (simpleType != null)
                 {
                     elementDeclXsi = simpleType.ElementDecl;
                 }
             }
             if (elementDeclXsi == null)
             {
                 SendValidationEvent(Res.Sch_XsiTypeNotFound, xsiType.ToString());
                 elementDecl = null;
             }
             else if (!XmlSchemaType.IsDerivedFrom(elementDeclXsi.SchemaType, elementDecl.SchemaType, elementDecl.Block))
             {
                 SendValidationEvent(Res.Sch_XsiTypeBlockedEx, new string[] { xsiType.ToString(), XmlSchemaValidator.QNameString(context.LocalName, context.Namespace) });
                 elementDecl = null;
             }
             else
             {
                 elementDecl = elementDeclXsi;
             }
         }
         if (elementDecl != null && elementDecl.IsNillable)
         {
             if (xsiNil != null)
             {
                 context.IsNill = XmlConvert.ToBoolean(xsiNil);
                 if (context.IsNill && elementDecl.DefaultValueTyped != null)
                 {
                     SendValidationEvent(Res.Sch_XsiNilAndFixed);
                 }
             }
         }
         else if (xsiNil != null)
         {
             SendValidationEvent(Res.Sch_InvalidXsiNill);
         }
     }
     return(elementDecl);
 }
Esempio n. 44
0
        internal void Validate(ValidationType valType) {
            if (ValidationType.None != valType) {
                Validate();
                return;
            }

            if (XmlNodeType.Element == reader.NodeType) {
                this.name = QualifiedName(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                nextElement = SchemaInfo.GetElementDecl(this.name, (context != null) ? context.ElementDecl : null);

                if (null == nextElement) {
                    //this could be an undeclared element
                    nextElement = (SchemaElementDecl)(SchemaInfo.UndeclaredElementDecls[this.name]);
                    if (nextElement != null) {
                        //add default attributes
                        foreach (SchemaAttDef attdef in nextElement.AttDefs.Values) {
                                if (attdef.Presence == SchemaDeclBase.Use.Default ||
                                     attdef.Presence == SchemaDeclBase.Use.Fixed) {
                                        reader.AddDefaultAttribute(attdef);
                                }
                        }
                        return;
                    }
                    return;
                }
                int count = reader.AttributeCount;

                for (int i = 0; i < count ; i++) {
                    reader.MoveToAttribute(i);

                    this.name = QualifiedName(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                    attnDef =  nextElement.GetAttDef(this.name);
                    if (attnDef != null) {
                        reader.SchemaTypeObject = (attnDef.SchemaType != null) ? (object)attnDef.SchemaType : (object)attnDef.Datatype;
                    }
                    else  {
                        reader.SchemaTypeObject = dtCDATA;
                    }
                }

                reader.MoveToElement();
                // Add default attributes
                foreach (SchemaAttDef attdef in nextElement.AttDefs.Values) {
                    if (attdef.Presence == SchemaDeclBase.Use.Default ||
                        attdef.Presence == SchemaDeclBase.Use.Fixed) {
                        reader.AddDefaultAttribute(attdef);
                    }
                }
            }

        }
Esempio n. 45
0
        private void ParseElementDecl() {

            // element name
            if ( GetToken( true ) != Token.QName ) {
                goto UnexpectedError;
            }

            // get schema decl for element
            SchemaElementDecl elementDecl = null;
            XmlQualifiedName name = GetNameQualified( true );
            elementDecl = (SchemaElementDecl)schemaInfo.ElementDecls[name];

            if ( elementDecl != null ) {
                if ( validate ) {
                    SendValidationEvent( curPos - name.Name.Length, XmlSeverityType.Error, Res.Sch_DupElementDecl, GetNameString() );
                }
            }
            else {
                if ( ( elementDecl = (SchemaElementDecl)schemaInfo.UndeclaredElementDecls[name] ) != null ) {
                    schemaInfo.UndeclaredElementDecls.Remove( name );
                }
                else {
                    elementDecl = new SchemaElementDecl( name, name.Namespace, SchemaType.DTD );
                }
                schemaInfo.ElementDecls.Add( name, elementDecl );
            }
            elementDecl.IsDeclaredInExternal = !ParsingInternalSubset;

            // content spec
            switch ( GetToken( true ) ) {
                case Token.EMPTY:
                    elementDecl.ContentValidator = ContentValidator.Empty;
                    goto End;
                case Token.ANY:
                    elementDecl.ContentValidator = ContentValidator.Any;
                    goto End;
                case Token.LeftParen:
                    int startParenEntityId = currentEntityId;
                    switch ( GetToken( false ) ) {
                        case Token.PCDATA:
                        {
                            ParticleContentValidator pcv = new ParticleContentValidator( XmlSchemaContentType.Mixed );
                            pcv.Start();
                            pcv.OpenGroup();

                            ParseElementMixedContent( pcv, startParenEntityId );

                            elementDecl.ContentValidator = pcv.Finish( true );
                            goto End;
                        }
                        case Token.None:
                        {
                            ParticleContentValidator pcv = null;
                            pcv = new ParticleContentValidator( XmlSchemaContentType.ElementOnly );
                            pcv.Start();
                            pcv.OpenGroup();

                            ParseElementOnlyContent( pcv, startParenEntityId );

                            elementDecl.ContentValidator = pcv.Finish( true );
                            goto End;
                        }
                        default:
                            goto UnexpectedError;
                    }
                default:
                    goto UnexpectedError;
            }
    End:
            if ( GetToken( false ) != Token.GreaterThan ) {
                ThrowUnexpectedToken( curPos, ">" );
            }
            return;

            UnexpectedError:
                OnUnexpectedError();
        }
        private SchemaElementDecl CheckXsiTypeAndNil(SchemaElementDecl elementDecl, string xsiType, string xsiNil, ref bool declFound) {
            XmlQualifiedName xsiTypeName = XmlQualifiedName.Empty;
            if (xsiType != null) {
                object typedVal = null;
                Exception exception = dtQName.TryParseValue(xsiType, nameTable, nsResolver, out typedVal);
                if (exception != null) {
                    SendValidationEvent(Res.Sch_InvalidValueDetailedAttribute, new string[] { "type", xsiType, dtQName.TypeCodeString, exception.Message }, exception);
                }
                else {
                    xsiTypeName = typedVal as XmlQualifiedName;
                }
            }
            if (elementDecl != null) { //nillable is not dependent on xsi:type.
                if (elementDecl.IsNillable) {
                    if (xsiNil != null) {
                        context.IsNill = XmlConvert.ToBoolean(xsiNil);
                        if (context.IsNill && elementDecl.Presence == SchemaDeclBase.Use.Fixed) {
                            Debug.Assert(elementDecl.DefaultValueTyped != null);				
                            SendValidationEvent(Res.Sch_XsiNilAndFixed);
                        }
                    }
                }
                else if (xsiNil != null) {
                    SendValidationEvent(Res.Sch_InvalidXsiNill);
                }
            }
            if (xsiTypeName.IsEmpty) {
                if (elementDecl != null && elementDecl.IsAbstract) {
                    SendValidationEvent(Res.Sch_AbstractElement, QNameString(context.LocalName, context.Namespace));
                    elementDecl = null;
                }
            }
            else {
                SchemaElementDecl elementDeclXsi = compiledSchemaInfo.GetTypeDecl(xsiTypeName);
                XmlSeverityType severity = XmlSeverityType.Warning;
                if (HasSchema && processContents == XmlSchemaContentProcessing.Strict) {
                    severity = XmlSeverityType.Error;
                }
                if (elementDeclXsi == null && xsiTypeName.Namespace == NsXs) {
                    XmlSchemaType schemaType = DatatypeImplementation.GetSimpleTypeFromXsdType(xsiTypeName);
                    if (schemaType == null) { //try getting complexType - xs:anyType
                        schemaType = XmlSchemaType.GetBuiltInComplexType(xsiTypeName);
                    }
                    if (schemaType != null) {
                        elementDeclXsi = schemaType.ElementDecl;
                    }

                }
                if (elementDeclXsi == null) {
                    SendValidationEvent(Res.Sch_XsiTypeNotFound, xsiTypeName.ToString(), severity);
                    elementDecl = null;
                }
                else {
                    declFound = true;
                    if (elementDeclXsi.IsAbstract) {
                        SendValidationEvent(Res.Sch_XsiTypeAbstract, xsiTypeName.ToString(), severity);
                        elementDecl = null;
                    }
                    else if (elementDecl != null && !XmlSchemaType.IsDerivedFrom(elementDeclXsi.SchemaType,elementDecl.SchemaType,elementDecl.Block)) {
                        SendValidationEvent(Res.Sch_XsiTypeBlockedEx, new string[] { xsiTypeName.ToString(), QNameString(context.LocalName, context.Namespace) });
                        elementDecl = null;
                    }
                    else {
                        if (elementDecl != null) { //Get all element decl properties before assigning xsi:type decl; nillable already checked
                            elementDeclXsi = elementDeclXsi.Clone(); //Before updating properties onto xsi:type decl, clone it
                            elementDeclXsi.Constraints = elementDecl.Constraints;
                            elementDeclXsi.DefaultValueRaw = elementDecl.DefaultValueRaw;
                            elementDeclXsi.DefaultValueTyped = elementDecl.DefaultValueTyped;
                            elementDeclXsi.Block = elementDecl.Block;
                        }
                        context.ElementDeclBeforeXsi = elementDecl;
                        elementDecl = elementDeclXsi;
                    }
                }
            }
            return elementDecl;
        }
 private void CompileComplexType(XmlSchemaComplexType complexType) {
     if (complexType.ElementDecl != null) { //already compiled
         return;
     }
     if (complexType.IsProcessing) {
         SendValidationEvent(Res.Sch_TypeCircularRef, complexType);
         return;
     }
     complexType.IsProcessing = true;
     try {
         if (complexType.ContentModel != null) { //simpleContent or complexContent
             if (complexType.ContentModel is XmlSchemaSimpleContent) {
                 XmlSchemaSimpleContent simpleContent = (XmlSchemaSimpleContent)complexType.ContentModel;
                 complexType.SetContentType(XmlSchemaContentType.TextOnly);
                 if (simpleContent.Content is XmlSchemaSimpleContentExtension) {
                     CompileSimpleContentExtension(complexType, (XmlSchemaSimpleContentExtension)simpleContent.Content);
                 }
                 else { //simpleContent.Content is XmlSchemaSimpleContentRestriction
                     CompileSimpleContentRestriction(complexType, (XmlSchemaSimpleContentRestriction)simpleContent.Content);
                 }
             }
             else { // complexType.ContentModel is XmlSchemaComplexContent
                 XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)complexType.ContentModel;
                 if (complexContent.Content is XmlSchemaComplexContentExtension) {
                     CompileComplexContentExtension(complexType, complexContent, (XmlSchemaComplexContentExtension)complexContent.Content);
                 }
                 else { // complexContent.Content is XmlSchemaComplexContentRestriction
                     CompileComplexContentRestriction(complexType, complexContent, (XmlSchemaComplexContentRestriction)complexContent.Content);
                 }
             }
         }
         else { //equals XmlSchemaComplexContent with baseType is anyType
                 complexType.SetBaseSchemaType(XmlSchemaComplexType.AnyType);
                 CompileLocalAttributes(XmlSchemaComplexType.AnyType, complexType, complexType.Attributes, complexType.AnyAttribute, XmlSchemaDerivationMethod.Restriction);
                 complexType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
                 complexType.SetContentTypeParticle(CompileContentTypeParticle(complexType.Particle));
                 complexType.SetContentType(GetSchemaContentType(complexType, null, complexType.ContentTypeParticle));
         }
         if (complexType.ContainsIdAttribute(true)) {
             SendValidationEvent(Res.Sch_TwoIdAttrUses, complexType);
         }
         SchemaElementDecl decl = new SchemaElementDecl();
         decl.ContentValidator = CompileComplexContent(complexType);
         decl.SchemaType = complexType;
         decl.IsAbstract = complexType.IsAbstract;
         decl.Datatype = complexType.Datatype;
         decl.Block = complexType.BlockResolved;
         decl.AnyAttribute = complexType.AttributeWildcard;
         foreach(XmlSchemaAttribute attribute in complexType.AttributeUses.Values) {
             if (attribute.Use == XmlSchemaUse.Prohibited) {
                 if (!decl.ProhibitedAttributes.ContainsKey(attribute.QualifiedName)) {
                     decl.ProhibitedAttributes.Add(attribute.QualifiedName, attribute.QualifiedName);
                 }
             }
             else {
                 if (!decl.AttDefs.ContainsKey(attribute.QualifiedName) && attribute.AttDef != null && attribute.AttDef.Name != XmlQualifiedName.Empty && attribute.AttDef != SchemaAttDef.Empty) {
                     decl.AddAttDef(attribute.AttDef);
                 }
             }
         }
         complexType.ElementDecl = decl;
     }
     finally {
         complexType.IsProcessing = false;
     }
 }
 private void CheckRequiredAttributes(SchemaElementDecl currentElementDecl) {
     Debug.Assert(currentElementDecl != null);
     Dictionary<XmlQualifiedName, SchemaAttDef> attributeDefs = currentElementDecl.AttDefs;
     foreach(SchemaAttDef attdef in attributeDefs.Values) {
         if (attPresence[attdef.Name] == null) {
             if (attdef.Presence == SchemaDeclBase.Use.Required || attdef.Presence == SchemaDeclBase.Use.RequiredFixed) {
                 SendValidationEvent(Res.Sch_MissRequiredAttribute, attdef.Name.ToString());
             }
         }
     }
 }
 private SchemaElementDecl CheckXsiTypeAndNil(SchemaElementDecl elementDecl, string xsiType, string xsiNil, ref bool declFound)
 {
     XmlQualifiedName empty = XmlQualifiedName.Empty;
     if (xsiType != null)
     {
         object typedValue = null;
         Exception innerException = dtQName.TryParseValue(xsiType, this.nameTable, this.nsResolver, out typedValue);
         if (innerException != null)
         {
             this.SendValidationEvent("Sch_InvalidValueDetailedAttribute", new string[] { "type", xsiType, dtQName.TypeCodeString, innerException.Message }, innerException);
         }
         else
         {
             empty = typedValue as XmlQualifiedName;
         }
     }
     if (elementDecl != null)
     {
         if (elementDecl.IsNillable)
         {
             if (xsiNil != null)
             {
                 this.context.IsNill = XmlConvert.ToBoolean(xsiNil);
                 if (this.context.IsNill && (elementDecl.Presence == SchemaDeclBase.Use.Fixed))
                 {
                     this.SendValidationEvent("Sch_XsiNilAndFixed");
                 }
             }
         }
         else if (xsiNil != null)
         {
             this.SendValidationEvent("Sch_InvalidXsiNill");
         }
     }
     if (empty.IsEmpty)
     {
         if ((elementDecl != null) && elementDecl.IsAbstract)
         {
             this.SendValidationEvent("Sch_AbstractElement", QNameString(this.context.LocalName, this.context.Namespace));
             elementDecl = null;
         }
         return elementDecl;
     }
     SchemaElementDecl typeDecl = this.compiledSchemaInfo.GetTypeDecl(empty);
     XmlSeverityType warning = XmlSeverityType.Warning;
     if (this.HasSchema && (this.processContents == XmlSchemaContentProcessing.Strict))
     {
         warning = XmlSeverityType.Error;
     }
     if ((typeDecl == null) && (empty.Namespace == this.NsXs))
     {
         XmlSchemaType simpleTypeFromXsdType = DatatypeImplementation.GetSimpleTypeFromXsdType(empty);
         if (simpleTypeFromXsdType == null)
         {
             simpleTypeFromXsdType = XmlSchemaType.GetBuiltInComplexType(empty);
         }
         if (simpleTypeFromXsdType != null)
         {
             typeDecl = simpleTypeFromXsdType.ElementDecl;
         }
     }
     if (typeDecl == null)
     {
         this.SendValidationEvent("Sch_XsiTypeNotFound", empty.ToString(), warning);
         elementDecl = null;
         return elementDecl;
     }
     declFound = true;
     if (typeDecl.IsAbstract)
     {
         this.SendValidationEvent("Sch_XsiTypeAbstract", empty.ToString(), warning);
         elementDecl = null;
         return elementDecl;
     }
     if ((elementDecl != null) && !XmlSchemaType.IsDerivedFrom(typeDecl.SchemaType, elementDecl.SchemaType, elementDecl.Block))
     {
         this.SendValidationEvent("Sch_XsiTypeBlockedEx", new string[] { empty.ToString(), QNameString(this.context.LocalName, this.context.Namespace) });
         elementDecl = null;
         return elementDecl;
     }
     if (elementDecl != null)
     {
         typeDecl = typeDecl.Clone();
         typeDecl.Constraints = elementDecl.Constraints;
         typeDecl.DefaultValueRaw = elementDecl.DefaultValueRaw;
         typeDecl.DefaultValueTyped = elementDecl.DefaultValueTyped;
         typeDecl.Block = elementDecl.Block;
     }
     this.context.ElementDeclBeforeXsi = elementDecl;
     elementDecl = typeDecl;
     return elementDecl;
 }
Esempio n. 50
0
        //
        // Static methods
        //
#if !SILVERLIGHT
        internal static SchemaElementDecl CreateAnyTypeElementDecl()
        {
            SchemaElementDecl anyTypeElementDecl = new SchemaElementDecl();
            anyTypeElementDecl.Datatype = DatatypeImplementation.AnySimpleType.Datatype;
            return anyTypeElementDecl;
        }
Esempio n. 51
0
        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 SchemaElementDecl ThoroughGetElementDecl(SchemaElementDecl elementDecl, XmlQualifiedName xsiType, string xsiNil)
 {
     if (elementDecl == null)
     {
         elementDecl = base.schemaInfo.GetElementDecl(base.elementName);
     }
     if (elementDecl != null)
     {
         if (xsiType.IsEmpty)
         {
             if (elementDecl.IsAbstract)
             {
                 base.SendValidationEvent("Sch_AbstractElement", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace));
                 elementDecl = null;
             }
         }
         else if ((xsiNil != null) && xsiNil.Equals("true"))
         {
             base.SendValidationEvent("Sch_XsiNilAndType");
         }
         else
         {
             SchemaElementDecl decl;
             if (!base.schemaInfo.ElementDeclsByType.TryGetValue(xsiType, out decl) && (xsiType.Namespace == this.NsXs))
             {
                 XmlSchemaSimpleType simpleTypeFromXsdType = DatatypeImplementation.GetSimpleTypeFromXsdType(new XmlQualifiedName(xsiType.Name, this.NsXs));
                 if (simpleTypeFromXsdType != null)
                 {
                     decl = simpleTypeFromXsdType.ElementDecl;
                 }
             }
             if (decl == null)
             {
                 base.SendValidationEvent("Sch_XsiTypeNotFound", xsiType.ToString());
                 elementDecl = null;
             }
             else if (!XmlSchemaType.IsDerivedFrom(decl.SchemaType, elementDecl.SchemaType, elementDecl.Block))
             {
                 base.SendValidationEvent("Sch_XsiTypeBlockedEx", new string[] { xsiType.ToString(), XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace) });
                 elementDecl = null;
             }
             else
             {
                 elementDecl = decl;
             }
         }
         if ((elementDecl != null) && elementDecl.IsNillable)
         {
             if (xsiNil != null)
             {
                 base.context.IsNill = XmlConvert.ToBoolean(xsiNil);
                 if (base.context.IsNill && (elementDecl.DefaultValueTyped != null))
                 {
                     base.SendValidationEvent("Sch_XsiNilAndFixed");
                 }
             }
             return elementDecl;
         }
         if (xsiNil != null)
         {
             base.SendValidationEvent("Sch_InvalidXsiNill");
         }
     }
     return elementDecl;
 }
Esempio n. 53
0
        private void ParseElementDecl()
        {
            // element name
            if (GetToken(true) != Token.QName)
            {
                goto UnexpectedError;
            }

            // get schema decl for element
            SchemaElementDecl elementDecl = null;
            XmlQualifiedName name = GetNameQualified(true);

            if (_schemaInfo.ElementDecls.TryGetValue(name, out elementDecl))
            {
#if !SILVERLIGHT
                if (_validate)
                {
                    SendValidationEvent(_curPos - name.Name.Length, XmlSeverityType.Error, SR.Sch_DupElementDecl, GetNameString());
                }
#endif
            }
            else
            {
                if (_schemaInfo.UndeclaredElementDecls.TryGetValue(name, out elementDecl))
                {
                    _schemaInfo.UndeclaredElementDecls.Remove(name);
                }
                else
                {
                    elementDecl = new SchemaElementDecl(name, name.Namespace);
                }
                _schemaInfo.ElementDecls.Add(name, elementDecl);
            }
            elementDecl.IsDeclaredInExternal = !ParsingInternalSubset;

            // content spec
#if SILVERLIGHT
            switch ( GetToken( true ) ) {
                case Token.EMPTY:
                case Token.ANY:
                    break;
                case Token.LeftParen:
                    switch ( GetToken( false ) ) {
                        case Token.PCDATA:
                            ParseElementMixedContentNoValidation();
                            break;
                        case Token.None:
                            ParseElementOnlyContentNoValidation();
                            break;
                        default:
                            goto UnexpectedError;
                    }
                    break;
                default:
                    goto UnexpectedError;
            }
#else
            switch (GetToken(true))
            {
                case Token.EMPTY:
                    elementDecl.ContentValidator = ContentValidator.Empty;
                    break;
                case Token.ANY:
                    elementDecl.ContentValidator = ContentValidator.Any;
                    break;
                case Token.LeftParen:
                    int startParenEntityId = _currentEntityId;
                    switch (GetToken(false))
                    {
                        case Token.PCDATA:
                            {
                                ParticleContentValidator pcv = new ParticleContentValidator(XmlSchemaContentType.Mixed);
                                pcv.Start();
                                pcv.OpenGroup();

                                ParseElementMixedContent(pcv, startParenEntityId);

                                elementDecl.ContentValidator = pcv.Finish(true);
                                break;
                            }
                        case Token.None:
                            {
                                ParticleContentValidator pcv = null;
                                pcv = new ParticleContentValidator(XmlSchemaContentType.ElementOnly);
                                pcv.Start();
                                pcv.OpenGroup();

                                ParseElementOnlyContent(pcv, startParenEntityId);

                                elementDecl.ContentValidator = pcv.Finish(true);
                                break;
                            }
                        default:
                            goto UnexpectedError;
                    }
                    break;
                default:
                    goto UnexpectedError;
            }
#endif
            if (GetToken(false) != Token.GreaterThan)
            {
                ThrowUnexpectedToken(_curPos, ">");
            }
            return;

        UnexpectedError:
            OnUnexpectedError();
        }
Esempio n. 54
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();
        }
 private void CompileSimpleType(XmlSchemaSimpleType simpleType)
 {
     if (simpleType.IsProcessing)
     {
         throw new XmlSchemaException("Sch_TypeCircularRef", simpleType);
     }
     if (simpleType.ElementDecl == null)
     {
         simpleType.IsProcessing = true;
         try
         {
             if (simpleType.Content is XmlSchemaSimpleTypeList)
             {
                 XmlSchemaDatatype datatype;
                 XmlSchemaSimpleTypeList content = (XmlSchemaSimpleTypeList) simpleType.Content;
                 simpleType.SetBaseSchemaType(DatatypeImplementation.AnySimpleType);
                 if (content.ItemTypeName.IsEmpty)
                 {
                     this.CompileSimpleType(content.ItemType);
                     content.BaseItemType = content.ItemType;
                     datatype = content.ItemType.Datatype;
                 }
                 else
                 {
                     XmlSchemaSimpleType type = this.GetSimpleType(content.ItemTypeName);
                     if (type == null)
                     {
                         throw new XmlSchemaException("Sch_UndeclaredSimpleType", content.ItemTypeName.ToString(), simpleType);
                     }
                     if ((type.FinalResolved & XmlSchemaDerivationMethod.List) != XmlSchemaDerivationMethod.Empty)
                     {
                         base.SendValidationEvent("Sch_BaseFinalList", simpleType);
                     }
                     content.BaseItemType = type;
                     datatype = type.Datatype;
                 }
                 simpleType.SetDatatype(datatype.DeriveByList(simpleType));
                 simpleType.SetDerivedBy(XmlSchemaDerivationMethod.List);
             }
             else if (simpleType.Content is XmlSchemaSimpleTypeRestriction)
             {
                 XmlSchemaDatatype datatype2;
                 XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) simpleType.Content;
                 if (restriction.BaseTypeName.IsEmpty)
                 {
                     this.CompileSimpleType(restriction.BaseType);
                     simpleType.SetBaseSchemaType(restriction.BaseType);
                     datatype2 = restriction.BaseType.Datatype;
                 }
                 else if ((simpleType.Redefined != null) && (restriction.BaseTypeName == simpleType.Redefined.QualifiedName))
                 {
                     this.CompileSimpleType((XmlSchemaSimpleType) simpleType.Redefined);
                     simpleType.SetBaseSchemaType(simpleType.Redefined.BaseXmlSchemaType);
                     datatype2 = simpleType.Redefined.Datatype;
                 }
                 else
                 {
                     if (restriction.BaseTypeName.Equals(DatatypeImplementation.QnAnySimpleType))
                     {
                         throw new XmlSchemaException("Sch_InvalidSimpleTypeRestriction", restriction.BaseTypeName.ToString(), simpleType);
                     }
                     XmlSchemaSimpleType type2 = this.GetSimpleType(restriction.BaseTypeName);
                     if (type2 == null)
                     {
                         throw new XmlSchemaException("Sch_UndeclaredSimpleType", restriction.BaseTypeName.ToString(), simpleType);
                     }
                     if ((type2.FinalResolved & XmlSchemaDerivationMethod.Restriction) != XmlSchemaDerivationMethod.Empty)
                     {
                         base.SendValidationEvent("Sch_BaseFinalRestriction", simpleType);
                     }
                     simpleType.SetBaseSchemaType(type2);
                     datatype2 = type2.Datatype;
                 }
                 simpleType.SetDatatype(datatype2.DeriveByRestriction(restriction.Facets, base.NameTable, simpleType));
                 simpleType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
             }
             else
             {
                 XmlSchemaSimpleType[] types = this.CompileBaseMemberTypes(simpleType);
                 simpleType.SetBaseSchemaType(DatatypeImplementation.AnySimpleType);
                 simpleType.SetDatatype(XmlSchemaDatatype.DeriveByUnion(types, simpleType));
                 simpleType.SetDerivedBy(XmlSchemaDerivationMethod.Union);
             }
         }
         catch (XmlSchemaException exception)
         {
             if (exception.SourceSchemaObject == null)
             {
                 exception.SetSource(simpleType);
             }
             base.SendValidationEvent(exception);
             simpleType.SetDatatype(DatatypeImplementation.AnySimpleType.Datatype);
         }
         finally
         {
             SchemaElementDecl decl = new SchemaElementDecl {
                 ContentValidator = ContentValidator.TextOnly,
                 SchemaType = simpleType,
                 Datatype = simpleType.Datatype
             };
             simpleType.ElementDecl = decl;
             simpleType.IsProcessing = false;
         }
     }
 }
Esempio n. 56
0
 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;
 }