예제 #1
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);
            }
        }
예제 #2
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);
            }
        }
예제 #3
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();
                vg.selectLcDepth(5); // 3 is default, by we set to 5 (for version 2.10 and onward)
                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);
            }
        }