Beispiel #1
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 #2
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);
        }
        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 #4
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);
        }
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
        // Is some value is read, return it.
        // If no values return empty.
        // If exception, return none
        public static XmlSchemaDerivationMethod ReadDerivationAttribute(XmlReader reader, out Exception innerExcpetion, string name, XmlSchemaDerivationMethod allowed)
        {
            innerExcpetion = null;
            try
            {
                string list = reader.Value;
                string warn = "";
                XmlSchemaDerivationMethod val = 0;

                if (list.IndexOf("#all") != -1 && list.Trim() != "#all")
                {
                    innerExcpetion = new Exception(list + " is not a valid value for " + name + ". #all if present must be the only value");
                    return(XmlSchemaDerivationMethod.All);
                }
                foreach (string xsdm in XmlSchemaUtil.SplitList(list))
                {
                    switch (xsdm)
                    {
                    case "":
                        val = AddFlag(val, XmlSchemaDerivationMethod.Empty, allowed); break;

                    case "#all":
                        val = AddFlag(val, XmlSchemaDerivationMethod.All, allowed); break;

                    case "substitution":
                        val = AddFlag(val, XmlSchemaDerivationMethod.Substitution, allowed); break;

                    case "extension":
                        val = AddFlag(val, XmlSchemaDerivationMethod.Extension, allowed); break;

                    case "restriction":
                        val = AddFlag(val, XmlSchemaDerivationMethod.Restriction, allowed); break;

                    case "list":
                        val = AddFlag(val, XmlSchemaDerivationMethod.List, allowed); break;

                    case "union":
                        val = AddFlag(val, XmlSchemaDerivationMethod.Union, allowed); break;

                    default:
                        warn += xsdm + " "; break;
                    }
                }
                if (warn != "")
                {
                    innerExcpetion = new Exception(warn + "is/are not valid values for " + name);
                }
                return(val);
            }
            catch (Exception ex)
            {
                innerExcpetion = ex;
                return(XmlSchemaDerivationMethod.None);
            }
        }
Beispiel #8
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);
        }
Beispiel #9
0
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            if (IsValidated(schema.ValidationId))
            {
                return(errorCount);
            }

            // ListItemType
            XmlSchemaSimpleType type = itemType;

            if (type == null)
            {
                type = schema.FindSchemaType(itemTypeName) as XmlSchemaSimpleType;
            }
            if (type != null)
            {
                errorCount           += type.Validate(h, schema);
                validatedListItemType = type;
            }
            else if (itemTypeName == XmlSchemaComplexType.AnyTypeName)
            {
                validatedListItemType = XmlSchemaSimpleType.AnySimpleType;
            }
            else if (XmlSchemaUtil.IsBuiltInDatatypeName(itemTypeName))
            {
                validatedListItemType = XmlSchemaDatatype.FromName(itemTypeName);
                if (validatedListItemType == null)
                {
                    error(h, "Invalid schema type name was specified: " + itemTypeName);
                }
            }
            // otherwise, it might be missing sub components.
            else if (!schema.IsNamespaceAbsent(itemTypeName.Namespace))
            {
                error(h, "Referenced base list item schema type " + itemTypeName + " was not found.");
            }

#if NET_2_0
            XmlSchemaSimpleType st = validatedListItemType as XmlSchemaSimpleType;
            if (st == null && validatedListItemType != null)
            {
                st = XmlSchemaType.GetBuiltInSimpleType(((XmlSchemaDatatype)validatedListItemType).TypeCode);
            }
            validatedListItemSchemaType = st;
#endif

            ValidationId = schema.ValidationId;
            return(errorCount);
        }
Beispiel #10
0
        /// <remarks>
        /// 1. name must be present
        /// 2. selector and field must be present
        /// 3. refer must be present
        /// </remarks>
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            base.Compile(h, schema);

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

            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 #12
0
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            if (IsValidated(schema.ValidationId))
            {
                return(errorCount);
            }

            if (baseType != null)
            {
                baseType.Validate(h, schema);
                actualBaseSchemaType = baseType;
            }
            else if (baseTypeName != XmlQualifiedName.Empty)
            {
                XmlSchemaType st = schema.FindSchemaType(baseTypeName);
                if (st != null)
                {
                    st.Validate(h, schema);
                    actualBaseSchemaType = st;
                }
                else if (baseTypeName == XmlSchemaComplexType.AnyTypeName)
                {
                    actualBaseSchemaType = XmlSchemaComplexType.AnyType;
                }
                else if (XmlSchemaUtil.IsBuiltInDatatypeName(baseTypeName))
                {
                    actualBaseSchemaType = XmlSchemaDatatype.FromName(baseTypeName);
                    if (actualBaseSchemaType == null)
                    {
                        error(h, "Invalid schema datatype name is specified.");
                    }
                }
                // otherwise, it might be missing sub components.
                else if (!schema.IsNamespaceAbsent(baseTypeName.Namespace))
                {
                    error(h, "Referenced base schema type " + baseTypeName + " was not found in the corresponding schema.");
                }
            }

            ValidationId = schema.ValidationId;
            return(errorCount);
        }
Beispiel #13
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);
        }
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            if (IsValidated(schema.CompilationId))
            {
                return(errorCount);
            }

            if (redefined == null && redefinedObject != null)
            {
                redefinedObject.Compile(h, schema);
                redefined = (XmlSchemaAttributeGroup)redefinedObject;
                redefined.Validate(h, schema);
            }

            XmlSchemaObjectCollection actualAttributes = null;

            /*
             * if (this.redefined != null) {
             *      actualAttributes = new XmlSchemaObjectCollection ();
             *      foreach (XmlSchemaObject obj in Attributes) {
             *              XmlSchemaAttributeGroupRef grp = obj as XmlSchemaAttributeGroupRef;
             *              if (grp != null && grp.QualifiedName == this.QualifiedName)
             *                      actualAttributes.Add (redefined);
             *              else
             *                      actualAttributes.Add (obj);
             *      }
             * }
             * else
             */
            actualAttributes = Attributes;

            attributeUses = new XmlSchemaObjectTable();
            errorCount   += XmlSchemaUtil.ValidateAttributesResolved(attributeUses,
                                                                     h, schema, actualAttributes, AnyAttribute,
                                                                     ref anyAttributeUse, redefined, false);
            ValidationId = schema.ValidationId;
            return(errorCount);
        }
Beispiel #16
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);
        }
Beispiel #17
0
        //<enumeration
        //  id = ID
        //  value = anySimpleType
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?)
        //</enumeration>
        internal static XmlSchemaEnumerationFacet Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaEnumerationFacet.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            enumeration.LineNumber   = reader.LineNumber;
            enumeration.LinePosition = reader.LinePosition;
            enumeration.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    enumeration.Id = reader.Value;
                }
                else if (reader.Name == "value")
                {
                    enumeration.Value = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for " + xmlname, null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, enumeration);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(enumeration);
            }

            //  Content: (annotation?)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaEnumerationFacet.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                          //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        enumeration.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(enumeration);
        }
        //<choice
        //  id = ID
        //  maxOccurs =  (nonNegativeInteger | unbounded)  : 1
        //  minOccurs = nonNegativeInteger : 1
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (element | group | choice | sequence | any)*)
        //</choice>
        internal static XmlSchemaChoice Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaChoice choice = new XmlSchemaChoice();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaChoice.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            choice.LineNumber   = reader.LineNumber;
            choice.LinePosition = reader.LinePosition;
            choice.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    choice.Id = reader.Value;
                }
                else if (reader.Name == "maxOccurs")
                {
                    try
                    {
                        choice.MaxOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for maxOccurs", e);
                    }
                }
                else if (reader.Name == "minOccurs")
                {
                    try
                    {
                        choice.MinOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for minOccurs", e);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for choice", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, choice);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(choice);
            }

            //  Content: (annotation?, (element | group | choice | sequence | any)*)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaChoice.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                     //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        choice.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "element")
                    {
                        level = 2;
                        XmlSchemaElement element = XmlSchemaElement.Read(reader, h);
                        if (element != null)
                        {
                            choice.items.Add(element);
                        }
                        continue;
                    }
                    if (reader.LocalName == "group")
                    {
                        level = 2;
                        XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h);
                        if (group != null)
                        {
                            choice.items.Add(group);
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 2;
                        XmlSchemaChoice ch = XmlSchemaChoice.Read(reader, h);
                        if (ch != null)
                        {
                            choice.items.Add(ch);
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 2;
                        XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h);
                        if (sequence != null)
                        {
                            choice.items.Add(sequence);
                        }
                        continue;
                    }
                    if (reader.LocalName == "any")
                    {
                        level = 2;
                        XmlSchemaAny any = XmlSchemaAny.Read(reader, h);
                        if (any != null)
                        {
                            choice.items.Add(any);
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
            return(choice);
        }
        ///<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 #20
0
        /*
         * internal new void error(ValidationEventHandler handle, string message)
         * {
         *      errorCount++;
         *      ValidationHandler.RaiseValidationError(handle, this, message);
         * }
         */
        //<unique
        //  id = ID
        //  name = NCName
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (selector, field+))
        //</unique>
        internal static XmlSchemaUnique Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaUnique unique = new XmlSchemaUnique();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaUnique.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            unique.LineNumber   = reader.LineNumber;
            unique.LinePosition = reader.LinePosition;
            unique.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    unique.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    unique.Name = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for unique", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, unique);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(unique);
            }

            //  Content: annotation?, selector, field+
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaUnion.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                     //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        unique.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "selector")
                {
                    level = 3;
                    XmlSchemaXPath selector = XmlSchemaXPath.Read(reader, h, "selector");
                    if (selector != null)
                    {
                        unique.Selector = selector;
                    }
                    continue;
                }
                if (level <= 3 && reader.LocalName == "field")
                {
                    level = 3;
                    if (unique.Selector == null)
                    {
                        error(h, "selector must be defined before field declarations", null);
                    }
                    XmlSchemaXPath field = XmlSchemaXPath.Read(reader, h, "field");
                    if (field != null)
                    {
                        unique.Fields.Add(field);
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(unique);
        }
Beispiel #21
0
        private static void ReadAttributes(XmlSchema schema, XmlSchemaReader reader, ValidationEventHandler h)
        {
            Exception ex;

            reader.MoveToElement();
            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case "attributeFormDefault":
                    schema.attributeFormDefault = XmlSchemaUtil.ReadFormAttribute(reader, out ex);
                    if (ex != null)
                    {
                        error(h, reader.Value + " is not a valid value for attributeFormDefault.", ex);
                    }
                    break;

                case "blockDefault":
                    schema.blockDefault = XmlSchemaUtil.ReadDerivationAttribute(reader, out ex, "blockDefault",
                                                                                XmlSchemaUtil.ElementBlockAllowed);
                    if (ex != null)
                    {
                        error(h, ex.Message, ex);
                    }
                    break;

                case "elementFormDefault":
                    schema.elementFormDefault = XmlSchemaUtil.ReadFormAttribute(reader, out ex);
                    if (ex != null)
                    {
                        error(h, reader.Value + " is not a valid value for elementFormDefault.", ex);
                    }
                    break;

                case "finalDefault":
                    schema.finalDefault = XmlSchemaUtil.ReadDerivationAttribute(reader, out ex, "finalDefault",
                                                                                XmlSchemaUtil.FinalAllowed);
                    if (ex != null)
                    {
                        error(h, ex.Message, ex);
                    }
                    break;

                case "id":
                    schema.id = reader.Value;
                    break;

                case "targetNamespace":
                    schema.targetNamespace = reader.Value;
                    break;

                case "version":
                    schema.version = reader.Value;
                    break;

                default:
                    if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                    {
                        error(h, reader.Name + " attribute is not allowed in schema element", null);
                    }
                    else
                    {
                        XmlSchemaUtil.ReadUnhandledAttribute(reader, schema);
                    }
                    break;
                }
            }
        }
Beispiel #22
0
        //<simpleType
        //  final = (#all | (list | union | restriction))
        //  id = ID
        //  name = NCName
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (restriction | list | union))
        //</simpleType>
        internal static XmlSchemaSimpleType Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleType stype = new XmlSchemaSimpleType();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaGroup.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            stype.LineNumber   = reader.LineNumber;
            stype.LinePosition = reader.LinePosition;
            stype.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "final")
                {
                    Exception innerex;
                    stype.Final = XmlSchemaUtil.ReadDerivationAttribute(reader, out innerex, "final",
                                                                        XmlSchemaUtil.FinalAllowed);
                    if (innerex != null)
                    {
                        error(h, "some invalid values not a valid value for final", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    stype.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    stype.Name = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for simpleType", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, stype);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(stype);
            }

            //	Content: (annotation?, (restriction | list | union))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleType.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                     //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        stype.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "restriction")
                    {
                        level = 3;
                        XmlSchemaSimpleTypeRestriction restriction = XmlSchemaSimpleTypeRestriction.Read(reader, h);
                        if (restriction != null)
                        {
                            stype.content = restriction;
                        }
                        continue;
                    }
                    if (reader.LocalName == "list")
                    {
                        level = 3;
                        XmlSchemaSimpleTypeList list = XmlSchemaSimpleTypeList.Read(reader, h);
                        if (list != null)
                        {
                            stype.content = list;
                        }
                        continue;
                    }
                    if (reader.LocalName == "union")
                    {
                        level = 3;
                        XmlSchemaSimpleTypeUnion union = XmlSchemaSimpleTypeUnion.Read(reader, h);
                        if (union != null)
                        {
                            stype.content = union;
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
            return(stype);
        }
        /// <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 #24
0
        //<union
        //  id = ID
        //  memberTypes = List of QName
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (simpleType*))
        //</union>
        internal static XmlSchemaSimpleTypeUnion Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaSimpleTypeUnion.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            union.LineNumber   = reader.LineNumber;
            union.LinePosition = reader.LinePosition;
            union.SourceUri    = reader.BaseURI;

            //Read Attributes
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    union.Id = reader.Value;
                }
                else if (reader.Name == "memberTypes")
                {
                    Exception innerEx;
                    string[]  names = XmlSchemaUtil.SplitList(reader.Value);
                    union.memberTypes = new XmlQualifiedName[names.Length];
                    for (int i = 0; i < names.Length; i++)
                    {
                        union.memberTypes[i] = XmlSchemaUtil.ToQName(reader, names[i], out innerEx);
                        if (innerEx != null)
                        {
                            error(h, "'" + names[i] + "' is not a valid memberType", innerEx);
                        }
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for union", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, union);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(union);
            }

            //  Content: annotation?, simpleType*
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleTypeUnion.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                     //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        union.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "simpleType")
                {
                    level = 2;
                    XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h);
                    if (stype != null)
                    {
                        union.baseTypes.Add(stype);
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(union);
        }
Beispiel #25
0
        //<complexContent
        //  id = ID
        //  mixed = boolean
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (restriction | extension))
        //</complexContent>
        internal static XmlSchemaComplexContent Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContent complex = new XmlSchemaComplexContent();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaComplexContent.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            complex.LineNumber   = reader.LineNumber;
            complex.LinePosition = reader.LinePosition;
            complex.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    complex.Id = reader.Value;
                }
                else if (reader.Name == "mixed")
                {
                    Exception innerex;
                    complex.isMixed = XmlSchemaUtil.ReadBoolAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is an invalid value for mixed", innerex);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for complexContent", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, complex);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(complex);
            }
            //Content: (annotation?, (restriction | extension))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaComplexContent.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                     //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        complex.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "restriction")
                    {
                        level = 3;
                        XmlSchemaComplexContentRestriction restriction = XmlSchemaComplexContentRestriction.Read(reader, h);
                        if (restriction != null)
                        {
                            complex.content = restriction;
                        }
                        continue;
                    }
                    if (reader.LocalName == "extension")
                    {
                        level = 3;
                        XmlSchemaComplexContentExtension extension = XmlSchemaComplexContentExtension.Read(reader, h);
                        if (extension != null)
                        {
                            complex.content = extension;
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
            return(complex);
        }
Beispiel #26
0
        //<anyAttribute
        //  id = ID
        //  namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any
        //  processContents = (lax | skip | strict) : strict
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?)
        //</anyAttribute>
        internal static XmlSchemaAnyAttribute Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAnyAttribute any = new XmlSchemaAnyAttribute();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaAnyAttribute.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            any.LineNumber   = reader.LineNumber;
            any.LinePosition = reader.LinePosition;
            any.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    any.Id = reader.Value;
                }
                else if (reader.Name == "namespace")
                {
                    any.nameSpace = reader.Value;
                }
                else if (reader.Name == "processContents")
                {
                    Exception innerex;
                    any.processing = XmlSchemaUtil.ReadProcessingAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for processContents", innerex);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for anyAttribute", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, any);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(any);
            }

            //  Content: (annotation?)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaAnyAttribute.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                          //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        any.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(any);
        }
        //<attributeGroup
        //  id = ID
        //  name = NCName
        //  ref = QName // Not present in this class.
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
        //</attributeGroup>
        internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAttributeGroup attrgrp = new XmlSchemaAttributeGroup();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            attrgrp.LineNumber   = reader.LineNumber;
            attrgrp.LinePosition = reader.LinePosition;
            attrgrp.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    attrgrp.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    attrgrp.name = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for attributeGroup in this context", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, attrgrp);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(attrgrp);
            }

            //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                     //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        attrgrp.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 2;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            attrgrp.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 2;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            attrgrp.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 3 && reader.LocalName == "anyAttribute")
                {
                    level = 4;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        attrgrp.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(attrgrp);
        }
Beispiel #28
0
        //<attributeGroup
        //  id = ID
        //  ref = QName
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?)
        //</attributeGroup>
        internal static XmlSchemaAttributeGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAttributeGroupRef attrgrp = new XmlSchemaAttributeGroupRef();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaAttributeGroupRef.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            attrgrp.LineNumber   = reader.LineNumber;
            attrgrp.LinePosition = reader.LinePosition;
            attrgrp.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    attrgrp.Id = reader.Value;
                }
                else if (reader.Name == "ref")
                {
                    Exception innerex;
                    attrgrp.refName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for ref attribute", innerex);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for attributeGroup in this context", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, attrgrp);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(attrgrp);
            }
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaAttributeGroupRef.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                     //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        attrgrp.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(attrgrp);
        }
        //<maxInclusive
        //  fixed = boolean : false
        //  id = ID
        //  value = anySimpleType
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?)
        //</maxInclusive>
        internal static XmlSchemaMaxInclusiveFacet Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaMaxInclusiveFacet maxi = new XmlSchemaMaxInclusiveFacet();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaMaxInclusiveFacet.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            maxi.LineNumber   = reader.LineNumber;
            maxi.LinePosition = reader.LinePosition;
            maxi.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    maxi.Id = reader.Value;
                }
                else if (reader.Name == "fixed")
                {
                    Exception innerex;
                    maxi.IsFixed = XmlSchemaUtil.ReadBoolAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for fixed attribute", innerex);
                    }
                }
                else if (reader.Name == "value")
                {
                    maxi.Value = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for " + xmlname, null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, maxi);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(maxi);
            }

            //  Content: (annotation?)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaMaxInclusiveFacet.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                          //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        maxi.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(maxi);
        }
Beispiel #30
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);
        }