13 Replies Latest reply: Mar 26, 2013 1:43 AM by FabioDouek RSS

    Need to replace a tag in Request XML in OSB

    pritamighty
      I have my proxy service in OSB connected to MQ as the input provider. Now I want to take a couple of namespaces and copy them into the body and remove those tags.

      Here is the input from MQ...

      -------------------------------------------------------------------------------------------------------------------------------------
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v="http://www.w3.org/1999/XSL/Transform">

      <soapenv:Header/>

      <soapenv:Body>

      <v:createAccount>

      <partId>Mnhtd_21</partId>

      </v:createAccount>

      </soapenv:Body>

      </soapenv:Envelope>
      -------------------------------------------------------------------------------------------------------------------------------------
      I want this request xml to be converted into the following xml before it can be routed to the Business Service...
      -------------------------------------------------------------------------------------------------------------------------------------

      <v:createAccount xmlns:v="http://www.w3.org/1999/XSL/Transform">

      <partId>Mnhtd_21</partId>

      </v:createAccount>
      -------------------------------------------------------------------------------------------------------------------------------------

      How can I transform it in the Proxy Service message flow?

      Please Help.

      Thanks in advance!

      Edited by: 994962 on Mar 20, 2013 12:10 AM
        • 1. Re: Need to replace a tag in Request XML in OSB
          991448
          try using a replace node
          Choose
          replace entire node
          xpath ./*
          variable $body
          expression

          <v:createAccount xmlns:v="http://www.w3.org/1999/XSL/Transform">

          <partId>$body/*[1]/*:partId/text</partId>

          </v:createAccount>
          • 2. Re: Need to replace a tag in Request XML in OSB
            pritamighty
            Hi,

            Thanks for your reply.

            It seems to work, but partly.

            The changed $body comes out as
            ----------------------------------------------------------------------------------------------------------------------------------------------------------
            <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
            <v:createAccount xmlns:v="http://www.w3.org/1999/XSL/Transform">
            <partId>$body/*[1]/*:partId/text</partId>
            </v:createAccount>
            </soapenv:Body>
            ----------------------------------------------------------------------------------------------------------------------------------------------------------
            As you can see, <soapenv:Body tag is added which is not desirable. Also, the transformation inside the <partId> didn't happen.

            Would really appreciate your reply on this.

            Thanks!
            • 3. Re: Need to replace a tag in Request XML in OSB
              FabioDouek
              Regarding <partId>$body/*[1]/*:partId/text</partId>

              There are two problems here: text is a function, so it should be /text()
              You have to specify it between {},
              so the correct would be:

              <partId>{$body/*[1]/*:partId/text()}</partId>

              Regards,
              Fabio Douek
              • 4. Re: Need to replace a tag in Request XML in OSB
                pritamighty
                Hi Fabio,

                I tried the changes suggested by you. Now the transformation looks like...

                <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                <v:createAccount xmlns:v="http://www.w3.org/1999/XSL/Transform">
                <partId/>
                </v:createAccount>
                </soapenv:Body>

                Thanks!
                • 5. Re: Need to replace a tag in Request XML in OSB
                  FabioDouek
                  Hi,

                  Try to assign the body to another variable before the routing, then using the variable as the source instead of body. You will still have to replace body inside your routing.

                  Edited by: Fabio Douek on Mar 21, 2013 1:47 PM
                  • 6. Re: Need to replace a tag in Request XML in OSB
                    pritamighty
                    Hi Fabio,

                    Thanks a ton for your input.

                    It worked with slight changes.

                    Just one more query.

                    If I want to access an attribute in a tag, what would be the Expression?

                    For Example:

                    In <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

                    If I want to extract xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" attribute, how should I write the expression?

                    The final expression which worked the way I wanted is:

                    <partId>{$body/soap-env:Envelope/soap-env:Body/v:createAccount/partId/text()}</partId>

                    Regards,
                    Pritam

                    Edited by: pritamighty on Mar 21, 2013 7:52 PM
                    • 7. Re: Need to replace a tag in Request XML in OSB
                      991448
                      There is something wrong with your configuration.
                      $body is never supposed to have soap-env:Envelope.
                      The payload which are getting is it like

                      <soap-env:Envelope>
                      <soap-env:body>
                      <soap-env:Envelope>
                      <soa-env:body>
                      ...


                      This format is not correct...
                      Otherwise i do not see any reason why the xpath should be $body/soap-env:Envelope/soap-env:Body
                      • 8. Re: Need to replace a tag in Request XML in OSB
                        FabioDouek
                        Hi,

                        I agree with 988445. I suggest you revisit your flow from the beginning. Soapenv shouldnt be part of body.

                        What is the request payload to the proxy service, and which other transformations do you have in the pipeline?

                        Regards,
                        Fabio Douek
                        • 9. Re: Need to replace a tag in Request XML in OSB
                          pritamighty
                          Hi,

                          Yes I know that ideally it should not be a part of the $body. But, the Input to OSB is an MQ and the XML which is getting put into the MQ contains <soap-env:Envelope>.

                          Can't help it...:)

                          So, can you please help me in making the Xpath to get the attribute?

                          Really appreciate your replies.

                          Thanks!
                          • 10. Re: Need to replace a tag in Request XML in OSB
                            FabioDouek
                            What are you trying to achieve? That's a namespace declaration.
                            Why would you need to propagate that information?

                            Regards,
                            Fabio Douek
                            • 11. Re: Need to replace a tag in Request XML in OSB
                              pritamighty
                              Dear Fabio,

                              I am forced to strip off the namespaces from the Soap Envelope that I am receiving from the MQ which is not the standard precedure. So I need the namespaces so that I can put them as attributes in the bosy itself.

                              Here's what I want to do.....

                              Input:

                              <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v="http://www.w3.org/1999/XSL/Transform">

                              <v:createAccount>

                              <partId>Mnhtd_21</partId>

                              </v:createAccount>

                              Desired Output:

                              <v:createAccount xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v="http://www.w3.org/1999/XSL/Transform">

                              <partId>Mnhtd_21</partId>

                              </v:createAccount>

                              So I need an Xpath to take the attributes out of the <soapenv:Envelope> and put them in <v:createAccount>

                              Thanks!
                              • 12. Re: Need to replace a tag in Request XML in OSB
                                FabioDouek
                                Hi,

                                This looks odd... But you probably know what is required to pass to the backend and also the use cases.
                                Note that there is no strict rule for naming a prefix. Usually you would propagate only namespaces which are being used in your message.

                                If you really want to do that, you can have a look into these two functions:

                                http://www.xqueryfunctions.com/xq/fn_in-scope-prefixes.html (retrieves the list of prefixes)
                                http://www.xqueryfunctions.com/xq/fn_namespace-uri-for-prefix.html (retrieves the namespace for a prefix)

                                OR if you want just to retrieve the namespace for a specific node:
                                http://www.xqueryfunctions.com/xq/fn_namespace-uri.html

                                Regards,
                                Fabio Douek
                                • 13. Re: Need to replace a tag in Request XML in OSB
                                  FabioDouek
                                  Hi,

                                  Did you manage to make it work?

                                  Regards,
                                  Fabio Douek