8 Replies Latest reply: Apr 15, 2013 7:24 AM by Richa Juneja RSS

    How to break XMl payload

    BK574
      Hi All,
      I have a requirement where I have to break the incoming message into parts, where each part will be sent into JMS queue as a single message.

      For ex:

      Currently I am getting following as a output from one service
      <ns1:ABCdataCollection>
      <ns1:ABCdata>
      <ns1:JobId>8786</ns1:JobId>
      <ns1:Message>aaaaaaa</ns1:Message>
      </ns1:ABCdata>
      <ns1:ABCdata>
      <ns1:JobId>8787</ns1:JobId>
      <ns1:Message>bbbbbb</ns1:Message>
      </ns1:ABCdata>
      <ns1:ABCdata>
      <ns1:JobId>8788</ns1:JobId>
      <ns1:Message>ccccccc</ns1:Message>
      </ns1:ABCdata>
      <ns1:ABCdata>
      <ns1:JobId>8789</ns1:JobId>
      <ns1:Message>dddddddd</ns1:Message>
      </ns1:ABCdata>
      <ns1:ABCdata>
      <ns1:JobId>8790</ns1:JobId>
      <ns1:Message>eeeeeee</ns1:Message>
      </ns1:ABCdata>
      </ns1:ABCCollection>

      and now I have to break this message in a such a way that
      ******************
      <ns1:ABCdataCollection>
      <ns1:ABCdata>
      <ns1:JobId>8786</ns1:JobId>
      <ns1:Message>aaaaaaa</ns1:Message>
      </ns1:ABCdata>
      </ns1:ABCdataCollection> will be sent as message 1 to JMS queue and
      ******************
      <ns1:ABCdataCollection>
      <ns1:ABCdata>
      <ns1:JobId>8787</ns1:JobId>
      <ns1:Message>bbbbbbb</ns1:Message>
      </ns1:ABCdata>
      </ns1:ABCdataCollection> will be sent as message 2, and there by followed on. Can you guys let me know, what kind of transformation i can use here?


      Thanks,
        • 1. Re: How to break XMl payload
          991448
          You can easily use a for each in bpel
          counter name say ABCDataCounter
          for start value counter use 1
          for final value counter use count($VAR/ns1:ABCdata)
          in the scope of for each access the required data by using predicates $VAR/ns1:ABCdata[$ABCDataCounter]
          You can now use transformations xsl or assign nodes for getting the taget data format.$VAR/ns1:ABCdata[$ABCDataCounter]/ns1:JobId will give you the required data.
          • 2. Re: How to break XMl payload
            DeepakDabbiru
            Hi Kamesh,

            You can define a While Loop and ensure that using an index variable send only one node per loop.

            While loop
            {

            1) Assign Activity to set the data into
            <ns1:ABCdataCollection>
            <ns1:ABCdata>
            <ns1:JobId>8786</ns1:JobId> here use the loop variable as an index to get only appropriate JobId(like ns1:ABCdataCollection/ns1:ABCdata[$Index]/ns1:JobId)
            <ns1:Message>aaaaaaa</ns1:Message> here use the loop variable as an index to get only appropriate Message(like ns1:ABCdataCollection/ns1:ABCdata[$Index]/ns1:Message)
            </ns1:ABCdata>
            </ns1:ABCdataCollection>

            2) Invoke activity to JMS queue

            3) Assign Activity to increment the while loop counters
            }

            This should suit your requirement.

            Thanks,
            Deepak.
            • 3. Re: How to break XMl payload
              BK574
              Thanks for your replies,

              I included the following code in my bpel file
              <while name="While1">
              <condition>$CounterVariable &gt; 0</condition>
              <sequence>
              <assign name="Transform1">
              <bpelx:annotation>
              <bpelx:pattern patternName="bpelx:transformation"/>
              </bpelx:annotation>
              <copy>
              <from>ora:doXSLTransformForDoc("xsl/Transformation_6.xsl", $Invoke3_getReportMetadata_OutputVariable.parameters)</from>
              <to variable="Invoke4_Write_InputVariable_6" part="body"/>
              </copy>
              </assign>
              <invoke name="Invoke4" partnerLink="WriteFile" portType="ns10:Write_ptt"
              operation="Write" inputVariable="Invoke4_Write_InputVariable_6"
              bpelx:invokeAsDetail="no"/>
              <assign name="Assign4">
              <copy>
              <from>$CounterVariable - 1</from>
              <to>$CounterVariable</to>
              </copy>
              </assign>
              </sequence>
              </while>

              and yes, it is generating 28 messages but with the same content, not different. Here, I have used a counter variable for which I assigned count(ABCData) and hence it is looping for 28 or more.

              For ex:
              in all the messages i am seeing same message like
              <?xml version="1.0" encoding="UTF-8" ?><element1 xmlns:ns2="http://www.guycarp.com/soa/grail/FileSchema.xsd" xmlns="http://www.xml.com/FileSchema.xsd">
              <ns2:ABCData>0001</ns2:ABCData>
              <ns2:FileLocation>C:/Documents/appl.pdf</ns2:FileLocation>
              </element1>

              it is supposed to be like
              <?xml version="1.0" encoding="UTF-8" ?><element1 xmlns:ns2="http://www.guycarp.com/soa/grail/FileSchema.xsd" xmlns="http://www.xml.com/FileSchema.xsd">
              <ns2:ABCData>0001</ns2:ABCData>
              <ns2:FileLocation>C:/Documents/appl.pdf</ns2:FileLocation>
              </element1>
              <?xml version="1.0" encoding="UTF-8" ?><element1 xmlns:ns2="http://www.guycarp.com/soa/grail/FileSchema.xsd" xmlns="http://www.xml.com/FileSchema.xsd">
              <ns2:ABCData>0002</ns2:ABCData>
              <ns2:FileLocation>C:/Documents/appl.pdf</ns2:FileLocation>
              </element1>
              <?xml version="1.0" encoding="UTF-8" ?><element1 xmlns:ns2="http://www.guycarp.com/soa/grail/FileSchema.xsd" xmlns="http://www.xml.com/FileSchema.xsd">
              <ns2:ABCData>0003</ns2:ABCData>
              <ns2:FileLocation>C:/Documents/appl.pdf</ns2:FileLocation>
              </element1> and so on.....

              Even I tried with For each, but i am seeing the same output.
              • 4. Re: How to break XMl payload
                991448
                What are the inputs which you are passsing to your trasnfromation.
                Please paste your transformation code,
                • 5. Re: How to break XMl payload
                  BK574
                  Hi,
                  Please find the transformation code

                  <xsl:template match="/">
                  <ns2:element1>
                  <ns2:JobID>
                  <xsl:value-of select="/tns:getReportMetadataResponse/return/ns0:ReportMetadataCollection/ns0:ReportMetadata/ns0:ABCData"/>
                  </ns2:JobID>
                  <ns2:FilePath>
                  <xsl:value-of select="/tns:getReportMetadataResponse/return/ns0:ReportMetadataCollection/ns0:ReportMetadata/ns0:FileLocation"/>
                  </ns2:FilePath>
                  </ns2:element1>
                  </xsl:template>
                  </xsl:stylesheet>
                  • 6. Re: How to break XMl payload
                    991448
                    And what r u passing as input.. I guess u are passing the the whole payload as input...
                    if yes then you will always get the first element..
                    you have two options here...

                    1) modify your you input to transfromation so that it accepts the input is single unit of
                    <ns1:ABCdata>
                    <ns1:JobId>8786</ns1:JobId>
                    <ns1:Message>aaaaaaa</ns1:Message>
                    </ns1:ABCdata>

                    and the get the required output
                    ...u will have to pass the input as tns:getReportMetadataResponse/return/ns0:ReportMetadataCollection/ns0:ReportMetadata/ns0:ABCData[$CounterVariable]

                    2) modify the transformation to accept a number as an input parameter and then ur transformation should look like:- Pass the $Counter variable also as input...
                    <xsl:param name="counter"/>
                    <xsl:template match="/">
                    <ns2:element1>
                    <ns2:JobID>
                    <xsl:value-of select="/tns:getReportMetadataResponse/return/ns0:ReportMetadataCollection/ns0:ReportMetadata[$counter]/ns0:ABCData"/>
                    </ns2:JobID>
                    <ns2:FilePath>
                    <xsl:value-of select="/tns:getReportMetadataResponse/return/ns0:ReportMetadataCollection/ns0:ReportMetadata[$counter]/ns0:FileLocation"/>
                    </ns2:FilePath>
                    </ns2:element1>
                    </xsl:template>
                    </xsl:stylesheet>

                    Edited by: 988445 on Mar 26, 2013 7:55 PM
                    • 7. Re: How to break XMl payload
                      BK574
                      Thanks you very much its working now
                      • 8. Re: How to break XMl payload
                        Richa Juneja
                        You can use position function also to split it.

                        e.g. ABCollection/position[1]-> as first message.
                        ABCollection/position[2]-> as second message.

                        Edited by: Richa Juneja on Apr 15, 2013 5:24 AM