Example #1
0
        private Particle PopulateParticle(ComplexType ct)
        {
            if (ct.ContentModel == null)
            {
                if (ct.Particle == null)
                {
                    ct.Particle = CreateSequence();
                }
                return(ct.Particle);
            }
            ComplexModel cm = ct.ContentModel as ComplexModel;

            if (cm != null)
            {
                ComplexExt ce = cm.Content as ComplexExt;
                if (ce != null)
                {
                    if (ce.Particle == null)
                    {
                        ce.Particle = CreateSequence();
                    }
                    return(ce.Particle);
                }
                ComplexRst cr = cm.Content as ComplexRst;
                if (cr != null)
                {
                    if (cr.Particle == null)
                    {
                        cr.Particle = CreateSequence();
                    }
                    return(cr.Particle);
                }
            }
            throw Error(ct, "Schema inference internal error. The complexType should have been converted to have a complex content.");
        }
Example #2
0
        /// <remarks>
        /// 1. Content 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 (isRedefinedComponent)
            {
                if (Annotation != null)
                {
                    Annotation.isRedefinedComponent = true;
                }
                if (Content != null)
                {
                    Content.isRedefinedComponent = true;
                }
            }

            if (Content == null)
            {
                error(h, "Content must be present in a complexContent");
            }
            else
            {
                if (Content is XmlSchemaComplexContentRestriction)
                {
                    XmlSchemaComplexContentRestriction xscr = (XmlSchemaComplexContentRestriction)Content;
                    errorCount += xscr.Compile(h, schema);
                }
                else if (Content is XmlSchemaComplexContentExtension)
                {
                    XmlSchemaComplexContentExtension xsce = (XmlSchemaComplexContentExtension)Content;
                    errorCount += xsce.Compile(h, schema);
                }
                else
                {
                    error(h, "complexContent can't have any value other than restriction or extention");
                }
            }

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

            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
Example #3
0
        private SOMList GetAttributes(ComplexType ct)
        {
            if (ct.ContentModel == null)
            {
                return(ct.Attributes);
            }

            SimpleModel sc = ct.ContentModel as SimpleModel;

            if (sc != null)
            {
                SimpleExt sce = sc.Content as SimpleExt;
                if (sce != null)
                {
                    return(sce.Attributes);
                }
                SimpleRst scr = sc.Content as SimpleRst;
                if (scr != null)
                {
                    return(scr.Attributes);
                }
                else
                {
                    throw Error(sc, "Invalid simple content model.");
                }
            }
            ComplexModel cc = ct.ContentModel as ComplexModel;

            if (cc != null)
            {
                ComplexExt cce = cc.Content as ComplexExt;
                if (cce != null)
                {
                    return(cce.Attributes);
                }
                ComplexRst ccr = cc.Content as ComplexRst;
                if (ccr != null)
                {
                    return(ccr.Attributes);
                }
                else
                {
                    throw Error(cc, "Invalid simple content model.");
                }
            }
            throw Error(cc, "Invalid complexType. Should not happen.");
        }
Example #4
0
        private void ToEmptiableComplexContent(
            ComplexModel cm, bool isNew)
        {
            ComplexExt ce = cm.Content
                            as ComplexExt;

            if (ce != null)
            {
                if (ce.Particle != null)
                {
                    ce.Particle.MinOccurs = 0;
                }
                else if (ce.BaseTypeName != null &&
                         ce.BaseTypeName != QName.Empty &&
                         ce.BaseTypeName != QNameAnyType)
                {
                    throw Error(ce, "Complex type content extension has a reference to an external component that is not supported.");
                }
            }
            else
            {
                ComplexRst cr = cm.Content
                                as ComplexRst;
                if (cr == null)
                {
                    throw Error(cm, "Invalid complex content model was passed.");
                }
                if (cr.Particle != null)
                {
                    cr.Particle.MinOccurs = 0;
                }
                else if (cr.BaseTypeName != null &&
                         cr.BaseTypeName != QName.Empty &&
                         cr.BaseTypeName != QNameAnyType)
                {
                    throw Error(cr, "Complex type content extension has a reference to an external component that is not supported.");
                }
            }
        }
Example #5
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);
        }
        //<restriction
        //  base = QName
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
        //</restriction>
        internal static XmlSchemaComplexContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction();

            reader.MoveToElement();

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

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

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

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(restriction);
            }
            //Content: 1. annotation?,
            //			(2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaComplexContentRestriction.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)
                    {
                        restriction.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "group")
                    {
                        level = 3;
                        XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h);
                        if (group != null)
                        {
                            restriction.particle = group;
                        }
                        continue;
                    }
                    if (reader.LocalName == "all")
                    {
                        level = 3;
                        XmlSchemaAll all = XmlSchemaAll.Read(reader, h);
                        if (all != null)
                        {
                            restriction.particle = all;
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 3;
                        XmlSchemaChoice choice = XmlSchemaChoice.Read(reader, h);
                        if (choice != null)
                        {
                            restriction.particle = choice;
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 3;
                        XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h);
                        if (sequence != null)
                        {
                            restriction.particle = sequence;
                        }
                        continue;
                    }
                }
                if (level <= 3)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 3;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 3;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            restriction.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 4 && reader.LocalName == "anyAttribute")
                {
                    level = 5;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        restriction.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(restriction);
        }