Refine search
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))); } }
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 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.*; 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 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"); } } }
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())); } }
private static void updateAllConfigurations(File pomXml, Map<String, ModelNode> extensionSchemas, int indentationSize) throws Exception { VTDGen gen = new VTDGen(); gen.enableIgnoredWhiteSpace(true); gen.parseFile(pomXml.getAbsolutePath(), true); VTDNav nav = gen.getNav(); XMLModifier mod = new XMLModifier(nav); int textPos = nav.getText(); String jsonConfig = nav.toRawString(textPos); XmlUtil.toIndentedString(xml, indentationSize, nav.getTokenDepth(textPos), pretty); String prettyXml = pretty.toString().substring(indentationSize * nav.getTokenDepth(textPos)); mod.insertAfterElement(prettyXml); mod.remove(); AutoPilot ap = new AutoPilot(nav); ap.selectXPath("//plugin[groupId = 'org.revapi' and artifactId = 'revapi-maven-plugin']/configuration/analysisConfiguration"); while (ap.evalXPath() != -1) { update.call();
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"); } } }
public static void main(String[] args) throws VTDException,IOException { VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(), ap3=new AutoPilot(), ap4=new AutoPilot(), ap5= new AutoPilot(); ap.selectXPath("/root/a"); ap4.selectXPath("descendant::*"); ap5.selectXPath("//@*"); if (!vg.parseFile("d:\\xml\\oo.xml", false)) return; VTDNav vn = vg.getNav(); ap.bind(vn);ap3.bind(vn); ap4.bind(vn);ap5.bind(vn); while((i=ap5.evalXPath())!=-1){ xm.remove(); ap4.resetXPath(); vn.pop(); xm.output("d:\\xml\\ooo.xml");
VTDGen vg = new VTDGen(); String xml="<document-element xmlns=\"uri:ns1\">\n"+ "<foo>\n"+ "</foo>\n"+ "</document-element>\n"; vg.setDoc(xml.getBytes()); vg.parse(false); // namespace unaware to all name space nodes addressable using xpath @* VTDNav vn = vg.getNav(); XMLModifier xm = new XMLModifier(vn); FastIntBuffer fib = new FastIntBuffer(); ap.selectXPath("//@*"); int i=0; while((i=ap.evalXPath())!=-1){ if (vn.getTokenType(i)==VTDNav.TOKEN_ATTR_NS){ xm.remove(); //remove all ns node fib.append(i); int os = vn.getTokenOffset(fib.intAt(j)); int len = vn.getTokenOffset(fib.intAt(j)+1)+vn.getTokenLength(fib.intAt(j)+1)+1-os; vn.toElement(VTDNav.ROOT); xm.insertAttribute(attrBytes); xm.output(baos); System.out.println(baos.toString());
private void updateAllConfigurationFiles(MavenProject project, Map<String, ModelNode> extensionSchemas, int indentationSize) throws Exception { VTDGen gen = new VTDGen(); gen.enableIgnoredWhiteSpace(true); gen.parseFile(project.getFile().getAbsolutePath(), true); VTDNav nav = gen.getNav(); XMLModifier mod = new XMLModifier(nav); AutoPilot ap = new AutoPilot(nav); ap.resetXPath(); ap.selectXPath(xpath); while (ap.evalXPath() != -1) { int textPos = nav.getText(); String configFile = nav.toString(textPos); mod.updateToken(textPos, newFile.getPath()); mod.output(out);
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"); } }
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); } }
import com.ximpleware.*; import java.io.*; public class removeAttrNode { public static void main(String[] s) throws VTDException, Exception{ VTDGen vg = new VTDGen(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Payment xmlns=\"http://api.com/schema/store/1.0\"><Store>abc</Store></Payment>"; vg.setDoc(xml.getBytes()); vg.parse(false); // turn off namespace awareness so that VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); XMLModifier xm = new XMLModifier(vn); ap.selectXPath("//@xmlns"); int i=0; while((i=ap.evalXPath())!=-1){ xm.remove(); } xm.output(baos); System.out.println(baos.toString()); } }
VTDGen gen = new VTDGen(); gen.enableIgnoredWhiteSpace(true); gen.parseFile(project.getFile().getAbsolutePath(), true); VTDNav nav = gen.getNav(); AutoPilot ap = new AutoPilot(nav); XMLModifier mod = new XMLModifier(nav); ap.selectXPath("/project/version"); if (ap.evalXPath() != -1) { int textPos = nav.getText(); mod.updateToken(textPos, version.toString()); } else { mod.insertAfterElement(versionLine.toString());
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"))); } }
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()); } }
public class simpleSplit { public static void main(String[] s) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("d:\\xml\\message.xml", true)) //namespace awareness disabled return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn), ap2=new AutoPilot(vn); XMLModifier xm = new XMLModifier(vn); ap.selectXPath("/messagge/heading/context/forniture/document"); //first xpath FastLongBuffer fib= new FastLongBuffer();// grab all the fragments int i=0;long l1=0,l2=0,l3=0; while((i=ap.evalXPath())!=-1){ fib.append(vn.getElementFragment()); ap2.selectXPath("/messagge/heading/context/forniture"); //second xpath i=ap2.evalXPath(); if(vn.toElement(VTDNav.FIRST_CHILD,"fornitureHeading")){ l1= vn.getElementFragment(); vn.toElement(VTDNav.P); l2 = vn.getContentFragment(); for (int j=0;j<fib.size();j++){ xm.insertAfterHead(vn,l1); xm.removeContent((int)(l2),(int)(l2>>32)); l3= fib.longAt(j); xm.insertBeforeTail(vn,l3); xm.output("d:\\xml\\outMessage"+(j+1)+".xml"); xm.reset();