Click here to Skip to main content
15,886,199 members
Articles / Mobile Apps

Programming XPath with VTD-XML

Rate me:
Please Sign up or sign in to vote.
3.93/5 (8 votes)
10 Jun 2010CPOL10 min read 72.3K   343   32  
Learn to take advantage of VTD-XML's stateless XPath capability to achieve unmatched efficiency and flexibility
using System;
using System.Collections.Generic;
using System.Text;
using com.ximpleware;
namespace app4
{
    class Program
    {
        static void Main(string[] args)
        {
            VTDGen vg = new VTDGen();
            int i;
            AutoPilot ap = new AutoPilot();

            ap.selectXPath("/CATALOG/CD[PRICE < 10]");
            if (vg.parseFile("catalog.xml", false))
            {
                VTDNav vn = vg.getNav();
                ap.bind(vn);
                //XPath eval returns one node at a time
                while ((i = ap.evalXPath()) != -1)
                {
                    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));
                    }
                    vn.pop();
                }
                ap.resetXPath();
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer XimpleWare
United States United States
Jimmy Zhang is a cofounder of XimpleWare, a provider of high performance XML processing solutions. He has working experience in the fields of electronic design automation and Voice over IP for a number of Silicon Valley high-tech companies. He holds both a BS and MS from the department of EECS from U.C. Berkeley.

Comments and Discussions