/** * Update token with the transcoded representation of * a segment of byte array contained in vn (in terms of offset and length) * @param index * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void updateToken(int index, VTDNav vn, int contentOffset, int contentLen) throws ModifyException,UnsupportedEncodingException, TranscodeException{ updateToken(index, vn.XMLDoc.getBytes(), contentOffset, contentLen, vn.encoding); }
/** * Update token with the transcoded representation of * a segment of byte array contained in vn (in terms of offset and length) * @param index * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void updateToken(int index, VTDNav vn, int contentOffset, int contentLen) throws ModifyException,UnsupportedEncodingException, TranscodeException{ updateToken(index, vn.XMLDoc.getBytes(), contentOffset, contentLen, vn.encoding); }
/** * Update token with the transcoded representation of * a segment of byte array contained in vn (in terms of offset and length) * @param index * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void updateToken(int index, VTDNav vn, int contentOffset, int contentLen) throws ModifyException,UnsupportedEncodingException, TranscodeException{ updateToken(index, vn.XMLDoc.getBytes(), contentOffset, contentLen, vn.encoding); }
xm.updateToken(textIndex, text); LOG.trace("Element text already existed at token index {} and is replaced.", textIndex); } else {
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()); } }
import com.ximpleware.*; public class changeAttrVal { public static void main(String s[]) throws VTDException,java.io.UnsupportedEncodingException,java.io.IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); XMLModifier xm = new XMLModifier(vn); ap.selectXPath("/*/place[@id=\"p14\" and @initialMarking=\"2\"]/@initialMarking"); int i=0; while((i=ap.evalXPath())!=-1){ xm.updateToken(i+1, "499");// change initial marking from 2 to 499 } xm.output("new.xml"); // output to a new document called new.xml } }
import com.ximpleware.*; public class changeAttrVal { public static void main(String s[]) throws VTDException,java.io.UnsupportedEncodingException,java.io.IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); XMLModifier xm = new XMLModifier(vn); ap.selectXPath("/*/place[@id=\"p14\" and @initialMarking=\"2\"]/@initialMarking"); int i=0; while((i=ap.evalXPath())!=-1){ xm.updateToken(i+1, "499");// change initial marking from 2 to 499 } xm.output("new.xml"); } }
import java.io.*; public class modifyXML { public static void main(String[] s) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/vertices/vertex/name/text()"); XMLModifier xm = new XMLModifier(vn); // using XPath int i=ap.evalXPath(); if(i!=-1){ xm.updateToken(i, "user2"); } xm.output("output.xml"); } }
import com.ximpleware.*; import java.io.*; public class updateXSD { public static void main(String[] s) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("d:\\xml\\xsd.xml", true)){ return; } VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.declareXPathNameSpace("xs", "XSD namespace here"); ap.selectXPath("//xs:element[@name='Bike']/@type"); XMLModifier xm = new XMLModifier(vn); int i=-1; while((i=ap.evalXPath())!=-1){ xm.updateToken(i+1, "Twowheeler"); } xm.output("d:\\xml\\newXSD.xml"); } }
import com.ximpleware.*; import java.io.*; public class modifyXML { public static void main(String[] s) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/configuration/param1/text()"); XMLModifier xm = new XMLModifier(vn); // using XPath int i=ap.evalXPath(); if(i!=-1){ xm.updateToken(i, "4.0"); } String s1 ="<param2>asdf</param2>/n<test>/n<param3>true</param3>/n</test>"; xm.insertAfterElement(s1); xm.output("output.xml"); } }
mod.updateToken(textPos, version.toString()); } else {
int k=vn.getText(); if (i!=-1) xm.updateToken(k, "Jonathan"); vn.toElement(VTDNav.PARENT); int k=vn.getText(); if (i!=-1) xm.updateToken(k, "42"); vn.toElement(VTDNav.PARENT);
xm.updateToken(i,"value"); xm.updateToken(i," new content ");
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 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"); } } }
updateToken(i,newElementName); long l = md.getElementFragment(); int encoding = md.getEncoding();
mod.updateToken(textPos, newFile.getPath());
throws ModifyException,UnsupportedEncodingException,TranscodeException{ if (src_encoding == encoding){ updateToken(index,newContentBytes); return;
updateToken(index, newContentBytes, contentOffset, contentLen); return;