//<appinfo
        //  source = anyURI>
        //  Content: ({any})*
        //</appinfo>
        internal static XmlSchemaAppInfo Read(XmlSchemaReader reader, ValidationEventHandler h, out bool skip)
        {
            skip = false;
            XmlSchemaAppInfo appinfo = new XmlSchemaAppInfo();

            reader.MoveToElement();

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

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

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "source")
                {
                    appinfo.source = reader.Value;
                }
                else
                {
                    error(h, reader.Name + " is not a valid attribute for appinfo", null);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                appinfo.Markup = new XmlNode [0];
                return(appinfo);
            }

            //Content {any}*
            //FIXME: This is a pure Quick Hack; There must be a another method;
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.AppendChild(xmldoc.ReadNode(reader));
            XmlNode root = xmldoc.FirstChild;

            if (root != null && root.ChildNodes != null)
            {
                appinfo.Markup = new XmlNode[root.ChildNodes.Count];
                for (int i = 0; i < root.ChildNodes.Count; i++)
                {
                    appinfo.Markup[i] = root.ChildNodes[i];
                }
            }
            if (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement)
            {
                skip = true;
            }
            return(appinfo);
        }
示例#2
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);
        }