if you have questions feel free to drop a mail …
Regards, Johann
import java.io.;
import java.util.;
import java.text.;
import org.w3c.dom.;
import com.docuverse.dom.;
import com.softwareag.tamino.API.dom.;
import javax.xml.transform.;
import javax.xml.transform.stream.;
import javax.xml.transform.dom.*;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
*/
public class TClientDemo {
public TClientDemo() {
}
public static void main(String args) {
try {
TClientDemo tClientDemo1 = new TClientDemo();
TaminoClient tamino = new TaminoClient(“http://localhost/tamino/xmldb”);
Integer rc;
tamino.setAcceptCharset(“UTF-8”); // the charset we want our documents to be coded
tamino.setPageSize(0); // pagesize 0 returns the result set as a whole
tamino.startSession(); // open a session
TaminoResult tr = tamino.query(“//article[//author ~= ‘stonebraker’]”, “sigmod”);
rc = new Integer(tr.getReturnValue());
if (rc.intValue() > 0) {
System.out.println(tr.toString());
}
else {
// print the title of each article found, using the DOM API
System.out.println(tr.getTotalCount() + " documents returned");
System.out.println(“-- Now using DOM API”);
Enumeration articleList = tr; // TaminoResult implements the Enumeration interface
int i = 1;
while (articleList.hasMoreElements()) {
Element el = (Element)articleList.nextElement();
System.out.print(el.getNodeName() + " " + i++ + “: “);
System.out.println(el.getElementsByTagName(“title”).item(0).getChildNodes().item(0).getNodeValue());
}
// print the title of each article found, using a style sheet and the SAXON XSLT processor
System.out.println(”-- Now using SAXON stylesheet processor”);
TransformerFactory factory = TransformerFactory.newInstance();
Templates template = factory.newTemplates(new StreamSource(new File(“sigmod.xsl”)));
Transformer transformer = template.newTransformer();
StringWriter result = new StringWriter();
transformer.transform(new DOMSource(tr.getDocument()), new StreamResult(result));
System.out.println(result.getBuffer());
// fetch ol’ Atkins from the patients in the sample collection
System.out.println(“-- Now fetching and modifying good ol’ Atkins”);
tr = tamino.query(“/patient[name/surname = ‘Atkins’]”, “sample”);
rc = new Integer(tr.getReturnValue());
if (rc.intValue() > 0) {
System.out.println(tr.toString());
}
System.out.println(tr.getTotalCount() + " documents returned");
// get the Document - we need it for creating new nodes
Document responseDoc = tr.getDocument();
// extract the patient from the whole Tamino response
Element patient = (Element)tr.getElement().getFirstChild();
// locate the tag - we need it as an anchor for locating the position of the new
Element submitted = (Element)patient.getElementsByTagName(“submitted”).item(0);
// create a new
Element examination = responseDoc.createElement(“examination”);
// create a new
Element date = responseDoc.createElement(“date”);
// create a #text node, fill it with the system date and append it to
date.appendChild(responseDoc.createTextNode(new SimpleDateFormat(“yyyyMMdd:HHmmssSSS”).format(new Date())));
// append the to
examination.appendChild(date);
// create a new , create #text node, append #text to - same as above
Element remarks = responseDoc.createElement(“remarks”);
remarks.appendChild(responseDoc.createTextNode(“this is a remark”));
examination.appendChild(remarks);
// insert into s child list, before the right sibling (if any) of submitted
patient.insertBefore(examination, submitted.getNextSibling());
// update the in Tamino
tr = tamino.update(patient, “sample”, “patient”);
rc = new Integer(tr.getReturnValue());
if (rc.intValue() > 0) {
System.out.println(tr.toString());
}
tamino.commit(false);
}
tamino.endSession(); // close the session
}
catch (TaminoError e){
System.out.println("Tamino Error Text: " + e.errorText );
System.out.println("Tamino Error Code: " + e.responseCode );
e.printStackTrace();
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
#API-Management#webMethods-Tamino-XML-Server-APIs#webMethods