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 static String getXpathValue(String xpath, AutoPilot ap) throws XPathParseException { ap.selectXPath(xpath); return ap.evalXPathToString(); }
AutoPilot ap = new AutoPilot(nav); ap.declareXPathNameSpace("xql", "someNameSpace"); ap.selectXPath("//xql:XQL");
AutoPilot ap = new AutoPilot(nav); ap.declareXPathNameSpace("xql", "someNameSpace"); ap.selectXPath("/startQuery/xql:XQL");
AutoPilot ap2 = new AutoPilot(); ap2.selectXPath("blah");
AutoPilot ap = new AutoPilot(nav); ap.declareXPathNameSpace("h", "urn:hypotheticalNamespace"); ap.declareXPathNameSpace("xql", "someNameSpace"); ap.selectXPath("/h:startQuery/xql:XQL");
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 concatTest{ public static void main(String s1[]) throws Exception { VTDGen vg= new VTDGen(); String s = "<users><user><firstName>some </firstName><lastName> one</lastName></user></users>"; vg.setDoc(s.getBytes()); vg.parse(false); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(); ap.selectXPath("concat('good', ' luck')"); System.out.println(" concat output ==>"+ap.evalXPathToString()); ap.selectXPath("concat(/, '')"); ap.bind(vn); System.out.println(" concat output ==>"+ap.evalXPathToString()); } }
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 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 simpleQuery { public static void main(String[] s) throws Exception{ String myXML="<resp><status>good</status><msg>hi</msg></resp>"; VTDGen vg = new VTDGen(); vg.setDoc(myXML.getBytes()); vg.parse(false); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/resp/status"); int i = ap.evalXPath(); if (i!=-1) System.out.println(" result ==>"+vn.toString(i)); } }
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 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 }
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"))); } }
@Override public void parseType(ConcreteType concreteType, VTDNav nav, JCas jcas, byte[] identifier, DocumentTextData docText) throws Exception { VTDNav vn = nav.cloneNav(); for (FeatureTemplate featureTemplate : concreteType.getTypeTemplate().getFeatures()) { for (String xPath : featureTemplate.getXPaths()) { AutoPilot ap = new AutoPilot(vn); ap.selectXPath(xPath); while (ap.evalXPath() != -1) { ConcreteFeature concreteFeature = new ConcreteFeature(featureTemplate); parseSingleType(concreteFeature, vn, jcas, identifier, docText); concreteType.addFeature(concreteFeature); } } } }