Beispiel #1
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();
            }
        }
Beispiel #2
0
        public static void Main(String[] args)
        {
            // instantiate VTDGen and XMLModifier
            VTDGen      vg  = new VTDGen();
            XMLModifier xm  = new XMLModifier();
            AutoPilot   ap  = new AutoPilot();
            AutoPilot   ap2 = new AutoPilot();

            ap.selectXPath("(/*/*/*)[position()>1 and position()<4]");
            ap2.selectXPath("/*/*/*");
            if (vg.parseFile("soap2.xml", true))
            {
                VTDNav vn = vg.getNav();
                xm.bind(vn);
                ap2.bind(vn);
                ap.bind(vn);
                ap2.evalXPath();
                ElementFragmentNs ef = vn.getElementFragmentNs();
                int i = -1;
                while ((i = ap.evalXPath()) != -1)
                {
                    xm.insertAfterElement(ef);
                }
                xm.output("new_soap.xml");
            }
        }
Beispiel #3
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);
     }
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            VTDGen vg = new VTDGen();
            int    i;

            if (vg.parseFile("po.xml", true))
            {
                // instantiate a node recorder here
                NodeRecorder nr = new NodeRecorder();
                AutoPilot    ap = new AutoPilot();
                VTDNav       vn = vg.getNav();
                ap.bind(vn);
                // bind node recorder to vn
                nr.bind(vn);
                ap.selectXPath("(/*/*/*)[position()=1 or position()=10]");
                while ((i = ap.evalXPath()) != -1)
                {
                    nr.record();   // save the selected nodes into nr
                }
                ap.resetXPath();   // a good practice
                nr.resetPointer(); // get into nr's read mode
                // iterating over the nodes recorded by nr
                while ((i = nr.iterate()) != -1)
                {
                    Console.WriteLine("string ==>" + vn.toString(i));
                }

                nr.clear(); //remove all the nodes in nr, buffer is however reused
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            VTDGen    vg = new VTDGen();
            AutoPilot ap = new AutoPilot();
            Encoding  eg = System.Text.Encoding.GetEncoding("utf-8");
            //ap.selectXPath("/*/*/*");
            AutoPilot ap2 = new AutoPilot();

            ap2.selectXPath("//@*");
            if (vg.parseFile("soap2.xml", true))
            {
                FileStream fs = new FileStream("output.xml", System.IO.FileMode.OpenOrCreate);
                VTDNav     vn = vg.getNav();
                ap.bind(vn);
                ap2.bind(vn);
                //ap.evalXPath();
                int i;
                while ((i = ap2.evalXPath()) != -1)
                {
                    //System.out.println("attr name ---> "+ i+ " "+vn.toString(i)+"  value ---> "+vn.toString(i+1));
                    vn.overWrite(i + 1, eg.GetBytes(""));
                }
                byte[] ba = vn.getXML().getBytes();
                fs.Write(ba, 0, ba.Length);
                fs.Close();
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            try
            {
                // open file to output extracted fragments
                System.IO.FileInfo   f1  = new System.IO.FileInfo("./out.txt");
                System.IO.FileStream fos = new System.IO.FileStream(f1.FullName, System.IO.FileMode.Create);

                // instantiate the parser
                VTDGen vg = new VTDGen();
                vg.selectLcDepth(5);
                if (vg.parseFile("./soap2.xml", true))
                {
                    VTDNav vn = vg.getNav();
                    // get to the SOAP header
                    if (vn.toElementNS(VTDNav.FC, "http://www.w3.org/2003/05/soap-envelope", "Header"))
                    {
                        if (vn.toElement(VTDNav.FC))
                        // to first child
                        {
                            do
                            {
                                // test MUSTHAVE
                                if (vn.hasAttrNS("http://www.w3.org/2003/05/soap-envelope", "mustUnderstand"))
                                {
                                    long   l      = vn.getElementFragment();
                                    int    len    = (int)(l >> 32);
                                    int    offset = (int)l;
                                    byte[] b      = vn.getXML().getBytes();
                                    fos.Write(b, offset, len); //write the fragment out into out.txt
                                    System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("ASCII");
                                    byte[] bytes = encoder.GetBytes("\n=========\n");

                                    fos.Write(bytes, 0, bytes.Length);
                                }
                            }while (vn.toElement(VTDNav.NS)); // navigate next sibling
                        }
                        else
                        {
                            System.Console.Out.WriteLine("Header has not child elements");
                        }
                    }
                    else
                    {
                        System.Console.Out.WriteLine(" Dosesn't have a header");
                    }

                    fos.Close();
                }
            }
            catch (NavException e)
            {
                System.Console.Out.WriteLine(" Exception during navigation " + e);
            }
            catch (System.IO.IOException e)
            {
                System.Console.Out.WriteLine(" IO exception condition" + e);
            }
        }
Beispiel #7
0
        public static void Main(String[] args)
        {
            VTDGen    vg  = new VTDGen();
            AutoPilot ap0 = new AutoPilot();
            AutoPilot ap1 = new AutoPilot();
            AutoPilot ap2 = new AutoPilot();

            ap0.selectXPath("/root/a");
            ap1.selectXPath("/root/b");
            ap2.selectXPath("/root/c");
            Encoding eg = System.Text.Encoding.GetEncoding("utf-8");

            if (vg.parseFile("old.xml", false))
            {
                VTDNav vn = vg.getNav();
                ap0.bind(vn);
                ap1.bind(vn);
                ap2.bind(vn);
                FileStream fos = new FileStream("new.xml", System.IO.FileMode.OpenOrCreate);
                //fos.Write("<root>".getBytes());
                byte[] ba0, ba1, ba2, ba3, ba4;
                //ba0 = eg.GetBytes("
                ba1 = eg.GetBytes("<root>");
                ba2 = eg.GetBytes("</root>");
                ba3 = eg.GetBytes("\n");
                fos.Write(ba1, 0, ba1.Length);
                byte[] ba = vn.getXML().getBytes();
                while (ap0.evalXPath() != -1)
                {
                    long l      = vn.getElementFragment();
                    int  offset = (int)l;
                    int  len    = (int)(l >> 32);
                    fos.Write(ba3, 0, ba3.Length);
                    fos.Write(ba, offset, len);
                }
                ap0.resetXPath();
                while (ap1.evalXPath() != -1)
                {
                    long l      = vn.getElementFragment();
                    int  offset = (int)l;
                    int  len    = (int)(l >> 32);
                    fos.Write(ba3, 0, ba3.Length);
                    fos.Write(ba, offset, len);
                }
                ap1.resetXPath();
                while (ap2.evalXPath() != -1)
                {
                    long l      = vn.getElementFragment();
                    int  offset = (int)l;
                    int  len    = (int)(l >> 32);
                    fos.Write(ba3, 0, ba3.Length);
                    fos.Write(ba, offset, len);
                }
                ap2.resetXPath();
                fos.Write(ba3, 0, ba3.Length);
                fos.Write(ba2, 0, ba2.Length);
            }
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            try
            {
                //File f = new File("bioinfo.xml");
                // counting child elements of parlist
                int count = 0;
                // counting child elements of parlist named "par"
                int    par_count = 0;
                VTDGen vg        = new VTDGen();
                if (vg.parseFile("./bioinfo.xml", true))
                {
                    VTDNav    vn = vg.getNav();
                    AutoPilot ap = new AutoPilot();
                    ap.bind(vn);
                    ap.selectXPath("/bix/package/command/parlist");
                    while (ap.evalXPath() != -1)
                    {
                        count++;
                    }

                    ap.selectXPath("/bix/package/command/parlist/par");
                    while (ap.evalXPath() != -1)
                    {
                        par_count++;
                    }

                    // print out the results
                    Console.WriteLine(" count ====> " + count);
                    Console.WriteLine(" par_count ==> " + par_count);

                    // verify results using iterators
                    int v = 0;
                    vn.toElement(VTDNav.ROOT);
                    ap = new AutoPilot(vn);
                    ap.selectElement("par");
                    while (ap.iterate())
                    {
                        if (vn.getCurrentDepth() == 4)
                        {
                            v++;
                        }
                    }
                    Console.WriteLine(" verify ==> " + v);
                }
            }
            catch (NavException e)
            {
                Console.WriteLine(" Exception during navigation " + e);
            }
            catch (XPathParseException e)
            {
            }
            catch (XPathEvalException e)
            {
            }
        }
Beispiel #9
0
        public static VTDNav parseString(String s)
        {
            VTDGen vg = new VTDGen();

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

            vg.setDoc(encoding.GetBytes(s));

            vg.parse(true);

            return(vg.getNav());
        }
Beispiel #10
0
 static void Main(string[] args)
 {
     try
     {
         VTDGen vg = new VTDGen();
         if (vg.parseFile("po.xml", true))
         {
             vg.writeIndex("po.vxl");
         }
     }
     catch (Exception e)
     {
     }
 }
Beispiel #11
0
        static void Main(string[] args)
        {
            try
            {
                // open file to output extracted fragments
                System.IO.FileInfo   f1  = new System.IO.FileInfo("./out.txt");
                System.IO.FileStream fos = new System.IO.FileStream(f1.FullName, System.IO.FileMode.Create);

                // instantiate the parser
                VTDGen vg = new VTDGen();
                vg.selectLcDepth(5);
                if (vg.parseFile("./soap2.xml", true))
                {
                    VTDNav vn = vg.getNav();
                    // get to the SOAP header
                    AutoPilot ap = new AutoPilot();
                    ap.bind(vn);
                    ap.declareXPathNameSpace("ns1", "http://www.w3.org/2003/05/soap-envelope");
                    // get to the SOAP header
                    ap.selectXPath("/ns1:Envelope/ns1:Header/*[@ns1:mustUnderstand]");
                    Console.WriteLine("expr string is " + ap.getExprString());
                    while (ap.evalXPath() != -1)
                    {
                        long   l      = vn.getElementFragment();
                        int    len    = (int)(l >> 32);
                        int    offset = (int)l;
                        byte[] b      = vn.getXML().getBytes();
                        fos.Write(b, offset, len); //write the fragment out into out.txt
                        System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("ASCII");
                        byte[] bytes = encoder.GetBytes("\n=========\n");

                        fos.Write(bytes, 0, bytes.Length);
                    }

                    fos.Close();
                }
            }
            catch (NavException e)
            {
                System.Console.Out.WriteLine(" Exception during navigation " + e);
            }
            catch (System.IO.IOException e)
            {
                System.Console.Out.WriteLine(" IO exception condition" + e);
            }
        }
Beispiel #12
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));
            }
        }
Beispiel #13
0
 static void Main(string[] args)
 {
     try
     {
         VTDGen    vg = new VTDGen();
         VTDNav    vn = vg.loadIndex("po.vxl");
         AutoPilot ap = new AutoPilot(vn);
         ap.selectXPath("//items");
         int i;
         while ((i = ap.evalXPath()) != -1)
         {
         }
         ap.resetXPath();
     }
     catch (Exception e)
     {
     }
 }
Beispiel #14
0
        static void Main(string[] args)
        {
            VTDGen vg = new VTDGen();

            if (vg.parseFile("mix3.xml", true))
            {
                VTDNav vn = vg.getNav();
                // duplicated VTDNav instances share the same XML, LC buffers and VTD buffers.
                VTDNav    vn2 = vn.duplicateNav();
                VTDNav    vn3 = vn.duplicateNav();
                AutoPilot ap  = new AutoPilot(vn);
                ap.selectXPath("//*");
                int i;
                while ((i = ap.evalXPath()) != -1)
                {
                    Console.WriteLine("element name: " + vn.toString(i));
                }
            }
        }
Beispiel #15
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("./oldpo.xml", true))
         {
             VTDNav vn = vg.getNav();
             System.IO.FileInfo f1 = new System.IO.FileInfo("./newpo.txt");
             System.IO.FileStream fos = new System.IO.FileStream(f1.FullName, System.IO.FileMode.Create);
             
             AutoPilot ap = new AutoPilot(vn);
             XMLModifier xm = new XMLModifier(vn);
             ap.selectXPath("/purchaseOrder/items/item[@partNum='872-AA']");
             int i = -1;
             while ((i = ap.evalXPath()) != -1)
             {
                 xm.remove();
                 xm.insertBeforeElement("<something/>\n");
             }
             ap.selectXPath("/purchaseOrder/items/item/USPrice[.<40]/text()");
             while ((i = ap.evalXPath()) != -1)
             {
                 xm.updateToken(i, "200");
             }
             xm.output(fos);
             fos.Close();
         }
     }
     catch (NavException e)
     {
         Console.WriteLine(" Exception during navigation " + e);
     }
     catch (ModifyException e)
     {
         Console.WriteLine(" Modify exception occurred " + e);
     }
     catch (System.IO.IOException e)
     {
         System.Console.Out.WriteLine(" IO exception condition" + e);
     }
 }
Beispiel #16
0
        static void Main(string[] args)
        {
            VTDGen vg = new VTDGen();

            if (vg.parseFile("mix3.xml", true))
            {
                vg.writeSeparateIndex("mix32.vtd");
            }
            VTDNav    vn = vg.loadSeparateIndex("mix3.xml", "mix3.vtd");
            AutoPilot ap = new AutoPilot(vn);

            ap.selectXPath("//*");
            int i;

            while ((i = ap.evalXPath()) != -1)
            {
                Console.WriteLine("element name: " + vn.toString(i));
            }
        }
Beispiel #17
0
        public static void Main(String[] args)
        {
            String   xml = "<aaaa> <bbbbb> <ccccc> </ccccc> <ccccc/> <ccccc></ccccc> </bbbbb> </aaaa>";
            Encoding eg  = Encoding.GetEncoding("utf-8");
            VTDGen   vg  = new VTDGen();

            vg.setDoc(eg.GetBytes(xml));
            vg.parse(false);
            VTDNav    vn = vg.getNav();
            AutoPilot ap = new AutoPilot(vn);

            ap.selectXPath("//*");
            XMLModifier xm = new XMLModifier(vn);

            while (ap.evalXPath() != -1)
            {
                xm.updateElementName("d:/lalalala");
            }
            xm.output("lala.xml");
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            try
            {
                // counting child elements of parlist
                int count = 0;
                // counting child elements of parlist named "par"
                int par_count = 0;

                VTDGen vg = new VTDGen();
                if (vg.parseFile("./bioinfo.xml", true))
                {
                    VTDNav vn = vg.getNav();
                    if (vn.matchElement("bix"))
                    { // match blix
                        // to first child named "package"
                        if (vn.toElement(VTDNav.FC, "package"))
                        {
                            do
                            {
                                Console.WriteLine("package");
                                // to first child named "command"
                                if (vn.toElement(VTDNav.FC, "command"))
                                {
                                    do
                                    {
                                        Console.WriteLine("command");
                                        if (vn.toElement(VTDNav.FC, "parlist"))
                                        {
                                            do
                                            {
                                                Console.WriteLine("parlist");
                                                count++; //increment count
                                                if (vn.toElement(VTDNav.FC))
                                                {
                                                    do
                                                    {
                                                        if (vn.matchElement("par"))
                                                        {
                                                            par_count++;
                                                        }
                                                    }while (vn.toElement(VTDNav.NS));
                                                    vn.toElement(VTDNav.P);
                                                }
                                            }while (vn.toElement(VTDNav.NS, "parlist"));
                                            vn.toElement(VTDNav.P);
                                        }
                                    }
                                    // to next silbing named "command"
                                    while (vn.toElement(VTDNav.NS, "command"));
                                    vn.toElement(VTDNav.P); // go up one level
                                }
                                else
                                {
                                    Console.WriteLine(" no child element named 'command' ");
                                }
                                // verify result
                            }while (vn.toElement(VTDNav.NS, "package")); // to next sibling named "package"
                            vn.toElement(VTDNav.P);                      // go up one level
                        }
                        else
                        {
                            Console.WriteLine(" no child element named 'package' ");
                        }
                    }
                    else
                    {
                        Console.WriteLine(" Root is not 'bix' ");
                    }
                    // print out the results
                    Console.WriteLine(" count ====> " + count);
                    Console.WriteLine(" par_count ==> " + par_count);

                    // verify results using iterators
                    int v = 0;
                    vn.toElement(VTDNav.ROOT);
                    AutoPilot ap = new AutoPilot(vn);
                    ap.selectElement("par");
                    while (ap.iterate())
                    {
                        if (vn.getCurrentDepth() == 4)
                        {
                            v++;
                        }
                    }
                    Console.WriteLine(" verify ==> " + v);
                }
            }
            catch (NavException e)
            {
                Console.WriteLine(" Exception during navigation " + e);
            }
        }
Beispiel #19
0
        public static void readSeparateIndex(System.IO.Stream index, System.IO.Stream XMLBytes, int XMLSize, VTDGen vg)
        {
            if (index == null || vg == null || XMLBytes == null)
            {
                throw new System.ArgumentException("Invalid argument(s) for readIndex()");
            }
            //UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader'
            //which has a different behavior.
            //"ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
            System.IO.BinaryReader dis = new System.IO.BinaryReader(index);
            byte b = dis.ReadByte(); // first byte

            // no check on version number for now
            // second byte
            vg.encoding = dis.ReadByte();
            int intLongSwitch;
            int endian;

            // third byte
            b = dis.ReadByte();
            if ((b & 0x80) != 0)
            {
                intLongSwitch = 1;
            }
            //use ints
            else
            {
                intLongSwitch = 0;
            }
            if ((b & 0x40) != 0)
            {
                vg.ns = true;
            }
            else
            {
                vg.ns = false;
            }
            if ((b & 0x20) != 0)
            {
                endian = 1;
            }
            else
            {
                endian = 0;
            }
            if ((b & 0x1f) != 0)
            {
                throw new IndexReadException("Last 5 bits of the third byte should be zero");
            }

            // fourth byte
            vg.VTDDepth = dis.ReadByte();

            // 5th and 6th byte
            int LCLevel = (((int)dis.ReadByte()) << 8) | dis.ReadByte();

            if (LCLevel != 4 && LCLevel != 6)
            {
                throw new IndexReadException("LC levels must be at least 3");
            }
            // 7th and 8th byte
            vg.rootIndex = (((int)dis.ReadByte()) << 8) | dis.ReadByte();

            // skip a long
            dis.ReadInt64();
            //Console.WriteLine(" l ==>" + l);
            dis.ReadInt64();
            //Console.WriteLine(" l ==>" + l);
            long l = dis.ReadInt64();

            int size;

            // read XML size
            if (BitConverter.IsLittleEndian && endian == 0 ||
                BitConverter.IsLittleEndian == false && endian == 1)
            {
                size = (int)l;
            }
            else
            {
                size = (int)reverseLong(l);
            }


            // read XML bytes
            byte[] XMLDoc = new byte[size];
            XMLBytes.Read(XMLDoc, 0, size);

            //dis.Read(XMLDoc, 0, size);

            /*if ((size & 0x7) != 0)
             * {
             *  int t = (((size >> 3) + 1) << 3) - size;
             *  while (t > 0)
             *  {
             *      dis.ReadByte();
             *      t--;
             *  }
             * }*/

            vg.setDoc(XMLDoc);
            // skip a long
            dis.ReadInt64();
            //Console.WriteLine(" l ==>" + l);
            dis.ReadInt64();
            //Console.WriteLine(" l ==>" + l);
            if (BitConverter.IsLittleEndian && endian == 0 ||
                BitConverter.IsLittleEndian == false && endian == 1)
            {
                // read vtd records
                int vtdSize = (int)dis.ReadInt64();
                while (vtdSize > 0)
                {
                    vg.VTDBuffer.append(dis.ReadInt64());
                    vtdSize--;
                }
                // read L1 LC records
                int l1Size = (int)dis.ReadInt64();
                while (l1Size > 0)
                {
                    vg.l1Buffer.append(dis.ReadInt64());
                    l1Size--;
                }
                // read L2 LC records
                int l2Size = (int)dis.ReadInt64();
                while (l2Size > 0)
                {
                    vg.l2Buffer.append(dis.ReadInt64());
                    l2Size--;
                }
                // read L3 LC records
                int l3Size = (int)dis.ReadInt64();
                if (vg.shallowDepth)
                {
                    if (intLongSwitch == 1)
                    {
                        //l3 uses ints
                        while (l3Size > 0)
                        {
                            vg.l3Buffer.append(dis.ReadInt32());
                            l3Size--;
                        }
                    }
                    else
                    {
                        while (l3Size > 0)
                        {
                            vg.l3Buffer.append((int)(dis.ReadInt64() >> 32));
                            l3Size--;
                        }
                    }
                }
                else
                {
                    while (l3Size > 0)
                    {
                        vg._l3Buffer.append(dis.ReadInt64());
                        l3Size--;
                    }

                    int l4Size = (int)dis.ReadInt64();
                    while (l4Size > 0)
                    {
                        vg._l4Buffer.append(dis.ReadInt64());
                        l4Size--;
                    }

                    int l5Size = (int)dis.ReadInt64();
                    if (intLongSwitch == 1)
                    {
                        while (l5Size > 0)
                        {
                            vg._l5Buffer.append(dis.ReadInt32());
                            l5Size--;
                        }
                    }
                    else
                    {
                        while (l5Size > 0)
                        {
                            vg._l5Buffer.append((int)(dis.ReadInt64() >> 32));
                            l5Size--;
                        }
                    }
                }
            }
            else
            {
                // read vtd records
                int vtdSize = (int)reverseLong(dis.ReadInt64());
                while (vtdSize > 0)
                {
                    vg.VTDBuffer.append(reverseLong(dis.ReadInt64()));
                    vtdSize--;
                }
                // read L1 LC records
                int l1Size = (int)reverseLong(dis.ReadInt64());
                while (l1Size > 0)
                {
                    vg.l1Buffer.append(reverseLong(dis.ReadInt64()));
                    l1Size--;
                }
                // read L2 LC records
                int l2Size = (int)reverseLong(dis.ReadInt64());
                while (l2Size > 0)
                {
                    vg.l2Buffer.append(reverseLong(dis.ReadInt64()));
                    l2Size--;
                }
                // read L3 LC records
                int l3Size = (int)reverseLong(dis.ReadInt64());
                if (vg.shallowDepth)
                {
                    if (intLongSwitch == 1)
                    {
                        //l3 uses ints
                        while (l3Size > 0)
                        {
                            vg.l3Buffer.append(reverseInt(dis.ReadInt32()));
                            l3Size--;
                        }
                    }
                    else
                    {
                        while (l3Size > 0)
                        {
                            vg.l3Buffer.append(reverseInt((int)(dis.ReadInt64() >> 32)));
                            l3Size--;
                        }
                    }
                }
                else
                {
                    while (l3Size > 0)
                    {
                        vg._l3Buffer.append(reverseLong(dis.ReadInt64()));
                        l3Size--;
                    }

                    int l4Size = (int)reverseLong(dis.ReadInt64());
                    {
                        vg._l4Buffer.append(reverseLong(dis.ReadInt64()));
                        l4Size--;
                    }

                    int l5Size = (int)reverseLong(dis.ReadInt64());
                    if (intLongSwitch == 1)
                    {
                        //l3 uses ints
                        while (l5Size > 0)
                        {
                            vg._l5Buffer.append(reverseInt(dis.ReadInt32()));
                            l5Size--;
                        }
                    }
                    else
                    {
                        while (l5Size > 0)
                        {
                            vg._l5Buffer.append(reverseInt((int)(dis.ReadInt64() >> 32)));
                            l5Size--;
                        }
                    }
                }
            }
        }
Beispiel #20
0
        protected override bool GetNextToken()
        {
            if (_isfirsttime)
            {
                _vgnav = null;
                _vg    = new VTDGen();

                if (_vg.parseFile(_fullname, true))
                {
                    _vgnav = _vg.getNav();
                    _vgnav.toElement(VTDNav.ROOT);
                    //_vgap = new AutoPilot(_vgnav);
                    //_vgap.selectElement("*");
                    _isfirsttime   = false;
                    _current_index = 0;
                }
            }
            if (_vgnav == null)
            {
                return(false);
            }
            int nb_tokens = _vgnav.getTokenCount();

            current_token_len = 0;
            while (true)
            {
                try
                {
                    if (_current_index >= nb_tokens)
                    {
                        return(false);
                    }
                    int len = _vgnav.getTokenLength(_current_index);
                    if (len >= 3)
                    {
                        string token = _vgnav.toString(_current_index);
                        len = token.Length;
                        if (len >= 3)
                        {
                            if (len > MAX_WORD_LEN)
                            {
                                len = MAX_WORD_LEN;
                            }
                            current_token        = token.ToCharArray(0, len);
                            current_token_offset = _vgnav.getTokenOffset(_current_index);
                            current_token_len    = len; //_vgnav.getTokenLength(_current_index)
                            _current_index++;
                            return(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    e = e;
                    return(false);
                }

                _current_index++;
            }
            return(true);
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            try
            {
                int t;
                System.IO.FileInfo   f   = new System.IO.FileInfo("./soap2.xml");
                System.IO.FileStream fis =
                    new System.IO.FileStream(f.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                System.IO.FileInfo   f1  = new System.IO.FileInfo("./out.xml");
                System.IO.FileStream fos = new System.IO.FileStream(f1.FullName, System.IO.FileMode.Create);
                byte[] b = new byte[(int)f.Length];
                fis.Read(b, 0, (int)f.Length);
                AutoPilot ap = new AutoPilot();
                ap.declareXPathNameSpace("ns1", "http://www.w3.org/2003/05/soap-envelope");
                // get to the SOAP header
                ap.selectXPath("/ns1:Envelope/ns1:Header/*[@ns1:mustUnderstand]");
                Console.WriteLine("expr string is " + ap.getExprString());
                // instantiate the parser
                VTDGen vg = new VTDGen();
                int    j  = 0;
                VTDNav vn = null;
                while (j < 10)
                {
                    vg.setDoc_BR(b); // use setDoc_BR (instead of setDoc) to turn on buffer reuse
                    vg.parse(true);  // set namespace awareness to true
                    vn = vg.getNav();
                    ap.bind(vn);     // bind calls resetXPath() so

                    while ((t = ap.evalXPath()) != -1)
                    {
                        Console.WriteLine("j t--> " + j + " " + t);
                        long l      = vn.getElementFragment();
                        int  len    = (int)(l >> 32);
                        int  offset = (int)l;
                        fos.Write(b, offset, len); //write the fragment out into out.txt
                        System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("ASCII");
                        byte[] bytes = encoder.GetBytes("\n=========\n");

                        fos.Write(bytes, 0, bytes.Length);
                    }
                    ap.resetXPath();
                    j++;
                }
                j = 0;
                Console.WriteLine("j -->" + j);
                vg.setDoc_BR(b); // use setDoc_BR (instead of setDoc) to turn on buffer reuse
                vg.parse(true);  // set namespace awareness to true
                vn = vg.getNav();
                ap.bind(vn);     // bind calls resetXPath() so
                t = -1;
                while (j < 10)
                {
                    while ((t = ap.evalXPath()) != -1)
                    {
                        Console.WriteLine("j t --> " + j + " " + t);
                        long l      = vn.getElementFragment();
                        int  len    = (int)(l >> 32);
                        int  offset = (int)l;
                        fos.Write(b, offset, len); //write the fragment out into out.txt
                        System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("ASCII");
                        byte[] bytes = encoder.GetBytes("\n=========\n");

                        fos.Write(bytes, 0, bytes.Length);
                    }
                    ap.resetXPath();
                    j++;
                }

                fis.Close();
                fos.Close();
            }
            catch (ParseException e)
            {
            }
            catch (NavException e)
            {
            }
            catch (XPathParseException e)
            {
            }
            catch (XPathEvalException e)
            {
            }
            catch (System.IO.IOException e)
            {
            }
        }