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());
}
}