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
        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 #3
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 #4
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);
        }
Example #5
0
        //<extension
        //  base = QName
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
        //</extension>
        internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();

            reader.MoveToElement();

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

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

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception innerex;
                    extension.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")
                {
                    extension.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for extension", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, extension);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(extension);
            }
            //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: XmlSchemaComplexContentExtension.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)
                    {
                        extension.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "group")
                    {
                        level = 3;
                        XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h);
                        if (group != null)
                        {
                            extension.particle = group;
                        }
                        continue;
                    }
                    if (reader.LocalName == "all")
                    {
                        level = 3;
                        XmlSchemaAll all = XmlSchemaAll.Read(reader, h);
                        if (all != null)
                        {
                            extension.particle = all;
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 3;
                        XmlSchemaChoice choice = XmlSchemaChoice.Read(reader, h);
                        if (choice != null)
                        {
                            extension.particle = choice;
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 3;
                        XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h);
                        if (sequence != null)
                        {
                            extension.particle = sequence;
                        }
                        continue;
                    }
                }
                if (level <= 3)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 3;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            extension.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 3;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            extension.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 4 && reader.LocalName == "anyAttribute")
                {
                    level = 5;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        extension.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(extension);
        }