Hello!
How can I retrieve the following values:
1) @ino:sessionid
2) @ino:sessionkey
3) @ino:returnvalue
?
Here is my code:
-----------------------------------
import java.util.;
import org.w3c.dom.;
import com.softwareag.tamino.API.dom.*;
public class ino {
public static final void main(String arg) throws Exception
{
String myQuery = “doc[id_client<‘12345’] sortby(id_client desc)”;
String myURL = “http://localhost/tamino/mydb/col”;
int intPageSize = 1;
TaminoClient tc = new TaminoClient(myURL);
tc.setPageSize(intPageSize);
tc.startSession();
try {
TaminoResult tr = tc.query(myQuery);
System.out.println(“myURL=” +myURL);
System.out.println(“myQuery=” +myQuery);
Document dc = tr.getDocument();
Element el = dc.getDocumentElement();
tc.printTree(el);
String strValue = el.getElementsByTagName(“@ino:returnvalue”).item(0).getChildNodes().item(0).getNodeValue();
System.out.println(“ino:returnvalue = " +strValue);
String strId = el.getElementsByTagName(”@ino:sessionid").item(0).getNodeValue();
System.out.println(“ino:sessionid = " +strId);
String strKey = el.getElementsByTagName(”@ino:sessionkey").item(0).getNodeValue();
System.out.println(“ino:sessionkey = " +strKey);
tc.endSession();
}
catch (com.softwareag.tamino.API.dom.TaminoError er) {
System.out.println(“TAMINO ERROR CODE=” +er.responseCode+”\n"+
“TAMINO ERROR TEXT=” +er.errorText);
}
}
}
-----------------------------------
Unfortunately I got the following exception: “Exception in thread “main” java.lang.NullPointerException at ino.main(ino.java:21)
So it means that at least the following line is incorrect:
—
String strValue = el.getElementsByTagName(”@ino:returnvalue").item(0).getChildNodes().item(0).getNodeValue();
—
Method “printTree” of object “tc” (of type “TaminoClient”) wrote me the following text:
-------------------------------------------------
–ino:response
?–@xmlns:ino=http://namespaces.softwareag.com/tamino/response2
?–@xmlns:xql=http://metalab.unc.edu/xql/
?–@ino:sessionid=16
?–@ino:sessionkey=20032
?–xql:query
? ?–#text doc[id_client<‘12345’] sortby(id_client desc)
?
?–ino:message
?–@ino:returnvalue=0
?–ino:messageline
?–#text XQL Request processed, no object returned
-------------------------------------------------
thanks in advance!
best regards,
Dariusz Baumann
The reason for the NullPointerException is that the getElementsByTagName will return an empty list because the ino:returnvalue in this case is an attribute and not an element.
So the following fragment would work:-
TaminoResult tr = tc.query (DOCTYPE) ;
…
Document root = tr.getDocument() ;
Element response = (Element)root.getElementsByTagName(“ino:response”).item(0) ;
String sessionkey = response.getAttributeNode(“ino:sessionkey”).getFirstChild().getNodeValue().toString() ;
Hope this helps.
Stuart Fyffe-Collins
Software AG (UK) Ltd.
Hello Stuart Fyffe-Collins!
Yes, you are right!
Now it works well.
thanks a lot for support!
best regards,
Dariusz Baumann
PS.
Here is my code:
---------------------------------------
import java.util.;
import org.w3c.dom.;
import com.softwareag.tamino.API.dom.*;
public class ino {
public static final void main(String arg) throws Exception
{
String myQuery = “doc[id_client<‘12345’] sortby(id_client desc)”;
String myURL = “http://localhost/tamino/mydb/col”;
int intPageSize = 1;
TaminoClient tc = new TaminoClient(myURL);
tc.setPageSize(intPageSize);
tc.startSession();
try {
TaminoResult tr = tc.query(myQuery);
System.out.println(“myURL=” +myURL);
System.out.println(“myQuery=” +myQuery);
Document dc = tr.getDocument();
//ino:sessionkey
Element responseKey = (Element)dc.getElementsByTagName(“ino:response”).item(0) ;
String sessionkey = responseKey.getAttributeNode(“ino:sessionkey”).getFirstChild().getNodeValue().toString();
System.out.println(“ino:sessionkey=” +sessionkey);
//ino:sessionid
Element responseId = (Element)dc.getElementsByTagName(“ino:response”).item(0);
String sessionid = responseId.getAttributeNode(“ino:sessionid”).getFirstChild().getNodeValue().toString();
System.out.println(“ino:sessionid=” +sessionid);
//ino:returnvalue
Element responseValue = (Element)dc.getElementsByTagName(“ino:message”).item(0);
String returnValue = responseValue.getAttributeNode(“ino:returnvalue”).getFirstChild().getNodeValue().toString();
System.out.println(“ino:returnvalue=” +returnValue);
tc.endSession();
}
catch (com.softwareag.tamino.API.dom.TaminoError er) {
System.out.println(“TAMINO ERROR CODE=” +er.responseCode+“\n”+
“TAMINO ERROR TEXT=” +er.errorText);
}
}
}
---------------------------------------