Exemple #1
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);
     }
 }
Exemple #2
0
 private String getString(VTDNav vn)
 {
     if (argCount() == 0)
     {
         try
         {
             if (vn.atTerminal)
             {
                 if (vn.getTokenType(vn.LN) == VTDNav.TOKEN_CDATA_VAL)
                 {
                     return(vn.toRawString(vn.LN));
                 }
                 return(vn.toString(vn.LN));
             }
             return(vn.toString(vn.getCurrentIndex()));
         }
         catch (NavException e)
         {
             return(null); // this will almost never occur
         }
     }
     else if (argCount() == 1)
     {
         return(argumentList.e.evalString(vn));
     }
     else
     {
         throw new System.ArgumentException("String()'s argument count is invalid");
     }
 }
Exemple #3
0
        /// <summary> Select all elements along the preceding axis as defined in XPath</summary>
        /// <param name="en">
        /// </param>
        protected internal void  selectElement_P(System.String en)
        {
            if (en == null)
            {
                throw new System.ArgumentException("element name can't be null");
            }
            //depth = vn.getCurrentDepth();
            iter_type = PRECEDING;
            ft        = true;
            name      = en;

            endIndex = vn.getCurrentIndex();
            for (int i = vn.context[0] + 1; i < vn.context.Length; i++)
            {
                contextCopy[i] = -1;
            }
            contextCopy = new int[vn.context.Length];
            vn.context.CopyTo(contextCopy, 0);
            contextCopy[0] = vn.rootIndex;
        }
Exemple #4
0
 protected internal void selectPrecedingNode()
 {
     ft          = true;
     depth       = vn.getCurrentDepth();
     contextCopy = (int[])vn.context.Clone();
     if (contextCopy[0] != -1)
     {
         for (int i = contextCopy[0] + 1; i < contextCopy.Length; i++)
         {
             contextCopy[i] = 0;
         }
     }//else{
     //   for (int i=1;i<contextCopy.length;i++){
     //	   contextCopy[i]=0;
     //	   }
     //}
     iter_type = PRECEDING_NODE;
     endIndex  = vn.getCurrentIndex();
 }
Exemple #5
0
 private System.String normalizeSpace(VTDNav vn)
 {
     if (argCount() == 0)
     {
         String s = null;
         try
         {
             if (vn.atTerminal)
             {
                 int ttype = vn.getTokenType(vn.LN);
                 if (ttype == VTDNav.TOKEN_CDATA_VAL)
                 {
                     s = vn.toRawString(vn.LN);
                 }
                 else if (ttype == VTDNav.TOKEN_ATTR_NAME ||
                          ttype == VTDNav.TOKEN_ATTR_NS)
                 {
                     s = vn.toString(vn.LN + 1);
                 }
                 else
                 {
                     s = vn.toString(vn.LN);
                 }
             }
             else
             {
                 s = vn.toString(vn.getCurrentIndex());
             }
             return(normalize(s));
         }
         catch (NavException e)
         {
             return(""); // this will almost never occur
         }
     }
     else if (argCount() == 1)
     {
         String s = argumentList.e.evalString(vn);
         return(normalize(s));
     }
     throw new System.ArgumentException("normalize-space()'s argument count is invalid");
     //return null;
 }
Exemple #6
0
        private String getName(VTDNav vn)
        {
            int a;

            if (argCount() == 0)
            {
                a = vn.getCurrentIndex();
                int type = vn.getTokenType(a);

                if ((type == VTDNav.TOKEN_STARTING_TAG ||
                     type == VTDNav.TOKEN_ATTR_NAME))
                {
                    try
                    {
                        return(vn.toString(a));
                    }
                    catch (Exception e)
                    {
                        return("");
                    }
                }
                else
                {
                    return("");
                }
            }
            else if (argCount() == 1)
            {
                a = -1;
                vn.push2();
                try
                {
                    a = argumentList.e.evalNodeSet(vn);
                    argumentList.e.reset(vn);
                    vn.pop2();
                }
                catch (Exception e)
                {
                    argumentList.e.reset(vn);
                    vn.pop2();
                }
                try
                {
                    if (a == -1 || vn.ns == false)
                    {
                        return("");
                    }
                    else
                    {
                        int type = vn.getTokenType(a);
                        if (type == VTDNav.TOKEN_STARTING_TAG ||
                            type == VTDNav.TOKEN_ATTR_NAME)
                        {
                            return(vn.toString(a));
                        }
                        return("");
                    }
                }
                catch (Exception e)
                {
                }
                return("");
            }
            else
            {
                throw new System.ArgumentException
                          ("name()'s argument count is invalid");
            }
        }
Exemple #7
0
        private String getLocalName(VTDNav vn)
        {
            if (argCount() == 0)
            {
                try
                {
                    int index = vn.getCurrentIndex();
                    int type  = vn.getTokenType(index);
                    if (vn.ns && (type == VTDNav.TOKEN_STARTING_TAG ||
                                  type == VTDNav.TOKEN_ATTR_NAME))
                    {
                        long offset = vn.getTokenOffset(index);
                        int  length = vn.getTokenLength(index);
                        if (length < 0x10000)
                        {
                            return(vn.toRawString(index));
                        }
                        else
                        {
                            int preLen = length >> 16;
                            int QLen   = length & 0xffff;
                            if (preLen != 0)
                            {
                                return(vn.toRawString(offset + preLen + 1, QLen
                                                      - preLen - 1));
                            }
                            else
                            {
                                return(vn.toRawString(offset, QLen));
                            }
                        }
                    }
                    else
                    {
                        return("");
                    }
                }
                catch (NavException e)
                {
                    return(""); // this will almost never occur
                }
            }
            else if (argCount() == 1)
            {
                int a = -1;
                vn.push2();
                try
                {
                    a = argumentList.e.evalNodeSet(vn);
                    argumentList.e.reset(vn);
                    vn.pop2();
                }
                catch (Exception e)
                {
                    argumentList.e.reset(vn);
                    vn.pop2();
                }

                if (a == -1 || vn.ns == false)
                {
                    return("");
                }
                int type = vn.getTokenType(a);
                if (type != VTDNav.TOKEN_STARTING_TAG && type != VTDNav.TOKEN_ATTR_NAME)
                {
                    return("");
                }
                try
                {
                    long offset = vn.getTokenOffset(a);
                    int  length = vn.getTokenLength(a);
                    if (length < 0x10000)
                    {
                        return(vn.toRawString(a));
                    }
                    else
                    {
                        int preLen = length >> 16;
                        int QLen   = length & 0xffff;
                        if (preLen != 0)
                        {
                            return(vn.toRawString(offset + preLen + 1,
                                                  QLen - preLen - 1));
                        }
                        else
                        {
                            return(vn.toRawString(offset, QLen));
                        }
                    }
                }
                catch (NavException e)
                {
                    return(""); // this will almost never occur
                }
            }
            else
            {
                throw new System.ArgumentException
                          ("local-name()'s argument count is invalid");
            }
        }
Exemple #8
0
        /// <summary>
        ///
        ///  This method set the cursor in VTDNav to the nodes as recorded
        ///  in NodeRecorder, and return the output of "getCurrentIndex()"
        ///  It is important to notice that you can only go forward, not
        ///  backward
        ///
        /// </summary>
        /// <returns> @return int</returns>
        public int iterate()
        {
            int j, i;

            if (count < fib.size_Renamed_Field)
            {
                i = fib.intAt(count);
                bool b = (i >= 0);
                if (b == false)
                {
                    i = i & 0x7fffffff;
                }
                switch (i)
                {
                case 0xff:
                    vn.context[0] = -1;
                    vn.atTerminal = false;
                    count++;
                    break;

                case 0:
                    vn.context[0] = 0;
                    if (b == false)
                    {
                        vn.atTerminal = true;
                        vn.LN         = fib.intAt(count + 1);
                        count        += 2;
                    }
                    else
                    {
                        vn.atTerminal = false;
                        count++;
                    }

                    break;

                case 1:
                    vn.context[0] = 1;
                    vn.context[1] = fib.intAt(count + 1);
                    vn.l1index    = fib.intAt(count + 2);
                    if (b == false)
                    {
                        vn.atTerminal = true;
                        vn.LN         = fib.intAt(count + 3);
                        count        += 4;
                    }
                    else
                    {
                        vn.atTerminal = false;
                        count        += 3;
                    }

                    break;

                case 2:
                    vn.context[0] = 2;
                    vn.context[1] = fib.intAt(count + 1);
                    vn.context[2] = fib.intAt(count + 2);
                    vn.l1index    = fib.intAt(count + 3);
                    vn.l2lower    = fib.intAt(count + 4);
                    vn.l2upper    = fib.intAt(count + 5);
                    vn.l2index    = fib.intAt(count + 6);
                    if (b == false)
                    {
                        vn.atTerminal = true;
                        vn.LN         = fib.intAt(count + 7);
                        count        += 8;
                    }
                    else
                    {
                        vn.atTerminal = false;
                        count        += 7;
                    }

                    break;

                case 3:
                    vn.context[0] = 3;
                    vn.context[1] = fib.intAt(count + 1);
                    vn.context[2] = fib.intAt(count + 2);
                    vn.context[3] = fib.intAt(count + 3);
                    vn.l1index    = fib.intAt(count + 4);
                    vn.l2lower    = fib.intAt(count + 5);
                    vn.l2upper    = fib.intAt(count + 6);
                    vn.l2index    = fib.intAt(count + 7);
                    vn.l3lower    = fib.intAt(count + 8);
                    vn.l3upper    = fib.intAt(count + 9);
                    vn.l3index    = fib.intAt(count + 10);
                    if (b == false)
                    {
                        vn.atTerminal = true;
                        vn.LN         = fib.intAt(count + 11);
                        count        += 12;
                    }
                    else
                    {
                        vn.atTerminal = false;
                        count        += 11;
                    }

                    break;

                default:
                    if (vn.shallowDepth)
                    {
                        // vn.context[0] = i;
                        for (j = 0; j < i; j++)
                        {
                            vn.context[j] = fib.intAt(count + j);
                        }
                        vn.l1index = fib.intAt(count + i);
                        vn.l2lower = fib.intAt(count + i + 1);
                        vn.l2upper = fib.intAt(count + i + 2);
                        vn.l2index = fib.intAt(count + i + 3);
                        vn.l3lower = fib.intAt(count + i + 4);
                        vn.l3upper = fib.intAt(count + i + 5);
                        vn.l3index = fib.intAt(count + i + 6);
                        if (b == false)
                        {
                            vn.atTerminal = true;
                            vn.LN         = fib.intAt(count + 11);
                            count        += i + 9;
                        }
                        else
                        {
                            vn.atTerminal = false;
                            count        += i + 8;
                        }
                        break;
                    }
                    else
                    {
                        VTDNav_L5 vnl = (VTDNav_L5)vn;
                        switch (i)
                        {
                        case 4:
                            vn.context[0] = 4;
                            vn.context[1] = fib.intAt(count + 1);
                            vn.context[2] = fib.intAt(count + 2);
                            vn.context[3] = fib.intAt(count + 3);
                            vn.context[4] = fib.intAt(count + 4);
                            vn.l1index    = fib.intAt(count + 5);
                            vn.l2lower    = fib.intAt(count + 6);
                            vn.l2upper    = fib.intAt(count + 7);
                            vn.l2index    = fib.intAt(count + 8);
                            vn.l3lower    = fib.intAt(count + 9);
                            vn.l3upper    = fib.intAt(count + 10);
                            vn.l3index    = fib.intAt(count + 11);
                            vnl.l4lower   = fib.intAt(count + 12);
                            vnl.l4upper   = fib.intAt(count + 13);
                            vnl.l4index   = fib.intAt(count + 14);
                            if (b == false)
                            {
                                vn.atTerminal = true;
                                vn.LN         = fib.intAt(count + 15);
                                count        += 16;
                            }
                            else
                            {
                                vn.atTerminal = false;
                                count        += 15;
                            }

                            break;

                        case 5:
                            vn.context[0] = 5;
                            vn.context[1] = fib.intAt(count + 1);
                            vn.context[2] = fib.intAt(count + 2);
                            vn.context[3] = fib.intAt(count + 3);
                            vn.context[4] = fib.intAt(count + 4);
                            vn.context[5] = fib.intAt(count + 5);
                            vn.l1index    = fib.intAt(count + 6);
                            vn.l2lower    = fib.intAt(count + 7);
                            vn.l2upper    = fib.intAt(count + 8);
                            vn.l2index    = fib.intAt(count + 9);
                            vn.l3lower    = fib.intAt(count + 10);
                            vn.l3upper    = fib.intAt(count + 11);
                            vn.l3index    = fib.intAt(count + 12);
                            vnl.l4lower   = fib.intAt(count + 13);
                            vnl.l4upper   = fib.intAt(count + 14);
                            vnl.l4index   = fib.intAt(count + 15);
                            vnl.l5lower   = fib.intAt(count + 16);
                            vnl.l5upper   = fib.intAt(count + 17);
                            vnl.l5index   = fib.intAt(count + 18);
                            if (b == false)
                            {
                                vn.atTerminal = true;
                                vn.LN         = fib.intAt(count + 19);
                                count        += 20;
                            }
                            else
                            {
                                vn.atTerminal = false;
                                count        += 19;
                            }

                            break;

                        default:
                            vn.context[0] = i;
                            for (j = 1; j < i; j++)
                            {
                                vn.context[j] = fib.intAt(count + j);
                            }
                            vn.l1index  = fib.intAt(count + i);
                            vn.l2lower  = fib.intAt(count + i + 1);
                            vn.l2upper  = fib.intAt(count + i + 2);
                            vn.l2index  = fib.intAt(count + i + 3);
                            vn.l3lower  = fib.intAt(count + i + 4);
                            vn.l3upper  = fib.intAt(count + i + 5);
                            vn.l3index  = fib.intAt(count + i + 6);
                            vnl.l4lower = fib.intAt(count + i + 7);
                            vnl.l4upper = fib.intAt(count + i + 8);
                            vnl.l4index = fib.intAt(count + i + 9);
                            vnl.l5lower = fib.intAt(count + i + 10);
                            vnl.l5upper = fib.intAt(count + i + 11);
                            vnl.l5index = fib.intAt(count + i + 12);
                            if (b == false)
                            {
                                vn.atTerminal = true;
                                vn.LN         = fib.intAt(count + i + 13);
                                count        += i + 15;
                            }
                            else
                            {
                                vn.atTerminal = false;
                                count        += i + 14;
                            }
                            break;
                        }
                    }
                    break;
                }
                position++;
                return(vn.getCurrentIndex());
            }
            return(-1);
        }
Exemple #9
0
        /// <summary>
        ///
        ///  This method set the cursor in VTDNav to the nodes as recorded
        ///  in NodeRecorder, and return the output of "getCurrentIndex()"
        ///  It is important to notice that you can only go forward, not
        ///  backward
        ///
        /// </summary>
        /// <returns> @return int</returns>
        public int iterate()
        {
            int j, i;

            if (count < fib.size())
            {
                i = fib.intAt(count);
                bool b = (i >= 0);
                if (b == false)
                {
                    i = i & 0x7fffffff;
                }
                switch (i)
                {
                case 0xff:
                    vn.context[0] = -1;
                    vn.atTerminal = false;
                    count++;
                    break;

                case 0:
                    vn.context[0] = 0;
                    if (b == false)
                    {
                        vn.atTerminal = true;
                        vn.LN         = fib.intAt(count + 1);
                        count        += 2;
                    }
                    else
                    {
                        vn.atTerminal = false;
                        count++;
                    }

                    break;

                case 1:
                    vn.context[0] = 1;
                    vn.context[1] = fib.intAt(count + 1);
                    vn.l1index    = fib.intAt(count + 2);
                    if (b == false)
                    {
                        vn.atTerminal = true;
                        vn.LN         = fib.intAt(count + 3);
                        count        += 4;
                    }
                    else
                    {
                        vn.atTerminal = false;
                        count        += 3;
                    }

                    break;

                case 2:
                    vn.context[0] = 2;
                    vn.context[1] = fib.intAt(count + 1);
                    vn.context[2] = fib.intAt(count + 2);
                    vn.l1index    = fib.intAt(count + 3);
                    vn.l2lower    = fib.intAt(count + 4);
                    vn.l2upper    = fib.intAt(count + 5);
                    vn.l2index    = fib.intAt(count + 6);
                    if (b == false)
                    {
                        vn.atTerminal = true;
                        vn.LN         = fib.intAt(count + 7);
                        count        += 8;
                    }
                    else
                    {
                        vn.atTerminal = false;
                        count        += 7;
                    }

                    break;

                case 3:
                    vn.context[0] = 3;
                    vn.context[1] = fib.intAt(count + 1);
                    vn.context[2] = fib.intAt(count + 2);
                    vn.context[3] = fib.intAt(count + 3);
                    vn.l1index    = fib.intAt(count + 4);
                    vn.l2lower    = fib.intAt(count + 5);
                    vn.l2upper    = fib.intAt(count + 6);
                    vn.l2index    = fib.intAt(count + 7);
                    vn.l3lower    = fib.intAt(count + 8);
                    vn.l3upper    = fib.intAt(count + 9);
                    vn.l3index    = fib.intAt(count + 10);
                    if (b == false)
                    {
                        vn.atTerminal = true;
                        vn.LN         = fib.intAt(count + 11);
                        count        += 12;
                    }
                    else
                    {
                        vn.atTerminal = false;
                        count        += 11;
                    }

                    break;

                default:
                    vn.context[0] = i;
                    for (j = 1; j < i; j++)
                    {
                        vn.context[j] = fib.intAt(count + j);
                    }
                    vn.l1index = fib.intAt(count + i);
                    vn.l2lower = fib.intAt(count + i + 1);
                    vn.l2upper = fib.intAt(count + i + 2);
                    vn.l2index = fib.intAt(count + i + 3);
                    vn.l3lower = fib.intAt(count + i + 4);
                    vn.l3upper = fib.intAt(count + i + 5);
                    vn.l3index = fib.intAt(count + i + 6);
                    if (b == false)
                    {
                        vn.atTerminal = true;
                        vn.LN         = fib.intAt(count + 11);
                        count        += i + 8;
                    }
                    else
                    {
                        vn.atTerminal = false;
                        count        += i + 7;
                    }
                    break;
                }
                position++;
                return(vn.getCurrentIndex());
            }
            return(-1);
        }