// Function to execute a specified user-defined XPath extension
        // function at run time.
        public object Invoke(System.Xml.Xsl.XsltContext xsltContext,
                             object[] args, System.Xml.XPath.XPathNavigator docContext)
        {
            if (FunctionName == "CountChar")
            {
                return((Object)CountChar((XPathNodeIterator)args[0],
                                         Convert.ToChar(args[1])));
            }
            if (FunctionName == "FindTaskBy")
            {
                return(FindTaskBy((XPathNodeIterator)args[0],
                                  Convert.ToString(args[1])));
            }

            if (FunctionName == "Left")
            {
                return((Object)Left(Convert.ToString(args[0]),
                                    Convert.ToInt16(args[1])));
            }

            if (FunctionName == "Right")
            {
                return((Object)Right(Convert.ToString(args[0]),
                                     Convert.ToInt16(args[1])));
            }

            return(null);
        }
Exemple #2
0
        internal HtmlNode SelectSingleNode(string xpath, System.Xml.Xsl.XsltContext additionalContext)
        {
            Debug.Assert(m_XmlNode != null);

            Debug.Assert(xpath != null);
            if (xpath == null)
            {
                throw new ArgumentNullException("xpath");
            }

            //TODO: The XPATH is mixes case because if not some XPath functions will not work
            //      May be we need an XPathExpression parser, which will only change the
            //      case of the elements and attribute names !!! Will be very cool.
            XmlNode result = m_XmlNode.SelectSingleNode(xpath, XPath.HtmlXsltContext.GetInstance(additionalContext));

            if (result == null || (!(result is XmlRefElement) && !(result is XmlRefAttribute)))
            {
                return(null);
            }
            else
            {
                IHtmlNodeReferenceHolder resRef = result as IHtmlNodeReferenceHolder;
                if (resRef != null)
                {
                    return(resRef.HtmlNodeReference);
                }

                Debug.Assert(false);
                throw new XPathException("The type returned by an XPath operation was unexpected!");
            }
        }
Exemple #3
0
        /// <summary>
        /// Selects the list of nodes matching the XPath expression. External user-defined functions will be resolved using the supplied System.Xml.Xsl.XsltContext.
        /// </summary>
        /// <param name="xpath">The XPath expression.</param>
        /// <param name="additionalContext">An System.Xml.Xsl.XsltContext to use for resolving any user-defined functions
        ///     used in the XPath expression.</param>
        /// <exception cref="System.Xml.XPath.XPathException"></exception>
        /// <exception cref="Acrux.Html.HtmlParserException"></exception>
        /// <returns>An Acrux.Html.HtmlNodeList containing a collection of nodes matching the XPath
        ///     query. The HtmlNodeList should not be expected to be connected "live" to the
        ///     HTML document. That is, changes that appear in the HTML document may not appear
        ///     in the HtmlNodeList, and vice versa.</returns>
        internal HtmlNodeList SelectNodes(string xpath, System.Xml.Xsl.XsltContext additionalContext)
        {
            Debug.Assert(m_XmlNode != null);

            Debug.Assert(xpath != null);
            if (xpath == null)
            {
                throw new ArgumentNullException("xpath");
            }

            //TODO: The XPATH is mixes case because if not some XPath functions will not work
            //      May be we need an XPathExpression parser, which will only change the
            //      case of the elements and attribute names !!! Will be very cool.

            try
            {
                XmlNodeList result = m_XmlNode.SelectNodes(xpath, XPath.HtmlXsltContext.GetInstance(additionalContext));

                return(new HtmlNodeList(result));
            }
            catch (Exception ex)
            {
                throw new XPathException(string.Format(CultureInfo.InvariantCulture, "Error selecting nodes. X-Path expression: {0}", xpath), ex);
            }
        }
Exemple #4
0
        internal object EvaluateXPath(string xpath, System.Xml.Xsl.XsltContext additionalContext)
        {
            Debug.Assert(m_XmlNode != null);

            Debug.Assert(xpath != null);
            if (xpath == null)
            {
                throw new ArgumentNullException("xpath");
            }

            //TODO: [MOVE AS A DEVELOPMENT TASK] - Implement XPath Expression Parser
            //      The XPATH is mixed case because if not some XPath functions will not work
            //      May be we need an XPathExpression parser, which will only change the
            //      case of the elements and attribute names !!! Will be very cool.
            XPathNavigator  nav  = m_XmlNode.CreateNavigator();
            XPathExpression expr = nav.Compile(xpath);

            expr.SetContext(XPath.HtmlXsltContext.GetInstance(additionalContext));

            try
            {
                object result = nav.Evaluate(expr);
                return(result);
            }
            catch (XPathException ex)
            {
                throw new XPathException(string.Format(CultureInfo.InvariantCulture, "Error evaluating X-Path expression: {0}", xpath), ex);
            }
        }
Exemple #5
0
        // Function to execute a specified user-defined XPath extension
        // function at run time.
        public object Invoke(System.Xml.Xsl.XsltContext xsltContext,
                             object[] args, System.Xml.XPath.XPathNavigator docContext)
        {
            var result = GetMatchingFunction(this.FunctionName, this.GetType(),
                                             (method, xpathExtensionAttr) =>
            {
                var methodArgs = args
                                 .Zip(method.GetParameters(),
                                      (arg, parameter) => xpathExtensionAttr.BindArgumentToParameter(arg, parameter))
                                 .ToArray();
                return(method.Invoke(this, methodArgs));
            },
                                             () =>
            {
                var msgLine1 = $"`{this.GetType().FullName}` does not contain a method" +
                               $" that implements `{this.FunctionName}` with an Attribute that extends {typeof(IExtendXPath).FullName}";
                var msgLine2 = $"\nEnsure there is a single attribute extending {typeof(IExtendXPath).FullName} a method" +
                               $" named, or with {typeof(IExtendXPath).FullName}.Name equal to `{this.FunctionName}` on {this.GetType().FullName}.";
                throw new Exception(msgLine1 + msgLine2);
            });

            return(result);
        }
Exemple #6
0
 public XPathMessageFilter(System.Xml.XmlReader reader, System.Xml.Xsl.XsltContext context)
 {
 }
Exemple #7
0
 public XPathMessageFilter(string xpath, System.Xml.Xsl.XsltContext context)
 {
 }
 public XPathMessageQuery(string expression, System.Xml.Xsl.XsltContext context)
 {
 }