p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 (http://p2p.wrox.com/forumdisplay.php?f=398)
-   -   Pass generate multiple XML documents to Java Method/Web Service (http://p2p.wrox.com/showthread.php?t=89432)

Sandeep_Kumar February 25th, 2013 01:36 PM

Pass generate multiple XML documents to Java Method/Web Service
 
Hi, I have a requirement where the application receives updates in the form of XML from upstream and before sending it to the down stream client the XML needs to be validated and if there are any data issues, I need to generate two XML documents, one error XML to the upstream client and a second XML notification to the down stream client. I am keen on using result-document element but I cannot really create files. Is there way to pass the generated XML's to a Java method by using extensions or calling local jersey web service to post the XML from result-document.

I am trying to figure out if its a possibility or not.

Sandeep_Kumar February 25th, 2013 06:59 PM

Was able to figure out alternate solution using XSLT 1.0. But still looking for any better solutions.

Code:

                <!--====To generate a separate xml, create variable containing XML== -->
                <xsl:variable name="noticeXML">
                        <xsl:element name="Order">
                                <!-- Create the required attributes and elements -->
                        </xsl:element>
                </xsl:variable>
                <!--========Pass the variable to Java method===-->
                <xsl:value-of select="util:toXML($noticeXML)"/>


          //Java method to convert received 'Node' to stand alone XML and send to Client
        public static synchronized void toXML(Node xml) throws TransformerException
        {
                StringWriter writer = new StringWriter();
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            //Do not set declaration as its indicating the XML is not stand alone
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            transformer.transform(new DOMSource(xml), new StreamResult(writer));
            String receivedxml = writer.toString();
            //Send the message to the required client. 
        }



All times are GMT -4. The time now is 12:26 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.