Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Overwrite XML data directly using VTD-XML (See related posts)

// 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("<root>good</root>".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));
		}
	}	
}

You need to create an account or log in to post comments to this site.


Click here to browse all 7716 code snippets

Related Posts