/** * Generate the updated output XML document and write it into * a file of given name * @param fileName * @throws IOException * @throws ModifyException * */ public void output(String fileName) throws IOException, ModifyException,TranscodeException{ FileOutputStream fos = new FileOutputStream(fileName); output(fos); fos.close(); }
/** * Generate the updated output XML document and write it into * a file of given name * @param fileName * @throws IOException * @throws ModifyException * */ public void output(String fileName) throws IOException, ModifyException,TranscodeException{ FileOutputStream fos = new FileOutputStream(fileName); output(fos); fos.close(); }
/** * Generate the updated output XML document and write it into * a file of given name * @param fileName * @throws IOException * @throws ModifyException * */ public void output(String fileName) throws IOException, ModifyException,TranscodeException{ FileOutputStream fos = new FileOutputStream(fileName); output(fos); fos.close(); }
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()); } }
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.*; 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 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 com.ximpleware.*; import java.io.*; public class removeElement { public static void main(String s[]) throws VTDException,IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); XMLModifier xm = new XMLModifier(vn); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/ClOrdIDS/ClOrdID[@id='3']"); int i=0; while((i=ap.evalXPath())!=-1){ xm.remove(); } xm.output("output.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 removeElement { public static void main(String s[]) throws VTDException,IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); XMLModifier xm = new XMLModifier(vn); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/ClOrdIDS/ClOrdID[@id='3']"); int i=0; while((i=ap.evalXPath())!=-1){ xm.remove(); } xm.output("output.xml"); } }
import com.ximpleware.*; import java.io.*; public class removeElement { 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("/definition/task"); XMLModifier xm = new XMLModifier(vn); int i=0; while((i=ap.evalXPath())!=-1){ xm.remove(); } xm.output("output.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 } }
import com.ximpleware.*; public class removeNode { public static void main(String s[]) throws Exception{ VTDGen vg = new VTDGen(); boolean b = vg.parseFile("input.xml", false); if (b==false) return; VTDNav vn = vg.getNav(); XMLModifier xm = new XMLModifier(vn); vn.toElement(VTDNav.FC); // get to A node long l = vn.getContentFragment(); xm.remove(l); 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 merge { // merge second.xml into first.xml assuming the same encoding public static void main(String[] s) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("d:\\xml\\first.xml", false)) return; VTDNav vn1=vg.getNav(); if(!vg.parseFile("d:\\xml\\second.xml", false)) return; VTDNav vn2 = vg.getNav(); XMLModifier xm = new XMLModifier(vn1); long l = vn2.getContentFragment(); xm.insertBeforeTail(vn2, l); xm.output("d:\\xml\\merged.xml"); } }
/** * outAndReparse writes updated XML content into a new byte * array, then parse and return a new VTDNav object * @return VTDNav encapsulating update XML documents * @throws ParseException * @throws IOException * @throws TranscodeException * @throws ModifyException */ public VTDNav outputAndReparse() throws ParseException, IOException,TranscodeException,ModifyException{ XMLByteOutputStream xbos = new XMLByteOutputStream(getUpdatedDocumentSize()); output(xbos); VTDGen vg = new VTDGen(); vg.setDoc(xbos.getXML()); vg.parse(this.md.ns); return vg.getNav(); }
/** * outAndReparse writes updated XML content into a new byte * array, then parse and return a new VTDNav object * @return VTDNav encapsulating update XML documents * @throws ParseException * @throws IOException * @throws TranscodeException * @throws ModifyException */ public VTDNav outputAndReparse() throws ParseException, IOException,TranscodeException,ModifyException{ XMLByteOutputStream xbos = new XMLByteOutputStream(getUpdatedDocumentSize()); output(xbos); VTDGen vg = new VTDGen(); vg.setDoc(xbos.getXML()); vg.parse(this.md.ns); return vg.getNav(); }
/** * outAndReparse writes updated XML content into a new byte * array, then parse and return a new VTDNav object * @return VTDNav encapsulating update XML documents * @throws ParseException * @throws IOException * @throws TranscodeException * @throws ModifyException */ public VTDNav outputAndReparse() throws ParseException, IOException,TranscodeException,ModifyException{ XMLByteOutputStream xbos = new XMLByteOutputStream(getUpdatedDocumentSize()); output(xbos); VTDGen vg = new VTDGen(); vg.setDoc(xbos.getXML()); vg.parse(this.md.ns); return vg.getNav(); }
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"); } } }