internal static XmlSchemaAttribute Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAttribute xmlSchemaAttribute = new XmlSchemaAttribute();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "attribute")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaAttribute.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }
            xmlSchemaAttribute.LineNumber   = reader.LineNumber;
            xmlSchemaAttribute.LinePosition = reader.LinePosition;
            xmlSchemaAttribute.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "default")
                {
                    xmlSchemaAttribute.defaultValue = reader.Value;
                }
                else if (reader.Name == "fixed")
                {
                    xmlSchemaAttribute.fixedValue = reader.Value;
                }
                else if (reader.Name == "form")
                {
                    Exception ex;
                    xmlSchemaAttribute.form = XmlSchemaUtil.ReadFormAttribute(reader, out ex);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for form attribute", ex);
                    }
                }
                else if (reader.Name == "id")
                {
                    xmlSchemaAttribute.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    xmlSchemaAttribute.name = reader.Value;
                }
                else if (reader.Name == "ref")
                {
                    Exception ex2;
                    xmlSchemaAttribute.refName = XmlSchemaUtil.ReadQNameAttribute(reader, out ex2);
                    if (ex2 != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for ref attribute", ex2);
                    }
                }
                else if (reader.Name == "type")
                {
                    Exception ex3;
                    xmlSchemaAttribute.schemaTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out ex3);
                    if (ex3 != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for type attribute", ex3);
                    }
                }
                else if (reader.Name == "use")
                {
                    Exception ex4;
                    xmlSchemaAttribute.use = XmlSchemaUtil.ReadUseAttribute(reader, out ex4);
                    if (ex4 != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for use attribute", ex4);
                    }
                }
                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 attribute", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaAttribute);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaAttribute);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "attribute")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaAttribute.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaAttribute.Annotation = xmlSchemaAnnotation;
                    }
                }
                else if (num <= 2 && reader.LocalName == "simpleType")
                {
                    num = 3;
                    XmlSchemaSimpleType xmlSchemaSimpleType = XmlSchemaSimpleType.Read(reader, h);
                    if (xmlSchemaSimpleType != null)
                    {
                        xmlSchemaAttribute.schemaType = xmlSchemaSimpleType;
                    }
                }
                else
                {
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaAttribute);
        }
Пример #2
0
        //<attribute
        //  default = string
        //  fixed = string
        //  form = (qualified | unqualified)
        //  id = ID
        //  name = NCName
        //  ref = QName
        //  type = QName
        //  use = (optional | prohibited | required) : optional
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (simpleType?))
        //</attribute>
        internal static XmlSchemaAttribute Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAttribute attribute = new XmlSchemaAttribute();

            reader.MoveToElement();

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

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

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "default")
                {
                    attribute.defaultValue = reader.Value;
                }
                else if (reader.Name == "fixed")
                {
                    attribute.fixedValue = reader.Value;
                }
                else if (reader.Name == "form")
                {
                    Exception innerex;
                    attribute.form = XmlSchemaUtil.ReadFormAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for form attribute", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    attribute.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    attribute.name = reader.Value;
                }
                else if (reader.Name == "ref")
                {
                    Exception innerex;
                    attribute.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.Name == "type")
                {
                    Exception innerex;
                    attribute.schemaTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for type attribute", innerex);
                    }
                }
                else if (reader.Name == "use")
                {
                    Exception innerex;
                    attribute.use = XmlSchemaUtil.ReadUseAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for use attribute", innerex);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for attribute", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, attribute);
                }
            }

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

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

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaAttribute.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)
                    {
                        attribute.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "simpleType")
                {
                    level = 3;
                    XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h);
                    if (stype != null)
                    {
                        attribute.schemaType = stype;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(attribute);
        }