// Constructor used in the ResolveFunction method of the custom XsltContext
 // class to return an instance of IXsltContextFunction at run time.
 public XPathExtensionFunctions(int minArgs, int maxArgs,
                                XPathResultType returnType, XPathResultType[] argTypes, string functionName)
 {
     this.minArgs      = minArgs;
     this.maxArgs      = maxArgs;
     this.returnType   = returnType;
     this.argTypes     = argTypes;
     this.FunctionName = functionName;
 }
 // Constructor used in the ResolveFunction method of the custom XsltContext
 // class to return an instance of IXsltContextFunction at run time.
 public EasyXsltContextFunctions(int minArgs, int maxArgs,
                                 XPathResultType returnType, XPathResultType[] argTypes, string functionName)
 {
     this.minArgs      = minArgs;
     this.maxArgs      = maxArgs;
     this.returnType   = returnType;
     this.argTypes     = argTypes;
     this.FunctionName = functionName;
 }
Beispiel #3
0
        /// <summary>
        /// Perform an XPath search.
        /// </summary>
        /// <param name="xpathStrings">List of strings to search against.</param>
        public void DoSearch(string[] xpathStrings)
        {
            try
            {
                worker.ReportProgress(0, new ProgressReporter("Processing..."));
                XmlDocument XMLdoc = new XmlDocument();
                try
                {
                    IntPtr        curScintilla = PluginBase.GetCurrentScintilla();
                    int           length       = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_GETLENGTH, 0, 0) + 1;
                    StringBuilder sb           = new StringBuilder(length);

                    //Construct Scintilla Gateway, pull text and append document text into sb object.
                    //This prevents the need for massive reconstruction
                    ScintillaGateway Scintilla = new ScintillaGateway(curScintilla);
                    sb.Append(Scintilla.GetText(length));

                    string doc = sb.ToString();

                    if (Main.settings.IgnoreDocType)
                    {
                        XMLdoc.XmlResolver = null;
                    }
                    XMLdoc.LoadXml(doc.Replace("&", "&amp;"));
                }
                catch (XmlException xex)
                {
                    worker.ReportProgress(0, new ProgressReporter("Document ERROR"));
                    worker.ReportProgress(0, new ProgressReporter(xex.Message, "Document ERROR"));
                    try
                    {
                        IntPtr curScintilla = PluginBase.GetCurrentScintilla();
                        int    startPos     = (int)Win32.SendMessage(curScintilla, SciMsg.SCI_POSITIONFROMLINE, xex.LineNumber - 1, 0) + xex.LinePosition - 1;
                        Win32.SendMessage(curScintilla, SciMsg.SCI_GOTOPOS, startPos, 0);
                    }
                    catch { }
                    return;
                }

                bool bitDefaultRemoved = false;

                if (Main.settings.defaultNamespace == "")
                {
                    int Before = XMLdoc.OuterXml.Length;
                    XMLdoc = Main.RemoveDefaultNamespaces(XMLdoc);
                    if (XMLdoc.OuterXml.Length != Before)
                    {
                        bitDefaultRemoved = true;
                    }
                }

                XPathNavigator      navigator = XMLdoc.CreateNavigator();
                XmlNamespaceManager xnm       = new XmlNamespaceManager(XMLdoc.NameTable);
                Main.DNSCount = 1;
                xnm           = Main.GetNameSpaces(XMLdoc.SelectSingleNode("/*"), xnm);
                XPathExpression xpe;
                object          result;
                string          strres = "";
                System.Xml.XPath.XPathResultType xprt = System.Xml.XPath.XPathResultType.Any;

                int i = 1;

                foreach (string s in xpathStrings)
                {
                    if (worker.CancellationPending)
                    {
                        return;
                    }
                    string xPath = s;
                    //xPath Comments support.
                    //I know xPath 1.0 does not support these, but it is nice to be able to store comments at least in NPP.
                    while (xPath.Contains("(:") && xPath.Contains(":)"))
                    {
                        int intStart = xPath.IndexOf("(:");
                        int intEnd   = xPath.IndexOf(":)", i);

                        if (intEnd <= intStart)
                        {
                            intEnd = xPath.Length - 2;
                        }

                        xPath = xPath.Remove(intStart, intEnd - intStart + 2);
                    }
                    if (xPath != "")
                    {
                        try
                        {
                            xpe    = XPathExpression.Compile(xPath, xnm);
                            result = navigator.Evaluate(xpe);
                            xprt   = xpe.ReturnType;
                            strres = result.ToString();
                        }
                        catch (System.Xml.XPath.XPathException xpx)
                        {
                            worker.ReportProgress(0, new ProgressReporter(i + ": ERROR"));
                            worker.ReportProgress(0, new ProgressReporter(xpx.Message.Replace("'" + xPath + "'", "The xPath statement"), i + ": ERROR"));
                            i++;
                            continue;
                        }
                        if (xprt == System.Xml.XPath.XPathResultType.NodeSet)
                        {
                            XPathNodeIterator xpni = navigator.Select(xPath, xnm);
                            string            ss   = "s";
                            try
                            {
                                if (xpni.Count == 1)
                                {
                                    ss = "";
                                }
                            }
                            catch (Exception ex)
                            {
                                worker.ReportProgress(0, new ProgressReporter(i + ": ERROR"));
                                worker.ReportProgress(0, new ProgressReporter(ex.Message, i + ": ERROR"));
                                i++;
                                continue;
                            }
                            TreeNode tNode = new TreeNode(i + ": " + xpni.Count + " Hit" + ss);
                            tNode.Tag = "X:" + xPath;
                            worker.ReportProgress(0, new ProgressReporter(tNode));
                            while (xpni.MoveNext())
                            {
                                if (worker.CancellationPending)
                                {
                                    return;
                                }
                                if (xpni.Current is IHasXmlNode)
                                {
                                    XmlNode Node     = ((IHasXmlNode)xpni.Current).GetNode();
                                    string  pos      = Main.FindXPath(Node, bitDefaultRemoved);
                                    string  NodeText = Main.NodetoText(xpni.Current.OuterXml);
                                    if (NodeText.StartsWith("Text") || NodeText.StartsWith("CDATA"))
                                    {
                                        tNode = new TreeNode(NodeText);
                                    }
                                    else
                                    {
                                        TreeNode[] childNodes = GetChildren(Node, bitDefaultRemoved);
                                        if (childNodes != null)
                                        {
                                            tNode = new TreeNode(NodeText, childNodes);
                                        }
                                    }
                                    tNode.Tag = pos;
                                    worker.ReportProgress(0, new ProgressReporter(tNode, i + ": " + xpni.Count + " Hit" + ss));
                                }
                            }
                        }
                        else
                        {
                            worker.ReportProgress(0, new ProgressReporter(i + ": " + xprt + ": " + strres));
                        }
                    }
                    i++;
                }
            }
            catch (Exception ex)
            {
                worker.ReportProgress(0, new ProgressReporter("An unexpected error has occured: " + ex.Message));
            }
        }
Beispiel #4
0
Datei: test.cs Projekt: mono/gert
		// Constructor that is used in the ResolveFunction method of the custom XsltContext class (CustomContext) 
		// to create and to return an instance of the IXsltContextFunction object to execute a specified 
		// user-defined XPath extension function at run time.
		public XPathStringExtensionFunctions (int p_minArgs, int p_maxArgs, XPathResultType p_ReturnType, XPathResultType[] p_ArgTypes, string p_FunctionName)
		{
			this.m_MinArgs = p_minArgs;
			this.m_MaxArgs = p_maxArgs;
			this.m_ReturnType = p_ReturnType;
			this.m_ArgTypes = p_ArgTypes;
			this.FunctionName = p_FunctionName;
		}