Пример #1
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);
        }
Пример #2
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;

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);
            wildcard.TargetNamespace = AncestorSchema.TargetNamespace;
            if (wildcard.TargetNamespace == null)
            {
                wildcard.TargetNamespace = "";
            }
            CompileOccurence(h, schema);

            wildcard.Compile(Namespace, h, schema);

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

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
Пример #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);
            }

            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);
        }
Пример #4
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);
        }
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     this.errorCount = 0;
     this.wildcard.TargetNamespace = base.AncestorSchema.TargetNamespace;
     if (this.wildcard.TargetNamespace == null)
     {
         this.wildcard.TargetNamespace = string.Empty;
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.wildcard.Compile(this.Namespace, h, schema);
     if (this.processing == XmlSchemaContentProcessing.None)
     {
         this.wildcard.ResolvedProcessing = XmlSchemaContentProcessing.Strict;
     }
     else
     {
         this.wildcard.ResolvedProcessing = this.processing;
     }
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     base.CompileOccurence(h, schema);
     if (this.Items.Count == 0)
     {
         base.warn(h, "Empty choice is unsatisfiable if minOccurs not equals to 0");
     }
     foreach (XmlSchemaObject xmlSchemaObject in this.Items)
     {
         if (xmlSchemaObject is XmlSchemaElement || xmlSchemaObject is XmlSchemaGroupRef || xmlSchemaObject is XmlSchemaChoice || xmlSchemaObject is XmlSchemaSequence || xmlSchemaObject is XmlSchemaAny)
         {
             this.errorCount += xmlSchemaObject.Compile(h, schema);
         }
         else
         {
             base.error(h, "Invalid schema object was specified in the particles of the choice model group.");
         }
     }
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
Пример #7
0
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     if (this.Content == null)
     {
         base.error(h, "Content must be present in a simpleContent");
     }
     else if (this.Content is XmlSchemaSimpleContentRestriction)
     {
         XmlSchemaSimpleContentRestriction xmlSchemaSimpleContentRestriction = (XmlSchemaSimpleContentRestriction)this.Content;
         this.errorCount += xmlSchemaSimpleContentRestriction.Compile(h, schema);
     }
     else if (this.Content is XmlSchemaSimpleContentExtension)
     {
         XmlSchemaSimpleContentExtension xmlSchemaSimpleContentExtension = (XmlSchemaSimpleContentExtension)this.Content;
         this.errorCount += xmlSchemaSimpleContentExtension.Compile(h, schema);
     }
     else
     {
         base.error(h, "simpleContent can't have any value other than restriction or extention");
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
Пример #8
0
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     this.errorCount = 0;
     if (this.ItemType != null && !this.ItemTypeName.IsEmpty)
     {
         base.error(h, "both itemType and simpletype can't be present");
     }
     if (this.ItemType == null && this.ItemTypeName.IsEmpty)
     {
         base.error(h, "one of itemType or simpletype must be present");
     }
     if (this.ItemType != null)
     {
         this.errorCount += this.ItemType.Compile(h, schema);
     }
     if (!XmlSchemaUtil.CheckQName(this.ItemTypeName))
     {
         base.error(h, "BaseTypeName must be a XmlQualifiedName");
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
Пример #9
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);
        }
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     if (this.Name == null)
     {
         base.error(h, "Required attribute name must be present");
     }
     else if (!XmlSchemaUtil.CheckNCName(this.name))
     {
         base.error(h, "attribute name must be NCName");
     }
     else
     {
         this.qualifiedName = new XmlQualifiedName(this.Name, base.AncestorSchema.TargetNamespace);
     }
     if (this.Public == null)
     {
         base.error(h, "public must be present");
     }
     else if (!XmlSchemaUtil.CheckAnyUri(this.Public))
     {
         base.error(h, "public must be anyURI");
     }
     if (this.system != null && !XmlSchemaUtil.CheckAnyUri(this.system))
     {
         base.error(h, "system must be present and of Type anyURI");
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     return(this.errorCount);
 }
Пример #11
0
        /// <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);
        }
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     if (this.isRedefinedComponent)
     {
         if (base.Annotation != null)
         {
             base.Annotation.isRedefinedComponent = true;
         }
         if (this.AnyAttribute != null)
         {
             this.AnyAttribute.isRedefinedComponent = true;
         }
         foreach (XmlSchemaObject xmlSchemaObject in this.Attributes)
         {
             xmlSchemaObject.isRedefinedComponent = true;
         }
     }
     if (this.BaseTypeName == null || this.BaseTypeName.IsEmpty)
     {
         base.error(h, "base must be present, as a QName");
     }
     else if (!XmlSchemaUtil.CheckQName(this.BaseTypeName))
     {
         base.error(h, "BaseTypeName must be a QName");
     }
     if (this.BaseType != null)
     {
         this.errorCount += this.BaseType.Compile(h, schema);
     }
     if (this.AnyAttribute != null)
     {
         this.errorCount += this.AnyAttribute.Compile(h, schema);
     }
     foreach (XmlSchemaObject xmlSchemaObject2 in this.Attributes)
     {
         if (xmlSchemaObject2 is XmlSchemaAttribute)
         {
             XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)xmlSchemaObject2;
             this.errorCount += xmlSchemaAttribute.Compile(h, schema);
         }
         else if (xmlSchemaObject2 is XmlSchemaAttributeGroupRef)
         {
             XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = (XmlSchemaAttributeGroupRef)xmlSchemaObject2;
             this.errorCount += xmlSchemaAttributeGroupRef.Compile(h, schema);
         }
         else
         {
             base.error(h, xmlSchemaObject2.GetType() + " is not valid in this place::SimpleContentRestriction");
         }
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
 private void CompileCommon(ValidationEventHandler h, XmlSchema schema, bool refIsNotPresent)
 {
     if (refIsNotPresent)
     {
         if (this.Name == null)
         {
             base.error(h, "Required attribute name must be present");
         }
         else if (!XmlSchemaUtil.CheckNCName(this.Name))
         {
             base.error(h, "attribute name must be NCName");
         }
         else if (this.Name == "xmlns")
         {
             base.error(h, "attribute name must not be xmlns");
         }
         else
         {
             this.qualifiedName = new XmlQualifiedName(this.Name, this.targetNamespace);
         }
         if (this.SchemaType != null)
         {
             if (this.SchemaTypeName != null && !this.SchemaTypeName.IsEmpty)
             {
                 base.error(h, "attribute can't have both a type and <simpleType> content");
             }
             this.errorCount += this.SchemaType.Compile(h, schema);
         }
         if (this.SchemaTypeName != null && !XmlSchemaUtil.CheckQName(this.SchemaTypeName))
         {
             base.error(h, this.SchemaTypeName + " is not a valid QName");
         }
     }
     else
     {
         if (this.RefName == null || this.RefName.IsEmpty)
         {
             throw new InvalidOperationException("Error: Should Never Happen. refname must be present");
         }
         this.qualifiedName = this.RefName;
     }
     if (base.AncestorSchema.TargetNamespace == "http://www.w3.org/2001/XMLSchema-instance" && this.Name != "nil" && this.Name != "type" && this.Name != "schemaLocation" && this.Name != "noNamespaceSchemaLocation")
     {
         base.error(h, "targetNamespace can't be http://www.w3.org/2001/XMLSchema-instance");
     }
     if (this.DefaultValue != null && this.FixedValue != null)
     {
         base.error(h, "default and fixed must not both be present in an Attribute");
     }
     if (this.DefaultValue != null && this.Use != XmlSchemaUse.None && this.Use != XmlSchemaUse.Optional)
     {
         base.error(h, "if default is present, use must be optional");
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
 }
Пример #14
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);
        }
Пример #15
0
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(this.errorCount);
     }
     this.errorCount = 0;
     if (this.redefinedObject != null)
     {
         this.errorCount += this.redefined.Compile(h, schema);
         if (this.errorCount == 0)
         {
             this.redefined = (XmlSchemaAttributeGroup)this.redefinedObject;
         }
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     if (this.Name == null || this.Name == string.Empty)
     {
         base.error(h, "Name is required in top level simpletype");
     }
     else if (!XmlSchemaUtil.CheckNCName(this.Name))
     {
         base.error(h, "name attribute of a simpleType must be NCName");
     }
     else
     {
         this.qualifiedName = new XmlQualifiedName(this.Name, base.AncestorSchema.TargetNamespace);
     }
     if (this.AnyAttribute != null)
     {
         this.errorCount += this.AnyAttribute.Compile(h, schema);
     }
     foreach (XmlSchemaObject xmlSchemaObject in this.Attributes)
     {
         if (xmlSchemaObject is XmlSchemaAttribute)
         {
             XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)xmlSchemaObject;
             this.errorCount += xmlSchemaAttribute.Compile(h, schema);
         }
         else if (xmlSchemaObject is XmlSchemaAttributeGroupRef)
         {
             XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = (XmlSchemaAttributeGroupRef)xmlSchemaObject;
             this.errorCount += xmlSchemaAttributeGroupRef.Compile(h, schema);
         }
         else
         {
             base.error(h, "invalid type of object in Attributes property");
         }
     }
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            if (this.CompilationId == schema.CompilationId)
            {
                return(0);
            }
            this.errorCount = 0;
            int num = this.BaseTypes.Count;

            foreach (XmlSchemaObject xmlSchemaObject in this.baseTypes)
            {
                if (xmlSchemaObject != null && xmlSchemaObject is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType)xmlSchemaObject;
                    this.errorCount += xmlSchemaSimpleType.Compile(h, schema);
                }
                else
                {
                    base.error(h, "baseTypes can't have objects other than a simpletype");
                }
            }
            if (this.memberTypes != null)
            {
                for (int i = 0; i < this.memberTypes.Length; i++)
                {
                    if (this.memberTypes[i] == null || !XmlSchemaUtil.CheckQName(this.MemberTypes[i]))
                    {
                        base.error(h, "Invalid membertype");
                        this.memberTypes[i] = XmlQualifiedName.Empty;
                    }
                    else
                    {
                        num += this.MemberTypes.Length;
                    }
                }
            }
            if (num == 0)
            {
                base.error(h, "Atleast one simpletype or membertype must be present");
            }
            XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
            this.CompilationId = schema.CompilationId;
            return(this.errorCount);
        }
Пример #17
0
        // 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);
        }
Пример #18
0
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     this.errorCount = 0;
     if (this.RefName == null || this.RefName.IsEmpty)
     {
         base.error(h, "ref must be present");
     }
     else if (!XmlSchemaUtil.CheckQName(this.RefName))
     {
         base.error(h, "ref must be a valid qname");
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
Пример #19
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);
        }
Пример #20
0
        // 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);
        }
Пример #21
0
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     if (this.Name == null)
     {
         base.error(h, "Required attribute name must be present");
     }
     else if (!XmlSchemaUtil.CheckNCName(this.name))
     {
         base.error(h, "attribute name must be NCName");
     }
     else
     {
         this.qualifiedName = new XmlQualifiedName(this.Name, base.AncestorSchema.TargetNamespace);
     }
     if (this.Particle == null)
     {
         base.error(h, "Particle is required");
     }
     else
     {
         if (this.Particle.MaxOccursString != null)
         {
             this.Particle.error(h, "MaxOccurs must not be present when the Particle is a child of Group");
         }
         if (this.Particle.MinOccursString != null)
         {
             this.Particle.error(h, "MinOccurs must not be present when the Particle is a child of Group");
         }
         this.Particle.Compile(h, schema);
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
Пример #22
0
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     if (this.nsmgr == null)
     {
         this.nsmgr = new XmlNamespaceManager(new NameTable());
         if (base.Namespaces != null)
         {
             foreach (XmlQualifiedName xmlQualifiedName in base.Namespaces.ToArray())
             {
                 this.nsmgr.AddNamespace(xmlQualifiedName.Name, xmlQualifiedName.Namespace);
             }
         }
     }
     this.currentPath = new XsdIdentityPath();
     this.ParseExpression(this.xpath, h, schema);
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
Пример #23
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);
        }
Пример #24
0
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     this.schema = schema;
     if (base.MaxOccurs != 1m)
     {
         base.error(h, "maxOccurs must be 1");
     }
     if (base.MinOccurs != 1m && base.MinOccurs != 0m)
     {
         base.error(h, "minOccurs must be 0 or 1");
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     base.CompileOccurence(h, schema);
     foreach (XmlSchemaObject xmlSchemaObject in this.Items)
     {
         XmlSchemaElement xmlSchemaElement = xmlSchemaObject as XmlSchemaElement;
         if (xmlSchemaElement != null)
         {
             if (xmlSchemaElement.ValidatedMaxOccurs != 1m && xmlSchemaElement.ValidatedMaxOccurs != 0m)
             {
                 xmlSchemaElement.error(h, "The {max occurs} of all the elements of 'all' must be 0 or 1. ");
             }
             this.errorCount += xmlSchemaElement.Compile(h, schema);
         }
         else
         {
             base.error(h, "XmlSchemaAll can only contain Items of type Element");
         }
     }
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     if (this.Name == null)
     {
         base.error(h, "Required attribute name must be present");
     }
     else if (!XmlSchemaUtil.CheckNCName(this.name))
     {
         base.error(h, "attribute name must be NCName");
     }
     else
     {
         this.qName = new XmlQualifiedName(this.Name, base.AncestorSchema.TargetNamespace);
         if (schema.NamedIdentities.Contains(this.qName))
         {
             XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint = schema.NamedIdentities[this.qName] as XmlSchemaIdentityConstraint;
             base.error(h, string.Format("There is already same named identity constraint in this namespace. Existing item is at {0}({1},{2})", xmlSchemaIdentityConstraint.SourceUri, xmlSchemaIdentityConstraint.LineNumber, xmlSchemaIdentityConstraint.LinePosition));
         }
         else
         {
             schema.NamedIdentities.Add(this.qName, this);
         }
     }
     if (this.Selector == null)
     {
         base.error(h, "selector must be present");
     }
     else
     {
         this.Selector.isSelector = true;
         this.errorCount         += this.Selector.Compile(h, schema);
         if (this.selector.errorCount == 0)
         {
             this.compiledSelector = new XsdIdentitySelector(this.Selector);
         }
     }
     if (this.errorCount > 0)
     {
         return(this.errorCount);
     }
     if (this.Fields.Count == 0)
     {
         base.error(h, "atleast one field value must be present");
     }
     else
     {
         for (int i = 0; i < this.Fields.Count; i++)
         {
             XmlSchemaXPath xmlSchemaXPath = this.Fields[i] as XmlSchemaXPath;
             if (xmlSchemaXPath != null)
             {
                 this.errorCount += xmlSchemaXPath.Compile(h, schema);
                 if (xmlSchemaXPath.errorCount == 0)
                 {
                     this.compiledSelector.AddField(new XsdIdentityField(xmlSchemaXPath, i));
                 }
             }
             else
             {
                 base.error(h, "Object of type " + this.Fields[i].GetType() + " is invalid in the Fields Collection");
             }
         }
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
        /// <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);
        }
Пример #27
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);
        }
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     if (this.isRedefinedComponent)
     {
         if (base.Annotation != null)
         {
             base.Annotation.isRedefinedComponent = true;
         }
         if (this.AnyAttribute != null)
         {
             this.AnyAttribute.isRedefinedComponent = true;
         }
         foreach (XmlSchemaObject xmlSchemaObject in this.Attributes)
         {
             xmlSchemaObject.isRedefinedComponent = true;
         }
         if (this.Particle != null)
         {
             this.Particle.isRedefinedComponent = true;
         }
     }
     if (this.BaseTypeName == null || this.BaseTypeName.IsEmpty)
     {
         base.error(h, "base must be present, as a QName");
     }
     else if (!XmlSchemaUtil.CheckQName(this.BaseTypeName))
     {
         base.error(h, "BaseTypeName is not a valid XmlQualifiedName");
     }
     if (this.AnyAttribute != null)
     {
         this.errorCount += this.AnyAttribute.Compile(h, schema);
     }
     foreach (XmlSchemaObject xmlSchemaObject2 in this.Attributes)
     {
         if (xmlSchemaObject2 is XmlSchemaAttribute)
         {
             XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)xmlSchemaObject2;
             this.errorCount += xmlSchemaAttribute.Compile(h, schema);
         }
         else if (xmlSchemaObject2 is XmlSchemaAttributeGroupRef)
         {
             XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = (XmlSchemaAttributeGroupRef)xmlSchemaObject2;
             this.errorCount += xmlSchemaAttributeGroupRef.Compile(h, schema);
         }
         else
         {
             base.error(h, xmlSchemaObject2.GetType() + " is not valid in this place::ComplexConetnetExtension");
         }
     }
     if (this.Particle != null)
     {
         if (this.Particle is XmlSchemaGroupRef)
         {
             this.errorCount += ((XmlSchemaGroupRef)this.Particle).Compile(h, schema);
         }
         else if (this.Particle is XmlSchemaAll)
         {
             this.errorCount += ((XmlSchemaAll)this.Particle).Compile(h, schema);
         }
         else if (this.Particle is XmlSchemaChoice)
         {
             this.errorCount += ((XmlSchemaChoice)this.Particle).Compile(h, schema);
         }
         else if (this.Particle is XmlSchemaSequence)
         {
             this.errorCount += ((XmlSchemaSequence)this.Particle).Compile(h, schema);
         }
         else
         {
             base.error(h, "Particle of a restriction is limited only to group, sequence, choice and all.");
         }
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.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);
        }
Пример #30
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);
                }
            }
        }