Hi,
If I make an interaktive query with the Tamino XQuery-Tool I get the following result:
<?xml version="1.0"?>
<xq:attribute doc_id=“d883”/>
The query is:
let
$did:=input()/directory/host[@name=‘ahost2’]/host[@name=‘bhost2’]/host[@name=‘chost5’]/path[@name=‘apath2’]/path[@name=‘bpath2’]/path[@name=‘cpath3’]/path[@name=‘d883.xml’]/doc_info/@doc_id
return $did
but if I make the same query with a TXMLObjectAccessor the TResponse Object has only the following data (empty element)
‘xq:attribute/’
but I need the doc_id…
any suggestions??
Thanx
Markus
Hello Markus,
which object model are you using with the TXMLObjectAccessor - is it the TDOMObjectModel?
Could you please post your code?
Thanks,
Trevor.
Hello Trevor,
yes, I’m using the TDOMObjectModel…
here is the code:
String xqueryString = “let $did:=input()/directory/host[@name=‘ahost2’]/host[@name=‘bhost2’]/host[@name=‘chost5’]/path[@name=‘apath2’]/path[@name=‘bpath2’]/path[@name=‘cpath3’]/path[@name=‘d883.xml’]/doc_info/@doc_id return $did”;
TXMLObjectAccessor xmlObjectAccessor = connection.newXMLObjectAccessor(
TAccessLocation.newInstance( “ino:etc” ),
TDOMObjectModel.getInstance() );
TXQuery xquery = TXQuery.newInstance( xqueryString );
System.out.println("T-XQuery: " + xquery.toString());
try {
TResponse response = xmlObjectAccessor.xquery( xquery);
TXMLObjectIterator iterator = response.getXMLObjectIterator();
System.out.print( “The query "” + xqueryString + "" returns " );
if (!iterator.hasNext()) {
System.out.println( “no data!” );
} else {
while (iterator.hasNext()) {
TXMLObject xmlObject = iterator.next();
System.out.print( " count: " +iterator.getCount() );
}
}
String xqueryResult = xmlObjectAccessor.xquery( xquery ).getQueryContentAsString() ;
System.out.println("T-XQuery Result: " + xqueryResult);
return xqueryResult;
} catch (TXQueryException tqe) {
System.out.println( "T-XQuery FEHLER: " + tqe.toString() );
}
catch (TException te) {
System.out.println( "T-XQuery FEHLER: " + te.toString() );
}
I hope this helps
Markus
Hi Markus,
it looks like the “getQueryContentAsString()” method is not doing what you and I would expect here. You should open a request with your local Customer Support Center about this.
In the meantime, you could use the “writeTo” method of the TXMLObject class to output the desired result:
if (!iterator.hasNext()) {
System.out.println( "no data!" );
} else {
while (iterator.hasNext()) {
TXMLObject xmlObject = iterator.next();
// TFO added these two lines ////////////
System.out.println("\n\nresult: "); //
xmlObject.writeTo(System.out); //
/////////////////////////////////////////
System.out.print( "\n\n count: " + iterator.getCount() );
}
}
Cheers,
Trevor.
Hi Trevor,
thank you for your answer
I tried your workaround with the ‘writeTo’-method…
…and now it works
but: what for is the .getQueryContenAsString() method ??? I’ll request my support…
Thanx
Markus