Beispiel #1
0
        /// <remarks>
        /// 1. id must be of type ID
        /// 2. namespace can have one of the following values:
        ///		a) ##any or ##other
        ///		b) list of anyURI and ##targetNamespace and ##local
        /// </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;

            wildcard.TargetNamespace = AncestorSchema.TargetNamespace;
            if (wildcard.TargetNamespace == null)
            {
                wildcard.TargetNamespace = "";
            }

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

            wildcard.Compile(Namespace, h, schema);

            if (processing == XmlSchemaContentProcessing.None)
            {
                wildcard.ResolvedProcessing = XmlSchemaContentProcessing.Strict;
            }
            else
            {
                wildcard.ResolvedProcessing = processing;
            }

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

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

            if (Items.Count == 0)
            {
                this.warn(h, "Empty choice is unsatisfiable if minOccurs not equals to 0");
            }

            foreach (XmlSchemaObject obj in Items)
            {
                if (obj is XmlSchemaElement ||
                    obj is XmlSchemaGroupRef ||
                    obj is XmlSchemaChoice ||
                    obj is XmlSchemaSequence ||
                    obj is XmlSchemaAny)
                {
                    errorCount += obj.Compile(h, schema);
                }
                else
                {
                    error(h, "Invalid schema object was specified in the particles of the choice model group.");
                }
            }
            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
Beispiel #3
0
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

            if (nsmgr == null)
            {
                nsmgr = new XmlNamespaceManager(new NameTable());
                if (Namespaces != null)
                {
                    foreach (XmlQualifiedName qname in Namespaces.ToArray())
                    {
                        nsmgr.AddNamespace(qname.Name, qname.Namespace);
                    }
                }
            }

            currentPath = new XsdIdentityPath();
            ParseExpression(xpath, h, schema);

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);
            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
Beispiel #4
0
        /// <remarks>
        /// 1. One of itemType or a <simpleType> must be present, but not both.
        /// 2. id must be of type ID
        /// </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 (ItemType != null && !ItemTypeName.IsEmpty)
            {
                error(h, "both itemType and simpletype can't be present");
            }
            if (ItemType == null && ItemTypeName.IsEmpty)
            {
                error(h, "one of itemType or simpletype must be present");
            }
            if (ItemType != null)
            {
                errorCount += ItemType.Compile(h, schema);
            }
            if (!XmlSchemaUtil.CheckQName(ItemTypeName))
            {
                error(h, "BaseTypeName must be a XmlQualifiedName");
            }

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

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
Beispiel #5
0
        ///<remarks>
        /// 1. Content must be present and one of restriction or extention
        ///</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 (Content == null)
            {
                error(h, "Content must be present in a simpleContent");
            }
            else
            {
                if (Content is XmlSchemaSimpleContentRestriction)
                {
                    XmlSchemaSimpleContentRestriction xscr = (XmlSchemaSimpleContentRestriction)Content;
                    errorCount += xscr.Compile(h, schema);
                }
                else if (Content is XmlSchemaSimpleContentExtension)
                {
                    XmlSchemaSimpleContentExtension xsce = (XmlSchemaSimpleContentExtension)Content;
                    errorCount += xsce.Compile(h, schema);
                }
                else
                {
                    error(h, "simpleContent can't have any value other than restriction or extention");
                }
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);
            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
        /// <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);
        }
Beispiel #7
0
        /// <remarks>
        /// 1. Circular union type definition is disallowed. (WTH is this?)
        /// 2. id must be a valid ID
        /// </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;

            int count = BaseTypes.Count;

            foreach (XmlSchemaObject obj in baseTypes)
            {
                if (obj != null && obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    errorCount += stype.Compile(h, schema);
                }
                else
                {
                    error(h, "baseTypes can't have objects other than a simpletype");
                }
            }

            if (memberTypes != null)
            {
                for (int i = 0; i < memberTypes.Length; i++)
                {
                    if (memberTypes[i] == null || !XmlSchemaUtil.CheckQName(MemberTypes[i]))
                    {
                        error(h, "Invalid membertype");
                        memberTypes[i] = XmlQualifiedName.Empty;
                    }
                    else
                    {
                        count += MemberTypes.Length;
                    }
                }
            }

            if (count == 0)
            {
                error(h, "Atleast one simpletype or membertype must be present");
            }

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



            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);
        }
Beispiel #9
0
        /// <remarks>
        /// 1. MaxOccurs must be one. (default is also one)
        /// 2. MinOccurs must be zero or one.
        /// </remarks>
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

            this.schema = schema;

            if (MaxOccurs != Decimal.One)
            {
                error(h, "maxOccurs must be 1");
            }
            if (MinOccurs != Decimal.One && MinOccurs != Decimal.Zero)
            {
                error(h, "minOccurs must be 0 or 1");
            }

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

            foreach (XmlSchemaObject obj in Items)
            {
                XmlSchemaElement elem = obj as XmlSchemaElement;
                if (elem != null)
                {
                    if (elem.ValidatedMaxOccurs != Decimal.One && elem.ValidatedMaxOccurs != Decimal.Zero)
                    {
                        elem.error(h, "The {max occurs} of all the elements of 'all' must be 0 or 1. ");
                    }
                    errorCount += elem.Compile(h, schema);
                }
                else
                {
                    error(h, "XmlSchemaAll can only contain Items of type Element");
                }
            }

            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);
        }
Beispiel #11
0
        /// <remarks>
        /// 1. ref 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);
            }

            errorCount = 0;
            if (RefName == null || RefName.IsEmpty)
            {
                error(h, "ref must be present");
            }
            else if (!XmlSchemaUtil.CheckQName(RefName))
            {
                error(h, "ref must be a valid qname");
            }

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

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
        ///<remarks>
        /// 1. Base must be present and a QName
        ///</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 (this.isRedefinedComponent)
            {
                if (Annotation != null)
                {
                    Annotation.isRedefinedComponent = true;
                }
                if (AnyAttribute != null)
                {
                    AnyAttribute.isRedefinedComponent = true;
                }
                foreach (XmlSchemaObject obj in Attributes)
                {
                    obj.isRedefinedComponent = true;
                }
            }

            if (BaseTypeName == null || BaseTypeName.IsEmpty)
            {
                error(h, "base must be present, as a QName");
            }
            else if (!XmlSchemaUtil.CheckQName(BaseTypeName))
            {
                error(h, "BaseTypeName must be a QName");
            }

            if (this.AnyAttribute != null)
            {
                errorCount += 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 atgrp = (XmlSchemaAttributeGroupRef)obj;
                    errorCount += atgrp.Compile(h, schema);
                }
                else
                {
                    error(h, obj.GetType() + " is not valid in this place::SimpleConentExtension");
                }
            }

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

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
Beispiel #13
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 #14
0
        /// <remarks>
        /// </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 (this.isRedefinedComponent)
            {
                if (Annotation != null)
                {
                    Annotation.isRedefinedComponent = true;
                }
                if (AnyAttribute != null)
                {
                    AnyAttribute.isRedefinedComponent = true;
                }
                foreach (XmlSchemaObject obj in Attributes)
                {
                    obj.isRedefinedComponent = true;
                }
                if (Particle != null)
                {
                    Particle.isRedefinedComponent = true;
                }
            }

            if (BaseTypeName == null || BaseTypeName.IsEmpty)
            {
                error(h, "base must be present, as a QName");
            }
            else if (!XmlSchemaUtil.CheckQName(BaseTypeName))
            {
                error(h, "BaseTypeName is not a valid XmlQualifiedName");
            }

            if (this.AnyAttribute != null)
            {
                errorCount += 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 atgrp = (XmlSchemaAttributeGroupRef)obj;
                    errorCount += atgrp.Compile(h, schema);
                }
                else
                {
                    error(h, obj.GetType() + " is not valid in this place::ComplexConetnetExtension");
                }
            }

            if (Particle != null)
            {
                if (Particle is XmlSchemaGroupRef)
                {
                    errorCount += ((XmlSchemaGroupRef)Particle).Compile(h, schema);
                }
                else if (Particle is XmlSchemaAll)
                {
                    errorCount += ((XmlSchemaAll)Particle).Compile(h, schema);
                }
                else if (Particle is XmlSchemaChoice)
                {
                    errorCount += ((XmlSchemaChoice)Particle).Compile(h, schema);
                }
                else if (Particle is XmlSchemaSequence)
                {
                    errorCount += ((XmlSchemaSequence)Particle).Compile(h, schema);
                }
                else
                {
                    error(h, "Particle of a restriction is limited only to group, sequence, choice and all.");
                }
            }

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

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
Beispiel #15
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);
        }
        /// <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 #17
0
        void DoCompile(ValidationEventHandler handler, List <CompiledSchemaMemo> handledUris, XmlSchemaSet col, XmlResolver resolver)
        {
            SetParent();
            CompilationId = col.CompilationId;
            schemas       = col;
            if (!schemas.Contains(this))              // e.g. xs:import
            {
                schemas.Add(this);
            }

            attributeGroups.Clear();
            attributes.Clear();
            elements.Clear();
            groups.Clear();
            notations.Clear();
            schemaTypes.Clear();
            named_identities.Clear();
            ids.Clear();
            compilationItems.Clear();

            //1. Union and List are not allowed in block default
            if (BlockDefault != XmlSchemaDerivationMethod.All)
            {
                if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0)
                {
                    error(handler, "list is not allowed in blockDefault attribute");
                }
                if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0)
                {
                    error(handler, "union is not allowed in blockDefault attribute");
                }
            }

            //2. Substitution is not allowed in finaldefault.
            if (FinalDefault != XmlSchemaDerivationMethod.All)
            {
                if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0)
                {
                    error(handler, "substitution is not allowed in finalDefault attribute");
                }
            }

            //3. id must be of type ID
            XmlSchemaUtil.CompileID(Id, this, IDCollection, handler);

            //4. targetNamespace should be of type anyURI or absent
            if (TargetNamespace != null)
            {
                if (TargetNamespace.Length == 0)
                {
                    error(handler, "The targetNamespace attribute cannot have have empty string as its value.");
                }

                if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
                {
                    error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema");
                }
            }

            //5. version should be of type normalizedString
            if (!XmlSchemaUtil.CheckNormalizedString(Version))
            {
                error(handler, Version + "is not a valid value for version attribute of schema");
            }

            // Compile the content of this schema

            for (int i = 0; i < Items.Count; i++)
            {
                compilationItems.Add(Items [i]);
            }

            // First, we run into inclusion schemas to collect
            // compilation target items into compiledItems.
            for (int i = 0; i < Includes.Count; i++)
            {
                ProcessExternal(handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col);
            }

            // Compilation phase.
            // At least each Compile() must give unique (qualified) name for each component.
            // It also checks self-resolvable properties correctness.
            // Post compilation schema information contribution is not done here.
            // It should be done by Validate().
            for (int i = 0; i < compilationItems.Count; i++)
            {
                XmlSchemaObject obj = compilationItems [i];
                if (obj is XmlSchemaAnnotation)
                {
                    int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
                    errorCount += numerr;
                }
                else if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    int numerr = attr.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler);
                    }
                }
                else if (obj is XmlSchemaAttributeGroup)
                {
                    XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj;
                    int numerr = attrgrp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            AttributeGroups,
                            attrgrp,
                            attrgrp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj;
                    int numerr = ctype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            schemaTypes,
                            ctype,
                            ctype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    stype.islocal = false;                     //This simple type is toplevel
                    int numerr = stype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            SchemaTypes,
                            stype,
                            stype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaElement)
                {
                    XmlSchemaElement elem = (XmlSchemaElement)obj;
                    elem.parentIsSchema = true;
                    int numerr = elem.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Elements,
                            elem,
                            elem.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaGroup)
                {
                    XmlSchemaGroup grp    = (XmlSchemaGroup)obj;
                    int            numerr = grp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Groups,
                            grp,
                            grp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaNotation)
                {
                    XmlSchemaNotation ntn = (XmlSchemaNotation)obj;
                    int numerr            = ntn.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Notations,
                            ntn,
                            ntn.QualifiedName,
                            handler);
                    }
                }
                else
                {
                    ValidationHandler.RaiseValidationEvent(
                        handler,
                        null,
                        String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name),
                        null,
                        this,
                        null,
                        XmlSeverityType.Error);
                }
            }
        }