示例#1
0
        //<annotation
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (appinfo | documentation)*
        //</annotation>
        internal static XmlSchemaAnnotation Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();

            reader.MoveToElement();

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

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

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

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

            //Content: (appinfo | documentation)*
            bool   skip        = false;
            string expectedEnd = null;

            while (!reader.EOF)
            {
                if (skip)
                {
                    skip = false;
                }
                else
                {
                    reader.ReadNextElement();
                }

                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    bool   end      = true;
                    string expected = xmlname;
                    if (expectedEnd != null)
                    {
                        expected    = expectedEnd;
                        expectedEnd = null;
                        end         = false;
                    }
                    if (reader.LocalName != expected)
                    {
                        error(h, "Should not happen :2: XmlSchemaAnnotation.Read, name=" + reader.Name + ",expected=" + expected, null);
                    }
                    if (end)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                if (reader.LocalName == "appinfo")
                {
                    XmlSchemaAppInfo appinfo = XmlSchemaAppInfo.Read(reader, h, out skip);
                    if (appinfo != null)
                    {
                        annotation.items.Add(appinfo);
                    }
                    continue;
                }
                if (reader.LocalName == "documentation")
                {
                    XmlSchemaDocumentation documentation = XmlSchemaDocumentation.Read(reader, h, out skip);
                    if (documentation != null)
                    {
                        annotation.items.Add(documentation);
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(annotation);
        }
        internal static XmlSchemaAnnotation Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAnnotation xmlSchemaAnnotation = new XmlSchemaAnnotation();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "annotation")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaAnnotation.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }
            xmlSchemaAnnotation.LineNumber   = reader.LineNumber;
            xmlSchemaAnnotation.LinePosition = reader.LinePosition;
            xmlSchemaAnnotation.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaAnnotation.Id = 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 annotation", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaAnnotation);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaAnnotation);
            }
            bool   flag = false;
            string text = null;

            while (!reader.EOF)
            {
                if (flag)
                {
                    flag = false;
                }
                else
                {
                    reader.ReadNextElement();
                }
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    bool   flag2 = true;
                    string text2 = "annotation";
                    if (text != null)
                    {
                        text2 = text;
                        text  = null;
                        flag2 = false;
                    }
                    if (reader.LocalName != text2)
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaAnnotation.Read, name=" + reader.Name + ",expected=" + text2, null);
                    }
                    if (flag2)
                    {
                        break;
                    }
                }
                else if (reader.LocalName == "appinfo")
                {
                    XmlSchemaAppInfo xmlSchemaAppInfo = XmlSchemaAppInfo.Read(reader, h, out flag);
                    if (xmlSchemaAppInfo != null)
                    {
                        xmlSchemaAnnotation.items.Add(xmlSchemaAppInfo);
                    }
                }
                else if (reader.LocalName == "documentation")
                {
                    XmlSchemaDocumentation xmlSchemaDocumentation = XmlSchemaDocumentation.Read(reader, h, out flag);
                    if (xmlSchemaDocumentation != null)
                    {
                        xmlSchemaAnnotation.items.Add(xmlSchemaDocumentation);
                    }
                }
                else
                {
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaAnnotation);
        }