Over a million developers have joined DZone.

Overwrite XML Data Directly Using VTD-XML

·
// description of your code here
// This example shows you how to overwrite a token using 
// VTDNav's overwrite method call
// The basic concept is that if the replacement value is
// shorter than the original token, then you can directly
// write the replacement bytes into the XML message and
// the original VTD structure doesn't change at all!!!


import com.ximpleware.*;
class Overwrite{

	public static void main(String s[]) throws Exception{
		VTDGen vg = new VTDGen();
		vg.setDoc("good".getBytes());
		vg.parse(true);
		VTDNav vn = vg.getNav();
		int i=vn.getText();
		//print "good"
		System.out.println("text ---> "+vn.toString(i));
		if (vn.overWrite(i,"bad".getBytes())){
			//overwrite, if successful, returns true
			//print "bad" here 
			System.out.println("text ---> "+vn.toString(i));
		}
	}	
}
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}