示例#1
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            string        xPath = txtXpath.Text;
            int           curentCursorPosition = 0;
            StringBuilder sb = null;

            RtfCreator.RtfCreator rtfCreator   = null;
            List <Point>          lstOddsItems = new List <Point>();
            bool isOddItem = false;

            //XPathNavigator navigator = _XPathDoc.CreateNavigator();

            if (XPathDoc == null)
            {
                MessageBox.Show("Insert document or load it from file before", "No seted document", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            XPathNavigator navigator = XPathDoc.CreateNavigator();

            XPathExpression expr = null;

            navigator.MoveToFirstChild();
            XPathNodeIterator nList = null;


            try
            {
                expr  = EvaluateXpathExpr(xPath, navigator);
                nList = navigator.Select(expr);
            }
            catch (XPathException ex)
            {
                MessageBox.Show(ex.Message, "Check your XPath", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            sb           = new StringBuilder(nList.Count);
            _tblRezXpath = new Dictionary <Point, string[]>(nList.Count);
            while (nList.MoveNext())
            {
                List <string> lstPath = new List <string>();
                int           xpi     = 0;
                //sbPath.Append("/" + nList.Current.Name + (xpi < 0 ? "" : string.Format("[{0}]",xpi)));

                if (nList.Current.NodeType == XPathNodeType.Attribute)
                {
                    lstPath.Add("@" + nList.Current.Name);
                }
                else
                {
                    xpi = GetXpathIndex(nList.Current);
                    lstPath.Add(nList.Current.Name + (xpi < 0 ? "" : string.Format("[{0}]", xpi)));
                }
                XPathNavigator nParent = nList.Current.Clone();
                while (nParent.MoveToParent() && nParent.NodeType != XPathNodeType.Root)
                {
                    xpi = GetXpathIndex(nParent);
                    //sbPath.Insert(0, "/" + nParent.Name + (xpi < 0 ? "" : string.Format("[{0}]",xpi)));
                    lstPath.Add("" + nParent.Name + (xpi < 0 ? "" : string.Format("[{0}]", xpi)));
                }
                _tblRezXpath.Add(new Point(curentCursorPosition, curentCursorPosition + nList.Current.InnerXml.Length + 0), lstPath.ToArray());
                if (isOddItem)
                {
                    lstOddsItems.Add(new Point(curentCursorPosition, nList.Current.InnerXml.Length));
                }
                isOddItem             = !isOddItem;
                curentCursorPosition += nList.Current.InnerXml.Length + 1;

                sb.AppendFormat("{0}\n", nList.Current.InnerXml);
                //sb.AppendFormat(RtfCreator.RtfCreator.
            }
            txtRezult.Clear();
            //txtRezult.Text = sb.ToString();
            rtfCreator = new RtfCreator.RtfCreator(sb.ToString());
            for (int i = 0; i < lstOddsItems.Count; i++)
            {
                rtfCreator.MarkText(RtfCreator.RtfCreator.MarkType.BackGround, "Even", lstOddsItems[i].X, lstOddsItems[i].Y);
            }

            txtRezult.Rtf = rtfCreator.Rtf;

            ////

            MyAutoCompleteSource.AddItemToCollection(navigator.Name, txtXpath.Text);
            //txtXpath.AutoCompleteCustomSource = MyAutoCompleteSource.GetSource(navigator.Name); now using event Updated of MyAutoCompleteSource
            ////
        }
示例#2
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     MyAutoCompleteSource.Save();
 }
示例#3
0
 void MyAutoCompleteSource_Updated(object sender, MyAutocompleteItemEventHandlerArg e)
 {
     txtXpath.AutoCompleteCustomSource = MyAutoCompleteSource.GetSource(e.GroupName);
 }