ap.selectXPath(xpath); XMLModifier mod = new XMLModifier(nav); while (ap.evalXPath() != -1) { mod.remove();
XMLModifier mod = new XMLModifier(nav);
XMLModifier mod = new XMLModifier(nav);
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); } }
static VTDGen vg = new VTDGen(); static String inFile = "c:\\xml\\kepler.xml"; static XMLModifier xm = new XMLModifier(); /** * @param args */ public static void main(String[] args) throws ParseException, NavException, XPathParseException, XPathEvalException, Exception{ // TODO Auto-generated method stub int result; AutoPilot ap = new AutoPilot(); ap.selectXPath("//Address[LastName='ghi']/FirstName/text()"); if (vg.parseFile(inFile,true)){ VTDNav vn = vg.getNav(); ap.bind(vn);xm.bind(vn); while((result = ap.evalXPath())!=-1){ //System.out.println(vn.getText() + vn.toString(result)); xm.updateToken(result,"TestValue"); } } xm.output(new FileOutputStream("c:\\xml\\resultbooks.xml")); }
import com.ximpleware.*; public class replaceContent { public static void main(String[] s) throws VTDException, Exception{ VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(); XMLModifier xm = new XMLModifier(); if (vg.parseFile("d:\\xml\\input2.xml", true)){ VTDNav vn = vg.getNav(); ap.bind(vn); xm.bind(vn); ap.selectXPath("/clients/function/block"); int i=-1; byte[] s1 = ("\r\n\t\t<opster>hello = world</opster>\r\n\t\t"+ "<opster>abc = def</opster>\r\n\t").getBytes(); while((i=ap.evalXPath())!=-1){ xm.insertAfterHead(s1); long l= vn.getContentFragment(); // add new stuff after the starting tag xm.removeContent((int)l, (int)(l>>32)); // remove old stuff } xm.output("d:\\xml\\new.xml"); } } }
XMLModifier xm = new XMLModifier(); //Instantiate XMLModifier XMLModifier xm1 = new XMLModifier(); XMLModifier xm2 = new XMLModifier();
import com.ximpleware.*; public class removeWS { public static void main(String[] s) throws VTDException, Exception{ VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(); XMLModifier xm = new XMLModifier(); if (vg.parseFile("d:\\xml2\\ws.xml", true)){ VTDNav vn = vg.getNav(); ap.bind(vn); xm.bind(vn); ap.selectXPath("//text()"); int i=-1; while((i=ap.evalXPath())!=-1){ int offset = vn.getTokenOffset(i); int len = vn.getTokenLength(i); long l = vn.trimWhiteSpaces((((long)len)<<32)|offset ); System.out.println(" ===> "+vn.toString(i)); System.out.println("len ==>"+len+" new len==>"+ (l>>32)); int nlen = (int)(l>>32); int nos= (int) l; xm.updateToken(i,vn,nos,nlen); } xm.output("d:\\xml2\\new.xml"); } } }
XMLModifier mod = new XMLModifier(nav);
import com.ximpleware.*; public class insertTextNode { public static void main(String[] s) throws VTDException, Exception { VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(); XMLModifier xm = new XMLModifier(); if (vg.parseFile("input.xml", true)) { VTDNav vn = vg.getNav(); ap.bind(vn); xm.bind(vn); ap.selectXPath("/body/request/location/address"); int i=0; while((i=ap.evalXPath())!=-1){ xm.insertAfterHead("myAddress"); } xm.output("output.xml"); } } }
import com.ximpleware.*; import java.io.*; public class removeTag { public static void main(String[] args) throws VTDException,IOException { // TODO Auto-generated method stub VTDGen vg = new VTDGen(); AutoPilot ap=new AutoPilot(); ap.selectXPath("//value"); XMLModifier xm = new XMLModifier(); if (!vg.parseFile("d:\\xml\\tag.xml", false)){ System.out.println("error in xml"); return; } VTDNav vn = vg.getNav(); xm.bind(vn); ap.bind(vn); int i=0; while((i=ap.evalXPath())!=-1){ xm.remove();//remove value fragment long l = vn.getContentFragment(); //replace value with everything it encloses xm.insertBeforeElement(vn.getXML().getBytes(), l); } xm.output("d:\\xml\\newTag.xml"); } }
public static void main(String[] s) throws Exception{ VTDGen vg = new VTDGen(); // Instantiate VTDGen XMLModifier xm = new XMLModifier(); //Instantiate XMLModifier if (vg.parseFile("old.xml",false)){ VTDNav vn = vg.getNav();