Beispiel #1
0
        /// <summary>
        /// Evaluates the XPath expression and returns the typed result.
        /// </summary>
        /// <param name="xpath">A string representing an XPath expression that can be evaluated.</param>
        /// <returns></returns>
        public object SelectXmlNodes(string xpath)
        {
            object retval = null;
            // get the selected node
            XPathNavigatorTreeNode node = this.SelectedNode as XPathNavigatorTreeNode;

            // if there is no selected node, default to the root node
            if (node == null && this.Nodes.Count > 0)
            {
                node = this.GetRootXmlTreeNode();
            }

            if (node == null)
            {
                return(null);
            }

            try
            {
                XPathExpression xpe = node.Navigator.Compile(xpath);
                retval = node.Navigator.Evaluate(xpe);
            }
            catch (Exception ex)
            {
                ExpressionResultsWindow dialog = new ExpressionResultsWindow();
                dialog.Expression = xpath;
                dialog.Result     = ex.Message;
                dialog.ShowDialog(this.FindForm());
                logger.Error(SQLSchemaTool.ERRORFORMAT, ex.Message, ex.Source, ex.StackTrace);
            }
            // evaluate the expression, return the result
            return(retval);
        }
Beispiel #2
0
        /// <summary>
        /// Finds and selects an XPathNavigatorTreeNode using an XPath expression.
        /// </summary>
        /// <param name="xpath">An XPath expression.</param>
        /// <returns></returns>
        public bool FindByXpath(string xpath)
        {
            // evaluate the expression
            object result = this.SelectXmlNodes(xpath);

            if (result == null)
            {
                return(false);
            }

            // did the expression evaluate to a node set?
            XPathNodeIterator iterator = result as XPathNodeIterator;

            if (iterator != null)
            {
                // the expression evaluated to a node set
                if (iterator == null || iterator.Count < 1)
                {
                    return(false);
                }

                if (!iterator.MoveNext())
                {
                    return(false);
                }

                // select the first node in the set
                return(this.SelectXmlTreeNode(iterator.Current));
            }
            else
            {
                // the expression evaluated to something else, most likely a count()
                // show the result in a new window
                ExpressionResultsWindow dialog = new ExpressionResultsWindow();
                dialog.Expression = xpath;
                dialog.Result     = result.ToString();
                dialog.ShowDialog(this.FindForm());
                return(true);
            }
        }
        /// <summary>
        /// Finds and selects an XPathNavigatorTreeNode using an XPath expression.
        /// </summary>
        /// <param name="xpath">An XPath expression.</param>
        /// <returns></returns>
        public bool FindByXpath(string xpath)
        {
            // evaluate the expression
            object result = this.SelectXmlNodes(xpath);

            if (result == null)
                return false;

            // did the expression evaluate to a node set?
            XPathNodeIterator iterator = result as XPathNodeIterator;

            if (iterator != null)
            {
                // the expression evaluated to a node set
                if (iterator == null || iterator.Count < 1)
                    return false;

                if (!iterator.MoveNext())
                    return false;

                // select the first node in the set
                return this.SelectXmlTreeNode(iterator.Current);
            }
            else
            {
                // the expression evaluated to something else, most likely a count()
                // show the result in a new window
                ExpressionResultsWindow dialog = new ExpressionResultsWindow();
                dialog.Expression = xpath;
                dialog.Result = result.ToString();
                dialog.ShowDialog(this.FindForm());
                return true;
            }
        }
        /// <summary>
        /// Evaluates the XPath expression and returns the typed result.
        /// </summary>
        /// <param name="xpath">A string representing an XPath expression that can be evaluated.</param>
        /// <returns></returns>
        public object SelectXmlNodes(string xpath)
        {
            object retval = null;
            // get the selected node
            XPathNavigatorTreeNode node = this.SelectedNode as XPathNavigatorTreeNode;

            // if there is no selected node, default to the root node
            if (node == null && this.Nodes.Count > 0)
                node = this.GetRootXmlTreeNode();

            if (node == null)
                return null;

            try
            {
                XPathExpression xpe = node.Navigator.Compile(xpath);
                retval = node.Navigator.Evaluate(xpe);
            }
            catch(Exception ex)
            {
                ExpressionResultsWindow dialog = new ExpressionResultsWindow();
                dialog.Expression = xpath;
                dialog.Result = ex.Message;
                dialog.ShowDialog(this.FindForm());
                logger.Error(SQLSchemaTool.ERRORFORMAT, ex.Message, ex.Source, ex.StackTrace);
            }
            // evaluate the expression, return the result
            return retval;
        }