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
  • 1.  Tamino API and XSL

    Posted Tue August 27, 2002 09:07 PM

    I am converting a program I wrote using the Tamino 2.x API to the new Tamino 3.x API and I am running into a problem regarding the Document. I have figured out how to get the whole document back (including the ino:response), and managed to put it into a Document (using org.w3c.dom.Document). How can I convert this to a String format? I am having problems with the conversion. I need to pass the string to the JAXP Parsers that I am using.

    Any help or recommendation is appreciated.

    Thanks,

    Brian Garner

    Thanks,

    Brian Garner
    Advisory Systems Engineer, Softtware AG Canada
    416.364.1133 x.261 office


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


  • 2.  RE: Tamino API and XSL

    Posted Wed August 28, 2002 12:04 PM

    Hi Brian, if you use DOM then the implementation of the DOM doesn’t really support converting the Document into a string. If you try you will get a string like: “[#document: null]”. This seems to be a feature of xerces.

    The new API supports JAXP : so can you tell me why you need to convert your document to a string for further parsing? What is it you are trying to achieve?

    My advice if you really need to get a string representation of the Tamino response is to use a TStreamAccessor. By querying Tamino, all you get back is a TInputStream and you can use the read() method to get back the bytes of the whole Tamino response document.


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


  • 3.  RE: Tamino API and XSL

    Posted Thu August 29, 2002 03:34 PM

    Stuarts right, the DOM implement standard doesn’t support serializing to a String, but if you are using Apache you can use the following code.

    import org.apache.xalan.serialize.;
    import org.w3c.dom.
    ;


    org.w3c.dom.Document doc = …
    // Convert DOM into a String
    StringWriter sw = new StringWriter();
    SerializerToXML serxml = new SerializerToXML();
    serxml.setWriter(sw);
    serxml.serialize(doc );
    serxml.flushWriter();
    System.out.println( sw.toString() ):


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


  • 4.  RE: Tamino API and XSL

    Posted Thu August 29, 2002 05:35 PM

    Because xerces is used by TaminoAPI4J another way would be as follows (without requiring xalan):

    import org.apache.xml.serialize.;
    import java.io.
    ;


    org.w3c.dom.Document doc = …
    // Convert document to string
    StringWriter sw = new StringWriter();
    XMLSerializer serxml = new XMLSerializer();
    serxml.setOutputCharStream (sw);
    serxml.serialize(d);
    System.out.println(sw.toString()) ;


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


  • 5.  RE: Tamino API and XSL

    Posted Thu August 29, 2002 10:50 PM

    Thanks for the previous replies.

    What I am trying to do is convert an old program I wrote using the Tamino 2.x API to the new Tamino 3.x Java API. I figured I would get the Document back from Tamino as a DOM and serialize it to a string:

    serializer.setOutputCharStream(returnedQuery);
    serializer.serialize(TaminoDOMdoc);
    // for XML display testing purposes
    //out.print(returnedQuery.toString());

    This prints the XML document to the Web page perfectly. When I try and use the JAXP 1.0 API from Sun and apply a Stylesheet, I get the following error displayed in my Java Servlet on screen:
    java.net.MalformedURLException: no protocol: <?xml version="1.0"?>

    My Java Servlet code snippet is the following:

    TransformerFactory tFactory = TransformerFactory.newInstance();
    // Get the XML input document and the stylesheet.
    Source xmlSource = new StreamSource(returnedQuery.toString());
    Source xslSource = new StreamSource(Liststylesheet);
    // Generate the transformer.
    Transformer transformer = tFactory.newTransformer(xslSource);
    // Perform the transformation, sending the output to the response.
    transformer.transform(xmlSource, new StreamResult(out));

    Seems that the error happens at transformer.transform(xmlSource, new StreamResult(out));

    All I want to do is apply a Stylesheet (Liststylesheet) to the XML Document (returnedQuery.toString())

    If anyone has any suggestions on why this is not working, or if I should do it a better way, please let me know.

    I know that the styleesheet and XML file work, because if I copy the displayed XML to XML Spy and apply the exact Stylesheet, it renders perfectly.

    Thanks in advance,


    Brian Garner

    Thanks,

    Brian Garner
    Advisory Systems Engineer, Softtware AG Canada
    416.364.1133 x.261 office


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


  • 6.  RE: Tamino API and XSL

    Posted Fri August 30, 2002 12:09 PM

    Try changing the following line.

    // Get the XML input document and the stylesheet.
    Source xmlSource = new StreamSource(returnedQuery.toString());


    To →

    // Get the XML input document and the stylesheet.
    Source xmlSource = new StreamSource(new StringReader(returnedQuery.toString()));


    May need to also change your XSL source input depending on its type. An alternative approach would be to use the Tamino Pass-Thru Servlet.


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


  • 7.  RE: Tamino API and XSL

    Posted Fri August 30, 2002 07:52 PM

    Thanks Karl,

    It is now working. Seems that the change did the trick.

    Thanks again,


    Brian Garner

    Thanks,

    Brian Garner
    Advisory Systems Engineer, Softtware AG Canada
    416.364.1133 x.261 office


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