IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Problem using Count() function with TAPI4J

  • 1.  Problem using Count() function with TAPI4J

    Posted Wed September 22, 2004 06:46 PM

    Hello,

    I’m new in the TaminoAPI4Java with XQuery.

    I need to obtain the number of documents that satisfies a XQuery. I’ve tried using the count function but, although the XQuery is correctly parsed, the result is’nt the desired.

    I better show you a simple example for an imaginary Entity called Press:

    The XQuery is:
    for $p in input()/Press, $f in $p/fecha
    where $f=“2003/05/03”
    return $p

    In my app, in order to obtain the number of documents, I transform the String as follows:
    count(
    for $p in input()/Press, $f in $p/fecha
    where $f=“2003/05/03”
    return $p)

    This XQuery with the Tamino Interactive Interface returns:
    xq:value27</xq:value>

    But the TaminoAPI4J returns:
    xq:value/

    The piece of code that performs the XQuery is:
    (…)
    tsAccessor = connection.newStreamAccessor( TAccessLocation.newInstance( inoCol ) );
    TXQuery xQuery = TXQuery.newInstance (myQuery);
    tis = tsAccessor.xquery( xQuery );
    (…)


    Do you know why? Can you help me to do this?

    Thanks in advance,

    Pau.


    Pau Garc


    #webMethods
    #webMethods-Tamino-XML-Server-APIs
    #API-Management


  • 2.  RE: Problem using Count() function with TAPI4J

    Posted Thu September 23, 2004 09:34 AM

    Hi,

    I am quite new to Tamino myself, but I have been using the count function before, it worked.

    Please try the following:

    for $p in input()/Press, $f in $p/fecha
    where $f=“2003/05/03”
    return count($p)

    Let me know how u r doing!


    #webMethods-Tamino-XML-Server-APIs
    #webMethods
    #API-Management


  • 3.  RE: Problem using Count() function with TAPI4J

    Posted Thu September 23, 2004 11:49 AM

    Hi Dax42,

    I had already tried this, but it is a different query: The number of ocurrences of each document, that is, a sequence of 1’s.

    <xq:result xmlns:xq=“http://namespaces.softwareag.com/tamino/XQuery/result”>
    xq:value1</xq:value>
    xq:value1</xq:value>

    xq:value1</xq:value>
    xq:value1</xq:value>
    </xq:result>

    Thanks for your interest,


    Pau Garc


    #API-Management
    #webMethods-Tamino-XML-Server-APIs
    #webMethods


  • 4.  RE: Problem using Count() function with TAPI4J

    Posted Thu September 23, 2004 12:53 PM

    Ah, of course.

    “for” gives you the documents one by one, so instead you could try using “let” which should give you all documents at once and therefore the appropriate number.


    #webMethods-Tamino-XML-Server-APIs
    #API-Management
    #webMethods


  • 5.  RE: Problem using Count() function with TAPI4J

    Posted Thu September 23, 2004 06:41 PM

    I have just tried the new query you suggest:

    count(let $p:=input()/Prensa where $p/fecha=“2003/05/03” return $p)

    But the result is still wrong: xq:value/

    :frowning:


    Pau Garc


    #webMethods
    #webMethods-Tamino-XML-Server-APIs
    #API-Management


  • 6.  RE: Problem using Count() function with TAPI4J

    Posted Fri September 24, 2004 08:23 AM

    Hi,

    I know I am repeating myself, but did you also try
    let $p:=input()/Prensa where $p/fecha=“2003/05/03” return count($p)
    ?

    If that doesn’t work (it should, since the counting worked with “for”, just not the way you wanted it to), I don’t know any further.
    Also, I think if that doesn’t work the problem lies within other parts of your code…


    #API-Management
    #webMethods-Tamino-XML-Server-APIs
    #webMethods


  • 7.  RE: Problem using Count() function with TAPI4J

    Posted Mon October 04, 2004 02:04 PM

    Hi,

    Yes I also tried that query and it also returned the “xq:value/” empty string. And the code seems to be correct because after doing the count I process the same query without the “count” function and I get the desired result.

    This is the piece of code which performs the query:

    TXQuery xQuery = TXQuery.newInstance(myXQuery);
    txoAccessor = connection.newXMLObjectAccessor( TAccessLocation.newInstance( inoCol ) , TJDOMObjectModel.getInstance() );
    tResponse = txoAccessor.xquery( xQuery );
    String sResult = tResponse.getQueryContentAsString()


    Any other suggestion?

    Thanks in advance,

    Pau Garc


    #webMethods-Tamino-XML-Server-APIs
    #API-Management
    #webMethods


  • 8.  RE: Problem using Count() function with TAPI4J

    Posted Wed October 06, 2004 01:23 AM

    Hello Pau,

    Try it like this:

    let $a:=count(for $p in input()/Press, $f in $p/fecha
    where $f=“2003/05/03” return $p)
    return $a

    Rob


    #API-Management
    #webMethods
    #webMethods-Tamino-XML-Server-APIs


  • 9.  RE: Problem using Count() function with TAPI4J

    Posted Fri December 10, 2004 03:54 PM

    hello

    I dont know, if you could solve your problem…but the point is:
    The method getQueryContentAsString is not working for getting the result of the count.
    Better use this:
    String myResult = “”;
    TXQuery countQuery = TXQuery.newInstance(“count(” + xquery.getExpression() + “)”);
    TResponse response = accessor.xquery(countQuery);
    TXMLObjectIterator xmlIterator = response.getXMLObjectIterator();
    while (xmlIterator.hasNext()) {
    TXMLObject xmlObject = xmlIterator.next();
    Element myElement = ((Element)xmlObject.getElement());
    myResult = myElement.getFirstChild().getNodeValue();
    }

    best regards
    Reto Peter, Software AG Schweiz


    #webMethods
    #webMethods-Tamino-XML-Server-APIs
    #API-Management


  • 10.  RE: Problem using Count() function with TAPI4J

    Posted Mon December 13, 2004 09:42 AM

    Hello,

    I solved the problem in a similar way.

    Thanks for your interest.

    Best Regards,

    Pau Garc


    #webMethods
    #API-Management
    #webMethods-Tamino-XML-Server-APIs


  • 11.  RE: Problem using Count() function with TAPI4J

    Posted Fri June 02, 2006 10:45 AM

    Hola pau, me ocurre el mismo problema que a te ocurria a ti, como lo has solucionado??, he probado todo lo que dicen aqui pero no me ha funcionado nada :frowning:

    gracias y un saludo


    #API-Management
    #webMethods
    #webMethods-Tamino-XML-Server-APIs