예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="vn"></param>
        /// <returns></returns>
        protected int getStringIndex(VTDNav vn)
        {
            int a = -1;

            vn.push2();
            int size = vn.contextStack2.size;

            try
            {
                a = evalNodeSet(vn);
                if (a != -1)
                {
                    int t = vn.getTokenType(a);
                    if (t == VTDNav.TOKEN_ATTR_NAME)
                    {
                        a++;
                    }
                    else if (vn.getTokenType(a) == VTDNav.TOKEN_STARTING_TAG)
                    {
                        a = vn.getText();
                    }
                    else if (t == VTDNav.TOKEN_PI_NAME)
                    {
                        a++;
                    }
                }
            }
            catch (Exception e)
            {
            }
            vn.contextStack2.size = size;
            reset(vn);
            vn.pop2();
            return(a);
        }
예제 #2
0
 static void Main(string[] args)
 {
     try
     {
         // open a file and read the content into a byte array
         VTDGen vg = new VTDGen();
         if (vg.parseFile("./servers.xml", true))
         {
             VTDNav    vn = vg.getNav();
             AutoPilot ap = new AutoPilot(vn);
             ap.selectElementNS("http://purl.org/dc/elements/1.1/", "*"); // select name space here; * matches any local name
             int count = 0;
             while (ap.iterate())
             {
                 Console.Write("" + vn.getCurrentIndex() + "  ");
                 Console.WriteLine("Element name ==> " + vn.toString(vn.getCurrentIndex()));
                 int t = vn.getText(); // get the index of the text (char data or CDATA)
                 if (t != -1)
                 {
                     Console.WriteLine(" Text  ==> " + vn.toNormalizedString(t));
                 }
                 Console.WriteLine("\n ============================== ");
                 count++;
             }
             Console.WriteLine("Total # of element " + count);
         }
     }
     catch (NavException e)
     {
         Console.WriteLine(" Exception during navigation " + e);
     }
 }
예제 #3
0
        static void Main(string[] args)
        {
            VTDGen vg = new VTDGen();
            int i;
            AutoPilot ap = new AutoPilot();
            ap.selectXPath("/CATALOG/CD[PRICE < 10]");
            BookMark bm = new BookMark();
            if (vg.parseFile("cd.xml", false))
            {
                VTDNav vn = vg.getNav();
                bm.bind(vn);
                ap.bind(vn);

                //XPath eval returns one node at a time
                while ((i = ap.evalXPath()) != -1)
                {
                    // push the current cursor position
                    //vn.push();
                    bm.recordCursorPosition(); // equivalent to vn.push();
                    // get to the first child
                    if (vn.toElement(VTDNav.FIRST_CHILD, "TITLE"))
                    {
                        int j = vn.getText();
                        if (j != -1)
                            Console.WriteLine(" text node ==>" + vn.toString(j));
                    }
                    // restore the cursor position
                    //vn.pop(); 
                    bm.setCursorPosition(); // equivalent to vn.pop();
                }
                ap.resetXPath();
            }
        }
예제 #4
0
        private double sum(VTDNav vn)
        {
            int d = 0;

            if (argCount() != 1 || argumentList.e.NodeSet == false)
            {
                throw new System.ArgumentException("sum()'s argument count is invalid");
            }
            vn.push2();
            try
            {
                a = 0;
                int i1;
                while ((a = argumentList.e.evalNodeSet(vn)) != -1)
                {
                    int t = vn.getTokenType(a);
                    if (t == VTDNav.TOKEN_STARTING_TAG)
                    {
                        i1 = vn.getText();
                        if (i1 != -1)
                        {
                            d = (int)(d + vn.parseDouble(i1));
                        }
                        if (System.Double.IsNaN(d))
                        {
                            break;
                        }
                    }
                    else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS)
                    {
                        d = (int)(d + vn.parseDouble(a + 1));
                        if (System.Double.IsNaN(d))
                        {
                            break;
                        }
                    }
                    else if (t == VTDNav.TOKEN_CHARACTER_DATA || t == VTDNav.TOKEN_CDATA_VAL)
                    {
                        d = (int)(d + vn.parseDouble(a));
                        if (System.Double.IsNaN(d))
                        {
                            break;
                        }
                    }
                    //    fib1.append(i);
                }
                argumentList.e.reset(vn);
                vn.pop2();
                return(d);
            }
            catch (System.Exception e)
            {
                argumentList.e.reset(vn);
                vn.pop2();
                return(System.Double.NaN);
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            VTDGen vg = new VTDGen();

            vg.setDoc(getBytes("<root>good</root>"));
            vg.parse(true);
            VTDNav vn = vg.getNav();
            int    i  = vn.getText();

            //print "good"
            Console.WriteLine("text ---> " + vn.toString(i));
            if (vn.overWrite(i, getBytes("bad")))
            {
                //overwrite, if successful, returns true
                //print "bad" here
                Console.WriteLine("text ---> " + vn.toString(i));
            }
        }
예제 #6
0
        /*
         * (non-Javadoc)
         *
         * @see com.ximpleware.xpath.Expr#evalString(com.ximpleware.VTDNav)
         */
        public override System.String evalString(VTDNav vn)
        {
            if (e.String)
            {
                return(e.evalString(vn));
            }

            vn.push2();
            int size = vn.contextStack2.size;
            int a    = -1;

            try
            {
                a = evalNodeSet(vn);
                if (a != -1)
                {
                    if (vn.getTokenType(a) == VTDNav.TOKEN_ATTR_NAME)
                    {
                        a++;
                    }
                    if (vn.getTokenType(a) == VTDNav.TOKEN_STARTING_TAG)
                    {
                        a = vn.getText();
                    }
                }
            }
            catch (System.Exception ee)
            {
            }
            vn.contextStack2.size = size;
            reset(vn);
            vn.pop2();
            try
            {
                if (a != -1)
                {
                    return(vn.toString(a));
                }
            }
            catch (NavException ee)
            {
            }
            return("");
        }
예제 #7
0
        /*
         * (non-Javadoc)
         *
         * @see com.ximpleware.xpath.Expr#evalNumber(com.ximpleware.VTDNav)
         */
        public override double evalNumber(VTDNav vn)
        {
            if (e.Numerical)
            {
                return(e.evalNumber(vn));
            }
            int a = -1;

            vn.push2();
            int size = vn.contextStack2.size;

            try
            {
                a = evalNodeSet(vn);
                if (a != -1)
                {
                    if (vn.getTokenType(a) == VTDNav.TOKEN_ATTR_NAME)
                    {
                        a++;
                    }
                    else if (vn.getTokenType(a) == VTDNav.TOKEN_STARTING_TAG)
                    {
                        a = vn.getText();
                    }
                }
            }
            catch (System.Exception ee)
            {
            }
            vn.contextStack2.size = size;
            reset(vn);
            vn.pop2();
            try
            {
                if (a != -1)
                {
                    return(vn.parseDouble(a));
                }
            }
            catch (NavException ee)
            {
            }
            return(System.Double.NaN);
        }
예제 #8
0
        private int getStringVal(VTDNav vn, int i)
        {
            int i1, t = vn.getTokenType(i);

            if (t == VTDNav.TOKEN_STARTING_TAG)
            {
                i1 = vn.getText();
                return(i1);
            }
            else if (t == VTDNav.TOKEN_ATTR_NAME ||
                     t == VTDNav.TOKEN_ATTR_NS || t == VTDNav.TOKEN_PI_NAME)
            {
                return(i + 1);
            }
            else /*if (t == VTDNav.TOKEN_CHARACTER_DATA
                 || t == VTDNav.TOKEN_CDATA_VAL)
                 || return i;*/
            {
                return(i);
            }
        }
예제 #9
0
        public override double evalNumber(VTDNav vn)
        {
            int ac = 0;

            switch (opCode)
            {
            case FuncName.LAST:  if (argCount() != 0)
                {
                    throw new System.ArgumentException("floor()'s argument count is invalid");
                }
                return(contextSize);

            case FuncName.POSITION:  if (argCount() != 0)
                {
                    throw new System.ArgumentException("position()'s argument count is invalid");
                }
                return(position);

            case FuncName.COUNT:  return(count(vn));

            case FuncName.NUMBER:  if (argCount() != 1)
                {
                    throw new System.ArgumentException("number()'s argument count is invalid");
                }
                return(argumentList.e.evalNumber(vn));


            case FuncName.SUM:  return(sum(vn));

            case FuncName.FLOOR:  if (argCount() != 1)
                {
                    throw new System.ArgumentException("floor()'s argument count is invalid");
                }
                return(System.Math.Floor(argumentList.e.evalNumber(vn)));


            case FuncName.CEILING:  if (argCount() != 1)
                {
                    throw new System.ArgumentException("ceiling()'s argument count is invalid");
                }
                return(System.Math.Ceiling(argumentList.e.evalNumber(vn)));


            case FuncName.STRING_LENGTH:
                ac = argCount();
                if (ac == 0)
                {
                    try
                    {
                        if (vn.atTerminal == true)
                        {
                            int type = vn.getTokenType(vn.LN);
                            if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS)
                            {
                                return(vn.getStringLength(vn.LN + 1));
                            }
                            else
                            {
                                return(vn.getStringLength(vn.LN));
                            }
                        }
                        else
                        {
                            int i = vn.getText();
                            if (i == -1)
                            {
                                return(0);
                            }
                            else
                            {
                                return(vn.getStringLength(i));
                            }
                        }
                    }
                    catch (NavException e)
                    {
                        return(0);
                    }
                }
                else if (ac == 1)
                {
                    return(argumentList.e.evalString(vn).Length);
                }
                else
                {
                    throw new System.ArgumentException("string-length()'s argument count is invalid");
                }
            //goto case FuncName.ROUND;


            case FuncName.ROUND:  if (argCount() != 1)
                {
                    throw new System.ArgumentException("round()'s argument count is invalid");
                }
                //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangMathround_double'"
                return((long)System.Math.Round(argumentList.e.evalNumber(vn)));


            default:  if (isBoolean_Renamed_Field)
                {
                    if (evalBoolean(vn))
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(System.Double.Parse(evalString(vn)));
                }
                //break;
            }
        }