Ejemplo n.º 1
0
        //Вычисление выражений с помощью XPath
        static void Main(string[] args)
        {
            double sum = 0;

            //Создание XPath документа:
            XPathDocument  xPathDocument  = new XPathDocument("books.xml");
            XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();

            //Вычисляющий запрос с дополнительной компиляцией.
            XPathExpression xPathExpression = xPathNavigator.Compile("sum(ListOfBooks/Book/Price/text())");

            Console.WriteLine(xPathExpression.ReturnType);

            if (xPathExpression.ReturnType == XPathResultType.Number)
            {
                sum = (double)xPathNavigator.Evaluate(xPathExpression);
                Console.WriteLine(sum);
            }

            //Вычисляющий запрос без предварительной компиляции.
            //Кроме выборки производится арифметическое вычисление.
            sum = (double)xPathNavigator.Evaluate("sum(//Price/text())*10");
            Console.WriteLine(sum);

            XPathNodeIterator elements = (XPathNodeIterator)xPathNavigator.Evaluate("//Title[@FontSize='10']");
            var enumaretor             = elements.GetEnumerator();

            while (enumaretor.MoveNext())
            {
                Console.WriteLine((enumaretor.Current as XPathNavigator).Value);
            }

            //Delay
            Console.ReadKey();
        }
        // Token: 0x0600637A RID: 25466 RVA: 0x001BF9AC File Offset: 0x001BDBAC
        private List <Guid> FindAnnotationIds(string queryExpression)
        {
            Invariant.Assert(queryExpression != null && queryExpression.Length > 0, "Invalid query expression");
            List <Guid> list     = null;
            object      syncRoot = base.SyncRoot;

            lock (syncRoot)
            {
                this.CheckStatus();
                XPathNavigator    xpathNavigator    = this._document.CreateNavigator();
                XPathNodeIterator xpathNodeIterator = xpathNavigator.Select(queryExpression, this._namespaceManager);
                if (xpathNodeIterator != null && xpathNodeIterator.Count > 0)
                {
                    list = new List <Guid>(xpathNodeIterator.Count);
                    using (IEnumerator enumerator = xpathNodeIterator.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            object         obj             = enumerator.Current;
                            XPathNavigator xpathNavigator2 = (XPathNavigator)obj;
                            string         attribute       = xpathNavigator2.GetAttribute("Id", "");
                            if (string.IsNullOrEmpty(attribute))
                            {
                                throw new XmlException(SR.Get("RequiredAttributeMissing", new object[]
                                {
                                    "Id",
                                    "Annotation"
                                }));
                            }
                            Guid item;
                            try
                            {
                                item = XmlConvert.ToGuid(attribute);
                            }
                            catch (FormatException innerException)
                            {
                                throw new InvalidOperationException(SR.Get("CannotParseId"), innerException);
                            }
                            list.Add(item);
                        }
                        return(list);
                    }
                }
                list = new List <Guid>(0);
            }
            return(list);
        }
Ejemplo n.º 3
0
        public ArrayList SelectElementsByXPath(string xpath)
        {
            if (shouldWait)
            {
                WaitForDocumentToComplete(HtmlDocument);
            }

            XPathNavigator    navigator = CreateNavigator();
            XPathNodeIterator nodes     = navigator.Select(xpath);
            IEnumerator       allNodes  = nodes.GetEnumerator();
            ArrayList         elements  = new ArrayList();

            while (allNodes.MoveNext())
            {
                NavigableDocument node = (NavigableDocument)allNodes.Current;
                elements.Add(new WrappedWebElement(this, node.UnderlyingObject as IHTMLDOMNode));
            }
            return(elements);
        }