/// <remarks>
        /// An Attribute group can only be defined as a child of XmlSchema or in XmlSchemaRedefine.
        /// The other attributeGroup has type XmlSchemaAttributeGroupRef.
        ///  1. Name must be present
        /// </remarks>
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(errorCount);
            }

            errorCount = 0;

            if (redefinedObject != null)
            {
                errorCount += redefined.Compile(h, schema);
                if (errorCount == 0)
                {
                    redefined = (XmlSchemaAttributeGroup)redefinedObject;
                }
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);

            if (this.Name == null || this.Name == String.Empty)            //1
            {
                error(h, "Name is required in top level simpletype");
            }
            else if (!XmlSchemaUtil.CheckNCName(this.Name))            // b.1.2
            {
                error(h, "name attribute of a simpleType must be NCName");
            }
            else
            {
                this.qualifiedName = new XmlQualifiedName(this.Name, AncestorSchema.TargetNamespace);
            }

            if (this.AnyAttribute != null)
            {
                errorCount += this.AnyAttribute.Compile(h, schema);
            }

            foreach (XmlSchemaObject obj in Attributes)
            {
                if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    errorCount += attr.Compile(h, schema);
                }
                else if (obj is XmlSchemaAttributeGroupRef)
                {
                    XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)obj;
                    errorCount += gref.Compile(h, schema);
                }
                else
                {
                    error(h, "invalid type of object in Attributes property");
                }
            }
            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
        // 1. name must be present
        // 2. MinOccurs & MaxOccurs of the Particle must be absent
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

            if (Name == null)
            {
                error(h, "Required attribute name must be present");
            }
            else if (!XmlSchemaUtil.CheckNCName(this.name))
            {
                error(h, "attribute name must be NCName");
            }
            else
            {
                qualifiedName = new XmlQualifiedName(Name, AncestorSchema.TargetNamespace);
            }

            if (Particle == null)
            {
                error(h, "Particle is required");
            }
            else
            {
                if (Particle.MaxOccursString != null)
                {
                    Particle.error(h, "MaxOccurs must not be present when the Particle is a child of Group");
                }
                if (Particle.MinOccursString != null)
                {
                    Particle.error(h, "MinOccurs must not be present when the Particle is a child of Group");
                }

                Particle.Compile(h, schema);
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
        // 1. name and public must be present
        // public and system must be anyURI
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

            if (Name == null)
            {
                error(h, "Required attribute name must be present");
            }
            else if (!XmlSchemaUtil.CheckNCName(this.name))
            {
                error(h, "attribute name must be NCName");
            }
            else
            {
                qualifiedName = new XmlQualifiedName(Name, AncestorSchema.TargetNamespace);
            }

            if (Public == null)
            {
                error(h, "public must be present");
            }
            else if (!XmlSchemaUtil.CheckAnyUri(Public))
            {
                error(h, "public must be anyURI");
            }

            if (system != null && !XmlSchemaUtil.CheckAnyUri(system))
            {
                error(h, "system must be present and of Type anyURI");
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);

            return(errorCount);
        }
        /// <remarks>
        /// 1. name must be present
        /// 2. selector and field must be present
        /// </remarks>
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

            if (Name == null)
            {
                error(h, "Required attribute name must be present");
            }
            else if (!XmlSchemaUtil.CheckNCName(this.name))
            {
                error(h, "attribute name must be NCName");
            }
            else
            {
                this.qName = new XmlQualifiedName(Name, AncestorSchema.TargetNamespace);
                if (schema.NamedIdentities.Contains(qName))
                {
                    XmlSchemaIdentityConstraint existing =
                        schema.NamedIdentities [qName] as XmlSchemaIdentityConstraint;
                    error(h, String.Format("There is already same named identity constraint in this namespace. Existing item is at {0}({1},{2})", existing.SourceUri, existing.LineNumber, existing.LinePosition));
                }
                else
                {
                    schema.NamedIdentities.Add(qName, this);
                }
            }

            if (Selector == null)
            {
                error(h, "selector must be present");
            }
            else
            {
                Selector.isSelector = true;
                errorCount         += Selector.Compile(h, schema);
                if (selector.errorCount == 0)
                {
                    compiledSelector = new XsdIdentitySelector(Selector);
                }
            }
            if (errorCount > 0)
            {
                return(errorCount);                // fatal
            }
            if (Fields.Count == 0)
            {
                error(h, "atleast one field value must be present");
            }
            else
            {
                for (int i = 0; i < Fields.Count; i++)
                {
                    XmlSchemaXPath field = Fields [i] as XmlSchemaXPath;
                    if (field != null)
                    {
                        errorCount += field.Compile(h, schema);
                        if (field.errorCount == 0)
                        {
                            this.compiledSelector.AddField(new XsdIdentityField(field, i));
                        }
                    }
                    else
                    {
                        error(h, "Object of type " + Fields [i].GetType() + " is invalid in the Fields Collection");
                    }
                }
            }
            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
Beispiel #5
0
        /// <remarks>
        /// For a simple Type:
        ///		1. Content must be present
        ///		2. id if present, must have be a valid ID
        ///		a) If the simpletype is local
        ///			1-	are from <xs:complexType name="simpleType"> and <xs:complexType name="localSimpleType">
        ///			1. name  is prohibited
        ///			2. final is prohibited
        ///		b) If the simpletype is toplevel
        ///			1-  are from <xs:complexType name="simpleType"> and <xs:complexType name="topLevelSimpleType">
        ///			1. name is required, type must be NCName
        ///			2. Content is required
        ///			3. final can have values : #all | (list | union | restriction)
        ///			4. If final is set, finalResolved is same as final (but within the values of b.3)
        ///			5. If final is not set, the finalDefault of the schema (ie. only #all and restriction)
        ///			6. Base type is:
        ///				4.1 If restriction is chosen,the base type of restriction or elements
        ///				4.2 otherwise simple ur-type
        /// </remarks>
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

            errorCount = 0;

            if (this.islocal)            // a
            {
                if (this.Name != null)   // a.1
                {
                    error(h, "Name is prohibited in a local simpletype");
                }
                else
                {
                    this.QNameInternal = new XmlQualifiedName(this.Name, AncestorSchema.TargetNamespace);
                }
                if (this.Final != XmlSchemaDerivationMethod.None)                //a.2
                {
                    error(h, "Final is prohibited in a local simpletype");
                }
            }
            else                       //b
            {
                if (this.Name == null) //b.1
                {
                    error(h, "Name is required in top level simpletype");
                }
                else if (!XmlSchemaUtil.CheckNCName(this.Name))                // b.1.2
                {
                    error(h, "name attribute of a simpleType must be NCName");
                }
                else
                {
                    this.QNameInternal = new XmlQualifiedName(this.Name, AncestorSchema.TargetNamespace);
                }

                //NOTE: Although the FinalResolved can be Empty, it is not a valid value for Final
                //DEVIATION: If an error occurs, the finaldefault is always consulted. This deviates
                //			 from the way MS implementation works.
                switch (this.Final)                //b.3, b.4
                {
                case XmlSchemaDerivationMethod.All:
                    this.finalResolved = XmlSchemaDerivationMethod.All;
                    break;

                case XmlSchemaDerivationMethod.List:
                case XmlSchemaDerivationMethod.Union:
                case XmlSchemaDerivationMethod.Restriction:
                    this.finalResolved = Final;
                    break;

                default:
                    error(h, "The value of final attribute is not valid for simpleType");
                    goto case XmlSchemaDerivationMethod.None;

                // use assignment from finaldefault on schema.
                case XmlSchemaDerivationMethod.None:                         // b.5
                    XmlSchemaDerivationMethod flags =
                        (XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.List |
                         XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Union);
                    switch (schema.FinalDefault)
                    {
                    case XmlSchemaDerivationMethod.All:
                        finalResolved = XmlSchemaDerivationMethod.All;
                        break;

                    case XmlSchemaDerivationMethod.None:
                        finalResolved = XmlSchemaDerivationMethod.Empty;
                        break;

                    default:
                        finalResolved = schema.FinalDefault & flags;
                        break;
                    }
                    break;
                }
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);

            if (Content != null)
            {
                Content.OwnerType = this;
            }

            if (this.Content == null)            //a.3,b.2
            {
                error(h, "Content is required in a simpletype");
            }
            else if (Content is XmlSchemaSimpleTypeRestriction)
            {
                this.resolvedDerivedBy = XmlSchemaDerivationMethod.Restriction;
                errorCount            += ((XmlSchemaSimpleTypeRestriction)Content).Compile(h, schema);
            }
            else if (Content is XmlSchemaSimpleTypeList)
            {
                this.resolvedDerivedBy = XmlSchemaDerivationMethod.List;
                errorCount            += ((XmlSchemaSimpleTypeList)Content).Compile(h, schema);
            }
            else if (Content is XmlSchemaSimpleTypeUnion)
            {
                this.resolvedDerivedBy = XmlSchemaDerivationMethod.Union;
                errorCount            += ((XmlSchemaSimpleTypeUnion)Content).Compile(h, schema);
            }

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
Beispiel #6
0
        private void CompileCommon(ValidationEventHandler h, XmlSchema schema, bool refIsNotPresent)
        {
            if (refIsNotPresent)
            {
                if (Name == null)                       //a.4, b.1,
                {
                    error(h, "Required attribute name must be present");
                }
                else if (!XmlSchemaUtil.CheckNCName(Name))                // a.4.2, b1.2
                {
                    error(h, "attribute name must be NCName");
                }
                else if (Name == "xmlns")                // a.14 , b5
                {
                    error(h, "attribute name must not be xmlns");
                }
                else
                {
                    qualifiedName = new XmlQualifiedName(Name, targetNamespace);
                }

                if (SchemaType != null)
                {
                    if (SchemaTypeName != null && !SchemaTypeName.IsEmpty)                    // a.8
                    {
                        error(h, "attribute can't have both a type and <simpleType> content");
                    }

                    errorCount += SchemaType.Compile(h, schema);
                }

                if (SchemaTypeName != null && !XmlSchemaUtil.CheckQName(SchemaTypeName))
                {
                    error(h, SchemaTypeName + " is not a valid QName");
                }
            }
            else
            {
                if (RefName == null || RefName.IsEmpty)
                {
                    throw new InvalidOperationException("Error: Should Never Happen. refname must be present");
                }
                else
                {
                    qualifiedName = RefName;
                }
            }

            if (AncestorSchema.TargetNamespace == XmlSchema.InstanceNamespace && Name != "nil" && Name != "type" &&
                Name != "schemaLocation" && Name != "noNamespaceSchemaLocation")                    // a.15, a.16
            {
                error(h, "targetNamespace can't be " + XmlSchema.InstanceNamespace);
            }

            if (DefaultValue != null && FixedValue != null)            // a.6, b.3, c.3
            {
                error(h, "default and fixed must not both be present in an Attribute");
            }

            if (DefaultValue != null && Use != XmlSchemaUse.None && Use != XmlSchemaUse.Optional)
            {
                error(h, "if default is present, use must be optional");
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);
        }