Click here to Skip to main content
15,892,746 members
Articles / Programming Languages / XML

VTD-XML: XML Processing for the Future (Part I)

Rate me:
Please Sign up or sign in to vote.
4.50/5 (17 votes)
17 Apr 2008CPOL10 min read 96.2K   1.1K   59  
Introduce VTD-XML, the future of XML processing
import com.ximpleware.*; 
public class xpathNs{
        public static void main(String[] args) throws Exception{
            VTDGen vg = new VTDGen();
            AutoPilot ap = new AutoPilot();
            int i;
            // declareXPathNameSpace associates name space with a prefix
            ap.declareXPathNameSpace("ns1","someURL");
	    ap.selectXPath("/ns1:a/ns1:b/text()");
            if (vg.parseFile("d:/java_tutorial_by_code_examples/3/input.xml",true)){
                VTDNav vn = vg.getNav();
                ap.bind(vn); 
                // AutoPilot moves the cursor for you, as it returns the index value of the qualified node
                while((i=ap.evalXPath())!=-1){
                    // notice that i always is equal to vn.getCurrentIndex()!!!
                    System.out.println("the text node index val is "+ 
                        i +" the text string ==>"+vn.toString(i));
                    // below is equivalent to 
                    // vn's cursor is what gets moved by AutoPilot here
                    System.out.println("the text node index val is " + 
                        i + " the text string ==>" + vn.toString(vn.getCurrentIndex()));
                }
            }
        } 
}

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