Пример #1
0
        //<selector
        //  id = ID
        //  xpath = a subset of XPath expression, see below
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?)
        //</selector>
        internal static XmlSchemaXPath Read(XmlSchemaReader reader, ValidationEventHandler h, string name)
        {
            XmlSchemaXPath path = new XmlSchemaXPath();

            reader.MoveToElement();

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

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

            XmlNamespaceManager currentMgr = XmlSchemaUtil.GetParserContext(reader.Reader).NamespaceManager;

            if (currentMgr != null)
            {
                path.nsmgr = new XmlNamespaceManager(reader.NameTable);
                IEnumerator e = currentMgr.GetEnumerator();
                while (e.MoveNext())
                {
                    string prefix = e.Current as string;
                    switch (prefix)
                    {
                    case "xml":
                    case "xmlns":
                        continue;

                    default:
                        path.nsmgr.AddNamespace(prefix, currentMgr.LookupNamespace(prefix, false));
                        break;
                    }
                }
            }

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

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

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

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != name)
                    {
                        error(h, "Should not happen :2: XmlSchemaXPath.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)
                    {
                        path.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(path);
        }
Пример #2
0
        internal static XmlSchemaXPath Read(XmlSchemaReader reader, ValidationEventHandler h, string name)
        {
            XmlSchemaXPath xmlSchemaXPath = new XmlSchemaXPath();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != name)
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaXPath.LineNumber   = reader.LineNumber;
            xmlSchemaXPath.LinePosition = reader.LinePosition;
            xmlSchemaXPath.SourceUri    = reader.BaseURI;
            XmlNamespaceManager namespaceManager = XmlSchemaUtil.GetParserContext(reader.Reader).NamespaceManager;

            if (namespaceManager != null)
            {
                xmlSchemaXPath.nsmgr = new XmlNamespaceManager(reader.NameTable);
                foreach (object obj in namespaceManager)
                {
                    string text  = obj as string;
                    string text2 = text;
                    if (text2 != null)
                    {
                        if (XmlSchemaXPath.< > f__switch$map3C == null)
                        {
                            XmlSchemaXPath.< > f__switch$map3C = new Dictionary <string, int>(2)
                            {
                                {
                                    "xml",
                                    0
                                },
                                {
                                    "xmlns",
                                    0
                                }
                            };
                        }
                        int num;
                        if (XmlSchemaXPath.< > f__switch$map3C.TryGetValue(text2, out num))
                        {
                            if (num == 0)
                            {
                                continue;
                            }
                        }
                    }
                    xmlSchemaXPath.nsmgr.AddNamespace(text, namespaceManager.LookupNamespace(text, false));
                }
            }
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaXPath.Id = reader.Value;
                }
                else if (reader.Name == "xpath")
                {
                    xmlSchemaXPath.xpath = 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 " + name, null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaXPath);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaXPath);
            }
            int num2 = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != name)
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaXPath.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num2 <= 1 && reader.LocalName == "annotation")
                {
                    num2 = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaXPath.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaXPath);
        }