Пример #1
0
 /// <summary> Select the element name before iterating.
 /// "*" matches every element
 /// Creation date: (12/4/03 5:51:31 PM)
 /// </summary>
 /// <param name="en">java.lang.String
 /// </param>
 public void  selectElement(System.String en)
 {
     if (en == null)
     {
         throw new System.ArgumentException("element name can't be null");
     }
     iter_type = SIMPLE;
     depth     = vn.getCurrentDepth();
     //startIndex = vn.getCurrentIndex();
     name = en;
     ft   = true;
 }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="vn"></param>
        /// <param name="s"></param>
        /// <returns></returns>
        private bool lang(VTDNav vn, String s)
        {
            // check the length of s
            bool b = false;

            vn.push2();
            try
            {
                while (vn.getCurrentDepth() >= 0)
                {
                    int i = vn.getAttrVal("xml:lang");
                    if (i != -1)
                    {
                        b = vn.matchTokenString(i, s);
                        break;
                    }
                    vn.toElement(VTDNav.P);
                }
            }
            catch (NavException e)
            {
            }
            vn.pop2();
            return(b);
        }
Пример #3
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)
            {
            }
        }
Пример #4
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);
            }
        }