Refine search
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(), ap3=new AutoPilot(), ap4=new AutoPilot(), ap5= new AutoPilot(); ap.selectXPath("/root/a"); ap3.selectXPath("@key"); 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); XMLModifier xm = new XMLModifier(vn); while((i=ap5.evalXPath())!=-1){ xm.remove(); while((i=ap.evalXPath())!=-1){ keyName= ap3.evalXPathToString(); vn.push(); while((j=ap4.evalXPath())!=-1){ elementName = vn.toRawString(j); int offset = elementName.indexOf(':'); String newElementName = keyName+"_"+((offset==-1)?elementName: elementName.substring(offset+1)) ; xm.updateElementName(newElementName); ap4.resetXPath();
VTDGen vg = new VTDGen(); vg.selectLcDepth(5);// soap has deep nesting so set to 5 to speed up navigation if (!vg.parseFile("d:\\xml\\soap2.xml", true)) return; VTDNav vn = vg.getNav(); ap.declareXPathNameSpace("ns", "http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema"); ap.declareXPathNameSpace("ns1", "http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema"); ap.declareXPathNameSpace("cm", "http://www.ibm.com/xmlns/db2/cm/api/1.0/schema"); ap.declareXPathNameSpace("soapenv", "http://www.w3.org/2003/05/soap-envelope"); ap.selectXPath("/soapenv:Envelope/soapenv:Body/ns1:RunQueryReply/ns1:ResultSet/ns1:Item/ns1:ItemXML//ICCSPArchivSuche/@ICCFileName"); int i=0; if ((i=ap.evalXPath())!=-1){ System.out.println("file name ==>"+vn.toString(i+1)); ap.selectXPath("/soapenv:Envelope/soapenv:Body/ns1:RunQueryReply/ns1:ResultSet/ns1:Item/ns1:ItemXML//ICCSPArchivSuche/cm:resourceObject/cm:URL/@value"); if ((i=ap.evalXPath())!=-1){ System.out.println("file name ==>"+vn.toString(i+1));
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 ap2 = new AutoPilot(); ap2.selectXPath("blah");
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 deleteNode { 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("/*/*[@id='s2']");// this is the key XPath expression int i=0; while((i=ap.evalXPath())!=-1){ xm.remove(vn.getElementFragment());// remove the node } xm.output("new.xml"); // output to a new document called new.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())); } }
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)); } }
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(); ap.resetXPath(); ap.selectXPath("//plugin[groupId = 'org.revapi' and artifactId = 'revapi-maven-plugin']/executions/execution/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"); } } }
VTDGen vtdGen = new VTDGen(); vtdGen.selectLcDepth(5); vtdGen.parseFile("c:\\xml\\agata.xml",false); AutoPilot ap = new AutoPilot(),ap1=new AutoPilot(), ap2=new AutoPilot(),ap3=new AutoPilot(); ap.bind(vn);ap1.bind(vn);ap2.bind(vn);ap3.bind(vn); ap.selectXPath("/MedlineCitationSet/MedlineCitation"); ap1.selectXPath("PMID"); ap2.selectXPath("DateCreated"); ap3.selectXPath("Article"); while ((ap.evalXPath()) != -1) { String year = null, day = null, month = null; i++; if (vn.hasAttr("Owner")) System.out.println("Owner==>"+vn.toNormalizedString(vn.getAttrVal("Owner"))); while((ap1.evalXPath())!=-1){ ap1.resetXPath(); while((ap2.evalXPath())!=-1){ ap2.resetXPath(); while((ap3.evalXPath())!=-1){
VTDNav vn = vg.getNav(); FastIntBuffer fib = new FastIntBuffer(); for (i=0;i<vn.getTokenCount();i++){ if (vn.getTokenType(i)==VTDNav.TOKEN_STARTING_TAG){ fib.append(0x1);// b'11 since it is a white list, }else{ ap1.selectXPath("descendant::*");// mark descendant as keep for (int j=0;j<filter.size();j++){ ap.selectXPath(filter.get(j)); while((i=ap.evalXPath())!=-1){ fib.modifyEntry(i, 0x3); vn.push(); while((k=ap1.evalXPath())!=-1){ fib.modifyEntry(k, 0x3); ap1.resetXPath(); ap.resetXPath(); xm.remove(); xm.output("d:\\xml\\newSchoolInfo.xml");
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"); } }
VTDGen vg = new VTDGen(); VTDNav vn = vg.getNav(); AutoPilot table = new AutoPilot(vn); table.selectXPath("database/table"); while (table.iterate()) { String tableName = vn.toString(vn.getAttrVal("name")); column.selectElement("column"); while (column.iterate()) { 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/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"))); } }
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()); } }