Operation on result set - I don't get it!

Hi,

this one’s not classpath related, I hope!

Objective: Retrieve two Telephone entries and output the LoginName of each.

I thought the XMLObjectIterator provides ways and means to iterate through the result set. Yet, with the code below, no matter how hard I try, it seems I always get the whole ino:response document from method TXMLObject.getDocument() . (I think I get back the whole, because there are two LoginName elements output.)

This is despite the fact that TXMLObject.writeTo() returns one Document.

I am quite clueless, please help!

Best regards, Andreas

code:

TConnection connection = TConnectionFactory.getInstance().newConnection(serverurl);

TLocalTransaction localTransaction = connection.useLocalTransactionMode();
// Obtain a TXMLObjectAccessor with a DOM object model
TXMLObjectAccessor xmlObjectAccessor = connection.newXMLObjectAccessor(TAccessLocation.newInstance( “Telephone” ),TDOMObjectModel.getInstance() );

TXPath xpath= TXPath.newInstance(“Telephone[EntryID betw 141, 151]”);
System.out.println(“Retrieving telephone entries”);
TResponse response = xmlObjectAccessor.query(xpath, 100);

System.out.println("Has query content? "+response.hasQueryContent());
System.out.println(“ReturnCode: “+response.getReturnValue());
TXMLObjectIterator iterator = response.getXMLObjectIterator();

if (iterator != null) {

Vector docs = new Vector();

while (iterator.hasNext()) {

TXMLObject xmlobj = iterator.next();
System.out.println(xmlobj.getId()+”:”);
docs.add(xmlobj);
System.out.println(“docs.size()”+docs.size());
}


TXMLObject xml0 = (TXMLObject) docs.get(0);
TXMLObject xml1 = (TXMLObject) docs.get(1);

System.out.println(“xml0”);
xml0.writeTo(System.out);
System.out.println();
System.out.println(“xml1”);
xml1.writeTo(System.out);

Document doc0 = (Document) xml0.getDocument();
Document doc1 = (Document) xml1.getDocument();

NodeList list0 = doc0.getElementsByTagName(“LoginName”);
System.out.println("list0.getLength()= "+list0.getLength());
if (list0.getLength() > 0) {
Element login = (Element) list0.item(0);
Text name = (Text) login.getFirstChild();
System.out.println("1 LoginName= "+name.getData());
login = (Element) list0.item(1);
name = (Text) login.getFirstChild();
System.out.println("2 LoginName= "+name.getData());
}
}

Hi,

I think I “solved” it. It seems, you have to take TXMLObject’s getElement() method to get to a single document (of type Telephone) in the result set. getDocument() seems to always return the complete ino:response.

This seems counter-intuitive: I already iterate through the result set, I did not expect to see the complete response at this point in the API. But I guess this method’s there because there is good reason for. I hope an example in the release version of the doc will make this clear.

Best regards, Andreas

Only to confirm this: Yes, getElement() is the correct method to use. If you imagine the result from Tamino as a DOM Tree, getDocument() will give you the root node of the whole thing and getElement() will give you the root node of the specific document you are looking for, within the tree.