VTDGen vg = new VTDGen(); if (vg.parseFile("c://xml//alex.txt", true)){ VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//L/D"); int i=-1; while((i=ap.evalXPath())!=-1){ long l = vn.getContentFragment(); System.out.println(" -==> "+ vn.toString((int )l, (int)(l>>32))); } }
public class Uo { public boolean parse() { VTDGen vg = new VTDGen(); return vg.parseFile("test.xml", false); } }
import com.ximpleware.*; public class simpleQuery { public static void main(String[] s) throws Exception{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", true)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//targetChannel/mnemonic/text()"); int i = ap.evalXPath(); if (i!=-1) System.out.println(" result ==>"+vn.toString(i)); } }
import com.ximpleware.*; public class extractValue{ public static void main(String s[]) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/aa/bb[name='k1']/value"); int i=0; while ((i=ap.evalXPath())!=-1){ System.out.println(" value ===>"+vn.toString(i)); } } }
import com.ximpleware.*; public class xpathSearch { public static void main(String s[])throws VTDException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("d:\\xml\\input.txt", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/base/parent/*/data[contains(.,'hey')]/../../@id"); int i; while ((i=ap.evalXPath())!=-1) System.out.println("attr id has the value of "+vn.toString(i+1)); } }
import com.ximpleware.*; public class getContent { public static void main(String s[]) throws VTDException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("C:\\Users\\HC\\Desktop\\dataset\\book.xml", false)) return; VTDNav vn = vg.getNav(); if (vn.toElement(VTDNav.FIRST_CHILD, "book")){ long l = vn.getContentFragment(); System.out.println( "book content ==> "); System.out.println(vn.toString((int)l, (int)(l<<32))); } } }
import com.ximpleware.*; public class extractValue{ public static void main(String s[]) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/aa/bb[name='k1']/value"); int i=0; while ((i=ap.evalXPath())!=-1){ System.out.println(" value ===>"+vn.toString(i)); } } }
import com.ximpleware.*; public class removeElement { public static void main(String s[]) throws VTDException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/ClOrdIDS/ClOrdID[@id='3']"); int i=0; while((i=ap.evalXPath())!=-1){ } } }
import com.ximpleware.*; public class accessName { public static void main(String[] args) throws VTDException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/param[@name='id']/text()"); int i=0; while((i=ap.evalXPath())!=-1){ System.out.println("text value "+vn.toString(i)); } } }
import com.ximpleware.*; public class openAndTest{ public static void main(String[] s) throws VTDException{ // open the XML file VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false) ) // namespace disabled here return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); //bind to vn object ap.selectXPath("/CdtTrfTxInf/PmtId/EndToEndId"); // dont put xpath compilation in loop System.out.println(" test result is "+ap.evalXPathToBoolean()); ap.selectXPath("/CdtTrfTxInf/PmtId/EndToEndId"); // reuse AP, but you can instantiate a separate AutoPilot object. System.out.println(" test result is "+ap.evalXPathToBoolean()); } }
import com.ximpleware.*; public class getAttrs{ public static void main(String[] s) throws VTDException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml",false)) // turn off namespace return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/xml/item/@name"); int i=0; while( (i=ap.evalXPath())!=-1){ System.out.println(" item name is ===>"+vn.toString(i+1)); } } }
import com.ximpleware.*; public class Example1 { public static void main(String[] argv) throws Exception{ VTDGen vg = new VTDGen(); if (vg.parseFile("c:/test2.xml",true)){ VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//TextVar/text()"); int i; while((i=ap.evalXPath())!=-1){ System.out.println(" text value ==>"+vn.toString(i)); } } } }
VTDGen vg= new VTDGen(); if (vg.parseFile("input.xml",false)){ VTDNav vn = vg.getNav(); vn.toElement(VTDNav.FIRST_CHILD); int i = vn.getText(); if (i!=-1) System.out.println(" text node is "+vn.toString(i)); }
import com.ximpleware.*; public class simpleXpathSearch{ public static void main(String s[]) throws VTDException,java.io.UnsupportedEncodingException,java.io.IOException{ VTDGen vg = new VTDGen(); vg.setLCLevel(5); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/*/*[@rsID='1029293']"); int i=0; while((i=ap.evalXPath())!=-1){ // your code logic here }
import com.ximpleware.*; public class queryAttr{ public static void main(String[] s) throws VTDException{ VTDGen vg= new VTDGen(); if (!vg.parseFile("input.xml", false)) return false; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//xml/ep/source/@type"); int i=0; while((i = ap.evalXPath())!=-1){ system.out.println(" attr val ===>"+ vn.toString(i+1)); } } }
import com.ximpleware.*; import java.io.*; public class removeNode { public static void main(String s[]) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); XMLModifier xm = new XMLModifier(vn); ap.selectXPath("/xml/A/B[C/E='13']"); while (ap.evalXPath()!=-1){ xm.remove(); } xm.output("output.xml"); } }
import com.ximpleware.*; public class removeNode { public static void main(String s[]) throws Exception{ VTDGen vg = new VTDGen(); boolean b = vg.parseFile("input.xml", false); if (b==false) return; VTDNav vn = vg.getNav(); XMLModifier xm = new XMLModifier(vn); vn.toElement(VTDNav.FC); // get to A node long l = vn.getContentFragment(); xm.remove(l); xm.output("output.xml"); } }
final VTDGen vg = new VTDGen(); vg.parseFile("/path/to/file.xml", false); final VTDNav vn = vg.getNav(); final AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/Example/Entry"); int count = 1; while (ap.evalXPath() != -1) { System.out.println("Inside Entry: " + count); //move to n1 child vn.toElement(VTDNav.FIRST_CHILD, "n1"); System.out.println("\tn1: " + vn.toNormalizedString(vn.getText())); //move to n2 child vn.toElement(VTDNav.NEXT_SIBLING, "n2"); System.out.println("\tn2: " + vn.toNormalizedString(vn.getText())); //move back to parent vn.toElement(VTDNav.PARENT); count++; }
VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(); int i; ap.selectXPath("/root/device/modelname"); if (vg.parseFile(PATH_TO_FILE,true)){ VTDNav vn = vg.getNav(); ap.bind(vn); // apply XPath to the VTDNav instance // AutoPilot moves the cursor for you while((i=ap.evalXPath())!=-1){ System.out.println("the value is: " + vn.toNormalizedString(vn.getText())); } }
VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(); int i; ap.selectXPath("/root/element"); if (vg.parseFile(FILE_LOCATION,true)){ VTDNav vn = vg.getNav(); ap.bind(vn); // apply XPath to the VTDNav instance // AutoPilot moves the cursor for you while((i=ap.evalXPath())!=-1){ System.out.println("the attribute index val is "+ i +" the attribute string ==>"+vn.toString(vn.getAttrVal("attribute"))); } }