import java.io.InputStream;
import java.io.OutputStream;
import com.ximpleware.VTDGen;
import com.ximpleware.VTDNav;
import com.ximpleware.XMLModifier;
OutputStream objectFileOutputStream = null;
try {
// Get the value from context variable
String generatedOnServerName = (String) context.get("setVariable");
VTDGen vg = new VTDGen(); // Instantiate VTDGen
XMLModifier xm = new XMLModifier(); // Instantiate XMLModifier
//Read the input stream
byte[] data = new byte[inputStream.available()];
inputStream.read(data);
vg.setDoc(data);
vg.parse(false);
VTDNav vn = vg.getNav();
xm.bind(vn);
// first update the value of attr
int i = vn.getAttrVal("attr");
if (i != -1) {
xm.updateToken(i, "value");
}
// navigate to Tag Name where tag will be added
if (vn.toElement(VTDNav.FC, "XFRDOCS")) {
// update the text content of
i = vn.getText();
if (i != -1) {
xm.updateToken(i, " new content ");
}
// insert an element before (which is the cursor
// element)
xm.insertBeforeElement("\n\t"
+ generatedOnServerName
+ "");
}
objectFileOutputStream = service.getOutputStream();
xm.output(objectFileOutputStream);
} catch (Exception e) {
e.printStackTrace();
throw e;
}