private int getStringVal(VTDNav vn,int i){ int i1,t = vn.getTokenType(i); if (t == VTDNav.TOKEN_STARTING_TAG){ i1 = vn.getText(); return i1; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS || t==VTDNav.TOKEN_PI_NAME ) return i+1; else return i; }
final private int getStringVal(VTDNav vn,int i){ int i1,t = vn.getTokenType(i); if (t == VTDNav.TOKEN_STARTING_TAG){ i1 = vn.getText(); return i1; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS || t==VTDNav.TOKEN_PI_NAME) return i+1; else return i; }
private int getStringVal(VTDNav vn,int i){ int i1,t = vn.getTokenType(i); if (t == VTDNav.TOKEN_STARTING_TAG){ i1 = vn.getText(); return i1; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS || t==VTDNav.TOKEN_PI_NAME ) return i+1; else return i; }
final private int getStringVal(VTDNav vn,int i){ int i1,t = vn.getTokenType(i); if (t == VTDNav.TOKEN_STARTING_TAG){ i1 = vn.getText(); return i1; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS || t==VTDNav.TOKEN_PI_NAME) return i+1; else return i; }
final private int getStringVal(VTDNav vn,int i){ int i1,t = vn.getTokenType(i); if (t == VTDNav.TOKEN_STARTING_TAG){ i1 = vn.getText(); return i1; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS || t==VTDNav.TOKEN_PI_NAME) return i+1; else return i; }
private int getStringVal(VTDNav vn,int i){ int i1,t = vn.getTokenType(i); if (t == VTDNav.TOKEN_STARTING_TAG){ i1 = vn.getText(); return i1; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS || t==VTDNav.TOKEN_PI_NAME ) return i+1; else return i; }
protected Optional<List<String>> getXPathValues(String xpath) throws XPathParseException, XPathEvalException, NavException { try { vn.push(); List<String> values = new ArrayList<>(); AutoPilot ap = getAutoPilot(xpath, vn); while (ap.evalXPath() != -1) { int text = vn.getText(); if (text != -1) values.add(vn.toString(text)); } if (!values.isEmpty()) return Optional.of(values); return Optional.empty(); } finally { releaseAutoPilot(); vn.pop(); } }
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(); 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)); }
public void formCreateXMLRequest(MAMData mamData,Map<String, String> strTobeModified) throws DatatypeConfigurationException, PayPalUserCreationFailedException, ModifyException, TranscodeException, IOException, XPathEvalException, NavException, XPathParseException { VTDGen vg = new VTDGen(); if (!vg.parseFile(mamData.getDirectory() + mamData.getBatchRequest(), true)) return; VTDNav vn = vg.getNav(); XMLModifier xm = new XMLModifier(vn); AutoPilot ap = new AutoPilot(vn); Set<String> xpathkeys= strTobeModified.keySet(); for(String xpath : xpathkeys) { ap.selectXPath(xpath); while((ap.evalXPath()) != -1) { int p = vn.getText(); xm.updateToken(p, strTobeModified.get(xpath)); } xm.output(mamData.getDirectory()+mamData.getBatchRequest()); } }
VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//test"); while (ap.evalXPath() != -1) { System.out.println("Inside Test tag"); //now find the children called "bla" if(vn.toElement(VTDNav.FIRST_CHILD, "bla")){ do{ int val = vn.getText() ; if(val!=-1){ String value = vn.toNormalizedString(val); System.out.println("\tFound bla: " + value); } } while(vn.toElement(VTDNav.NEXT_SIBLING, "bla")); } //move back to parent vn.toElement(VTDNav.PARENT); }
final VTDGen vg = new VTDGen(); vg.parseFile("file.xml", false); final VTDNav vn = vg.getNav(); final AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/products/product"); while (ap.evalXPath() != -1) { System.out.println("PRODUCT:"); // you could either apply another xpath or simply get the first child if (vn.toElement(VTDNav.FIRST_CHILD, "title")) { int val = vn.getText(); if (val != -1) { System.out.println("Title: " + vn.toNormalizedString(val)); } vn.toElement(VTDNav.PARENT); } if (vn.toElement(VTDNav.FIRST_CHILD, "image")) { int val = vn.getText(); if (val != -1) { System.out.println("Image: " + vn.toNormalizedString(val)); } vn.toElement(VTDNav.PARENT); } }
import com.ximpleware.*; public class dumpKeyValue { public static void main(String[] s) throws VTDException{ VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(); ap.selectXPath("//part/*[text()]"); if (!vg.parseFile("d:\\xml\\soap.xml", false)){ System.out.println("invalid xml"); System.exit(0); } VTDNav vn = vg.getNav(); ap.bind(vn); int i=0; while((i=ap.evalXPath())!=-1){ System.out.println(" "+vn.toRawString(i)+" = "+vn.toNormalizedString(vn.getText())); } } }
import com.ximpleware.*; public class conditionalSelection { public static void main(String s[]) throws VTDException{ VTDGen vg = new VTDGen(); if(!vg.parseFile("d:\\xml\\condition.xml", false)) // disable namespace return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/root/parent[child1>20]"); // the xpath selecting all parents with child1>20 int i=0,j=0; while((i=ap.evalXPath())!=-1){ // now move the cursor to child2 and child3 if(vn.toElement(VTDNav.FC,"child2")){ j = vn.getText(); if (j!=-1)//make sure the text node exist System.out.println(" child2's text node is ==>"+ vn.toString(j)); vn.toElement(VTDNav.P); } if(vn.toElement(VTDNav.FC,"child3")){ j = vn.getText(); if (j!=-1)//make sure the text node exist System.out.println(" child3's text node is ==>"+ vn.toString(j)); vn.toElement(VTDNav.P); } } }
String text = vn.toNormalizedString(vn.getText()); String name = vn.toString(vn.getAttrVal("name"));
import com.ximpleware.*; public class dumpKeyValue { public static void main(String[] s) throws VTDException{ VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(); ap.selectXPath("//*[text()]"); if (!vg.parseFile("d:\\xml\\keyValue.xml", false)){ System.out.println("invalid xml"); System.exit(0); } VTDNav vn = vg.getNav(); ap.bind(vn); int i=0; while((i=ap.evalXPath())!=-1){ System.out.println(" "+vn.toRawString(i)+" = "+vn.toNormalizedString(vn.getText())); } } }
String text = vn.toNormalizedString(vn.getText()); String name = vn.toString(vn.getAttrVal("name"));
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())); } }
import com.ximpleware.*; public class retrieveNodes{ public static void main(String s[]) throws VTDException,java.io.UnsupportedEncodingException,java.io.IOException{ VTDGen vg = new VTDGen(); vg.setLCDepth(5); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/catalog/product/catalog_item"); int i=0; while((i=ap.evalXPath())!=-1){ if (vn.toElement(VTDNav.FIRST_CHILD,"itemNumber")){ int j=vn.getText(); if (j!=-1) System.out.println("text node ==>"+vn.toString(j); vn.toElement(VTDNav.PARENT); } } } }
void updateProjectParentVersion(MavenProject project, Version version) throws MojoExecutionException { try { VTDGen gen = new VTDGen(); gen.enableIgnoredWhiteSpace(true); gen.parseFile(project.getFile().getAbsolutePath(), true); VTDNav nav = gen.getNav(); AutoPilot ap = new AutoPilot(nav); ap.selectXPath("namespace-uri(.)"); String ns = ap.evalXPathToString(); nav.toElementNS(VTDNav.FIRST_CHILD, ns, "parent"); nav.toElementNS(VTDNav.FIRST_CHILD, ns, "version"); int pos = nav.getText(); XMLModifier mod = new XMLModifier(nav); mod.updateToken(pos, version.toString()); try (OutputStream out = new FileOutputStream(project.getFile())) { mod.output(out); } } catch (IOException | ModifyException | NavException | XPathParseException | TranscodeException e) { throw new MojoExecutionException("Failed to update the parent version of project " + project, e); } }