/** * This method will insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the head of cursor element, * @param vn * @param contentOffset in byte * @param contentLen in byte * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(VTDNav vn, int contentOffset, int contentLen) throws ModifyException, NavException,TranscodeException { insertAfterHead(vn.encoding,vn.XMLDoc.getBytes(),contentOffset, contentLen); }
/** * This method will insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the head of cursor element, * @param vn * @param contentOffset in byte * @param contentLen in byte * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(VTDNav vn, int contentOffset, int contentLen) throws ModifyException, NavException,TranscodeException { insertAfterHead(vn.encoding,vn.XMLDoc.getBytes(),contentOffset, contentLen); }
/** * This method will insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the head of cursor element, * @param vn * @param contentOffset in byte * @param contentLen in byte * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(VTDNav vn, int contentOffset, int contentLen) throws ModifyException, NavException,TranscodeException { insertAfterHead(vn.encoding,vn.XMLDoc.getBytes(),contentOffset, contentLen); }
/** * This method will insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the head of cursor element, * @param vn * @param l1 * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(VTDNav vn, long l1) throws ModifyException, NavException, TranscodeException { insertAfterHead(vn.encoding, vn.XMLDoc.getBytes(), l1); }
/** * This method will insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the head of cursor element, * @param vn * @param l1 * @return * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(VTDNav vn, long l1) throws ModifyException, NavException, TranscodeException { insertAfterHead(vn.encoding, vn.XMLDoc.getBytes(), l1); }
/** * This method will insert a segment of the byte array b (contained in vn, and * transcode into a byte array) after the head of cursor element, * @param vn * @param l1 * @return * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(VTDNav vn, long l1) throws ModifyException, NavException, TranscodeException { insertAfterHead(vn.encoding, vn.XMLDoc.getBytes(), l1); }
/** * This method will insert byte content of string right before the tail of cursor element, * @param s * @throws ModifyException * @throws NavException */ public void insertBeforeTail(String s) throws ModifyException,UnsupportedEncodingException,NavException { long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); // handle empty element case // <a/> would become <a>b's content</a> // so there are two insertions there insertAfterHead(s.getBytes(charSet)); return; } insertBytesAt((int)i,s.getBytes()); } /**
/** * This method will insert byte content of string right before the tail of cursor element, * @param s * @throws ModifyException * @throws NavException */ public void insertBeforeTail(String s) throws ModifyException,UnsupportedEncodingException,NavException { long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); // handle empty element case // <a/> would become <a>b's content</a> // so there are two insertions there insertAfterHead(s.getBytes(charSet)); return; } insertBytesAt((int)i,s.getBytes()); } /**
/** * This method will insert a namespace compensated fragment before the tail of cursor element, * @param ef * @throws ModifyException * @throws NavException */ public void insertBeforeTail(ElementFragmentNs ef) throws ModifyException, NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(ef); return; } insertElementFragmentNsAt((int)i, ef); }
/** * This method will insert a namespace compensated fragment before the tail of cursor element, * @param ef * @throws ModifyException * @throws NavException */ public void insertBeforeTail(ElementFragmentNs ef) throws ModifyException, NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(ef); return; } insertElementFragmentNsAt((int)i, ef); }
/** * This method will insert a namespace compensated fragment before the tail of cursor element, * @param ef * @throws ModifyException * @throws NavException */ public void insertBeforeTail(ElementFragmentNs ef) throws ModifyException, NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(ef); return; } insertElementFragmentNsAt((int)i, ef); }
/** * This method will insert a segment of the byte array before the tail of cursor element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b, long l) throws ModifyException,NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(b,l); return; } insertBytesAt((int)i,b,l); } /**
/** * This method will insert a segment of the byte array before the tail of cursor element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b, long l) throws ModifyException,NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(b,l); return; } insertBytesAt((int)i,b,l); } /**
/** * This method will insert a segment of the byte array before the tail of cursor element, * @param b * @param offset * @param len * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b, int offset, int len) throws ModifyException,NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(b, offset, len); return; } insertBytesAt((int)i,b,offset, len); } /**
/** * This method will insert byte array b right before the tail of cursor element, * @param b * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b) throws ModifyException,NavException { long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); // handle empty element case // <a/> would become <a>b's content</a> // so there are two insertions there insertAfterHead(b); return; } insertBytesAt((int)i,b); } /**
/** * This method will insert byte array b right before the tail of cursor element, * @param b * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b) throws ModifyException,NavException { long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); // handle empty element case // <a/> would become <a>b's content</a> // so there are two insertions there insertAfterHead(b); return; } insertBytesAt((int)i,b); } /**
/** * This method will insert a segment of the byte array before the tail of cursor element, * @param b * @param offset * @param len * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b, int offset, int len) throws ModifyException,NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(b, offset, len); return; } insertBytesAt((int)i,b,offset, len); } /**
/** * This method will insert a segment of the byte array before the tail of cursor element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b, long l) throws ModifyException,NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(b,l); return; } insertBytesAt((int)i,b,l); } /**
/** * This method will insert a segment of the byte array before the tail of cursor element, * @param b * @param offset * @param len * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b, int offset, int len) throws ModifyException,NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(b, offset, len); return; } insertBytesAt((int)i,b,offset, len); } /**
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"); } } }