コード例 #1
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);
        }
コード例 #2
0
        internal static XmlSchemaSimpleType Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleType xmlSchemaSimpleType = new XmlSchemaSimpleType();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "simpleType")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaGroup.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaSimpleType.LineNumber   = reader.LineNumber;
            xmlSchemaSimpleType.LinePosition = reader.LinePosition;
            xmlSchemaSimpleType.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "final")
                {
                    Exception ex;
                    xmlSchemaSimpleType.Final = XmlSchemaUtil.ReadDerivationAttribute(reader, out ex, "final", XmlSchemaUtil.FinalAllowed);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, "some invalid values not a valid value for final", ex);
                    }
                }
                else if (reader.Name == "id")
                {
                    xmlSchemaSimpleType.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    xmlSchemaSimpleType.Name = reader.Value;
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for simpleType", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaSimpleType);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaSimpleType);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "simpleType")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaSimpleType.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaSimpleType.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "restriction")
                        {
                            num = 3;
                            XmlSchemaSimpleTypeRestriction xmlSchemaSimpleTypeRestriction = XmlSchemaSimpleTypeRestriction.Read(reader, h);
                            if (xmlSchemaSimpleTypeRestriction != null)
                            {
                                xmlSchemaSimpleType.content = xmlSchemaSimpleTypeRestriction;
                            }
                            continue;
                        }
                        if (reader.LocalName == "list")
                        {
                            num = 3;
                            XmlSchemaSimpleTypeList xmlSchemaSimpleTypeList = XmlSchemaSimpleTypeList.Read(reader, h);
                            if (xmlSchemaSimpleTypeList != null)
                            {
                                xmlSchemaSimpleType.content = xmlSchemaSimpleTypeList;
                            }
                            continue;
                        }
                        if (reader.LocalName == "union")
                        {
                            num = 3;
                            XmlSchemaSimpleTypeUnion xmlSchemaSimpleTypeUnion = XmlSchemaSimpleTypeUnion.Read(reader, h);
                            if (xmlSchemaSimpleTypeUnion != null)
                            {
                                xmlSchemaSimpleType.content = xmlSchemaSimpleTypeUnion;
                            }
                            continue;
                        }
                    }
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaSimpleType);
        }