/** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param vn * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(VTDNav vn, long l1) throws ModifyException, UnsupportedEncodingException, NavException, TranscodeException { insertAfterElement(vn.encoding, vn.XMLDoc.getBytes(), l1); }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded array of bytes of a segment of the byte array b after the element * the VTDNav object is the container of the XML document in byte array * * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(VTDNav vn, int contentOffset, int contentLen) throws ModifyException, UnsupportedEncodingException, NavException,TranscodeException { insertAfterElement(vn.encoding,vn.XMLDoc.getBytes(),contentOffset, contentLen); } /**
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param vn * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(VTDNav vn, long l1) throws ModifyException, UnsupportedEncodingException, NavException, TranscodeException { insertAfterElement(vn.encoding, vn.XMLDoc.getBytes(), l1); }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param vn * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(VTDNav vn, long l1) throws ModifyException, UnsupportedEncodingException, NavException, TranscodeException { insertAfterElement(vn.encoding, vn.XMLDoc.getBytes(), l1); }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded array of bytes of a segment of the byte array b after the element * the VTDNav object is the container of the XML document in byte array * * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(VTDNav vn, int contentOffset, int contentLen) throws ModifyException, UnsupportedEncodingException, NavException,TranscodeException { insertAfterElement(vn.encoding,vn.XMLDoc.getBytes(),contentOffset, contentLen); } /**
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded array of bytes of a segment of the byte array b after the element * the VTDNav object is the container of the XML document in byte array * * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(VTDNav vn, int contentOffset, int contentLen) throws ModifyException, UnsupportedEncodingException, NavException,TranscodeException { insertAfterElement(vn.encoding,vn.XMLDoc.getBytes(),contentOffset, contentLen); } /**
import com.ximpleware.*; import java.io.*; public class simpleMod { 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),ap2=new AutoPilot(vn); ap.selectXPath("/employees/employee[@ID='1']/Salary"); ap2.selectXPath("../../employee[@ID='2'"); int i=ap.evalXPath(); if (i==-1) return; xm.insertAfterElement("<Address>10th cross, Park Avenue</Address>"); i=ap2.evalXPath(); if (i==-1) return; xm.insertAfterElement(" <Employee ID=\"3\">\n<Firstname>Holly</Firstname>\n<Lastname>Becker</Lastname>\n<Age>24</Age>\n<Salary>30000</Salary>\n</Employee>"); xm.output("output.xml"); } }
mod.insertAfterElement(versionLine.toString());
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.insertAfterElement(prettyXml); mod.remove();
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b (transcode into a byte array) after the element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b, long l1) throws ModifyException, UnsupportedEncodingException, NavException, TranscodeException { if (src_encoding == encoding){ insertAfterElement(b,l1); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); byte[] bo = Transcoder.transcode(b, (int)l, (int)l>>32, src_encoding, encoding); insertBytesAt(offset + len, bo, l1); } }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b (transcode into a byte array) after the element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b, long l1) throws ModifyException, UnsupportedEncodingException, NavException, TranscodeException { if (src_encoding == encoding){ insertAfterElement(b,l1); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); byte[] bo = Transcoder.transcode(b, (int)l, (int)l>>32, src_encoding, encoding); insertBytesAt(offset + len, bo, l1); } }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded array of bytes of a segment of the byte array b after the element * @param b * @param contentOffset * @param contentLen * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b, int contentOffset, int contentLen) throws ModifyException, NavException,TranscodeException { if (src_encoding == encoding) { insertAfterElement(b,contentOffset,contentLen); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); // transcode in here byte[] bo = Transcoder.transcode(b, contentOffset, contentLen, src_encoding, encoding); insertBytesAt(offset + len, bo); } }
/** * Insert a byte array of given encoding into the master document * transcoding is done underneath to ensure the correctness of output * @param src_encoding The encoding format of the byte array * @param b * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b) throws ModifyException, NavException,TranscodeException { if(src_encoding == encoding){ insertAfterElement(b); } else { int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int)l; int len = (int)(l>>32); // transcoding logic byte[] bo = Transcoder.transcode(b, 0, b.length, src_encoding, encoding); insertBytesAt(offset+len,bo); } } /**
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded array of bytes of a segment of the byte array b after the element * @param b * @param contentOffset * @param contentLen * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b, int contentOffset, int contentLen) throws ModifyException, NavException,TranscodeException { if (src_encoding == encoding) { insertAfterElement(b,contentOffset,contentLen); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); // transcode in here byte[] bo = Transcoder.transcode(b, contentOffset, contentLen, src_encoding, encoding); insertBytesAt(offset + len, bo); } }
/** * Insert a byte array of given encoding into the master document * transcoding is done underneath to ensure the correctness of output * @param encoding The encoding format of the byte array * @param b * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b) throws ModifyException, NavException,TranscodeException { if(src_encoding == encoding){ insertAfterElement(b); } else { int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int)l; int len = (int)(l>>32); // transcoding logic byte[] bo = Transcoder.transcode(b, 0, b.length, src_encoding, encoding); insertBytesAt(offset+len,bo); } } /**
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded array of bytes of a segment of the byte array b after the element * @param b * @param contentOffset * @param contentLen * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b, int contentOffset, int contentLen) throws ModifyException, NavException,TranscodeException { if (src_encoding == encoding) { insertAfterElement(b,contentOffset,contentLen); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); // transcode in here byte[] bo = Transcoder.transcode(b, contentOffset, contentLen, src_encoding, encoding); insertBytesAt(offset + len, bo); } }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b (transcode into a byte array) after the element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b, long l1) throws ModifyException, UnsupportedEncodingException, NavException, TranscodeException { if (src_encoding == encoding){ insertAfterElement(b,l1); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); byte[] bo = Transcoder.transcode(b, (int)l, (int)l>>32, src_encoding, encoding); insertBytesAt(offset + len, bo, l1); } }
/** * Insert a byte array of given encoding into the master document * transcoding is done underneath to ensure the correctness of output * @param encoding The encoding format of the byte array * @param b * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterElement(int src_encoding, byte[] b) throws ModifyException, NavException,TranscodeException { if(src_encoding == encoding){ insertAfterElement(b); } else { int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int)l; int len = (int)(l>>32); // transcoding logic byte[] bo = Transcoder.transcode(b, 0, b.length, src_encoding, encoding); insertBytesAt(offset+len,bo); } } /**
xm.insertAfterElement("\n\t<c/>");