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.


#TechXchangePresenter
 View Only
  • 1.  Getting "node" value?

    Posted Tue July 16, 2002 05:13 AM

    Hi, is there anyway to get node value and not to display the tag?

    If my query result reutrns:
    ABC

    How can I just display “ABC”?

    Must I use DOM?


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


  • 2.  RE: Getting "node" value?

    Posted Tue July 16, 2002 07:58 AM

    Hi KAren,

    I’m afraid it’s me again…
    It is possible to extract the result you want without using DOM (or SAX, for that matter).

    You can use a combination of the string() function in the X-Query and the getQueryContentAsString() method of the TResponse class.
    For example, if the query to get ABC is:
       /TCM/RIREG/NAME[…/ID=1]
    then convert it to this:
       string(/TCM/RIREG/NAME[…/ID=1])

    Then change your Java code to something like this:
       TConnection conn = TConnectionFactory.getInstance().newConnection(URI);
       TAccessLocation tal = TAccessLocation.newInstance(“xmldb”);
       TXMLObjectAccessor xmlAccessor = conn.newXMLObjectAccessor(tal,
                                                                TDOMObjectModel.getInstance());
       TResponse tr = xmlAccessor.query(TQuery.newInstance(“string(/Message)”));
       System.out.println(“Result: "” + tr.getQueryContentAsString() + “"”);

    I think that this will put you on the right track.

    Cheers,
    Trevor.


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


  • 3.  RE: Getting "node" value?

    Posted Tue July 16, 2002 08:58 AM

    Hey Trevor!

    I’m glad that you replied. :wink:

    I’ve tried what you suggested. The outcome was:




    The part where you change the query to string, I think it’s the same. Both display the same results.

    I went to check the method getQueryContentAsString(), it says: If the result is a value or a set of values, the string returned is the concatenation of these values.

    Anyway, the codes I’m using are:

    //Instantiate an empty TXMLObject instance using the DOM object model
    TXMLObject xmlObject = TXMLObject.newInstance(TDOMObjectModel.getInstance());

    //Establish the Tamino connection
    TConnection connection = TConnectionFactory.getInstance().newConnection(DATABASE_URI);

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


    //Invoke the query operation
    TQuery query = TQuery.newInstance(docName + “[//RIREG~=‘" + name + "’]/ID”);
    TResponse response = xmlObjectAccessor.query(query);

    TXMLObjectIterator myIterator = response.getXMLObjectIterator();


    while (myIterator.hasNext())
    {
    TXMLObject xmlObjectReturned = myIterator.next();
    xmlObjectReturned.writeTo(stringWriter);
    stringWriter.write(“\n”);
    searchCount++;
    }

    //Print out the results and number of results are returned
    //System.out.println(stringWriter);
    System.out.println(response.getQueryContentAsString());
    System.out.println("Number: " + searchCount);

    Thank you for your help,
    -KAren-
    :cool:


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


  • 4.  RE: Getting "node" value?

    Posted Tue July 16, 2002 05:06 PM

    Hey KAren,

    I’m not sure where we should go from here.

    The query you are using in your code is quite likely to return multiple documents - it uses the ~= and wildcards…

    What would you like to have the query return - the list of ID values (not ino:id, but the ID element) without the tags?

    Cheers,
    Trevor.


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


  • 5.  RE: Getting "node" value?

    Posted Wed July 17, 2002 07:24 PM

    Hi KAren,

    I’m going to take a risk and say that I don’t think it is possible to do this with a single XPath expression.
    (Though better heads than mine may easily prove me wrong!)

    I think that there are a number of options open to you:
       * remove the tags from the result using XSL
       * expand your existing code
       * dive into W3C XQuery…

    If you choose the third option, you can try using the “QuiP” tool to execute XQuery against Tamino.
    (See this forum.)

    TF.


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


  • 6.  RE: Getting "node" value?

    Posted Thu July 18, 2002 04:35 AM

    Hey Trevor,

    Do you think it’s possible to use DOM to extract out the values?

    Just a crazy thought,
    -KAren-
    :rolleyes:


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


  • 7.  RE: Getting "node" value?

    Posted Thu July 18, 2002 11:41 PM

    Hi KAren,

    sure - you can do it easily with the DOM.

    Your existing code contains this chunk:
    while (myIterator.hasNext())
    {
       TXMLObject xmlObjectReturned = myIterator.next();
       xmlObjectReturned.writeTo(stringWriter);
       stringWriter.write(“\n”);
       searchCount++;
    }

    Perhaps this is what you need:
    while ( myIterator.hasNext() ) {
       TXMLObject xmlObjectReturned = myIterator.next();
       Element el = (Element)xmlObjectReturned.getElement();
       // The value is the first child…
       Node val = el.getFirstChild();
       System.out.println(“\t” + val.getNodeValue());
    }

    (You’ll need to import Element & Node from the org.w3c.dom package.)

    I hope this helps you out!
    Trevor.


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


  • 8.  RE: Getting "node" value?

    Posted Sat July 20, 2002 07:41 AM

    Hi Trevor!

    Thanks for helping me out all the time!

    I took one of your advices. I wrote a program out to remove the tag. It works…it just need a little brain exercise and that will do the trick.

    Thank you once again!
    -KAren-
    :smiley:


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