Wednesday, August 31, 2011

Replace / rename namespace in OSB

I have an input schema without a name space, like <a><b><c>blah</c></b></a>.

I need to convert it into <a xmlns="http://x.y.com/z"><b><c>blah</c></b></a>. Beware this is equavilant to <foo:a xmlns:foo="http://x.y.com/z"><foo:b><foo:c>blah</foo:c><./foo:b></foo:a>

I have tried various ways, including use "fn-bea:serialize($arg-items)" and "contact()", just couldn't make it work. I found my solution by browsing online. then trial and error.

First of all, you can always use XSLT to transalte to new namespace. But I want to use the built-in activites to do it.

My answer is to use "rename" activity.

In my case, I put in

XPath: ".//*"
In Variable: myVar (which contains the source XML)
localname: (leave it empty)
Namespace: http://x.y.com/z"

This will take care of all elements of <b> and down. So you I have to do another rename, just for <a> (If you are wondering, I actually tried XPath: "//*". It didn't work).

So for the 2nd rename:
XPath: "."
In Variable: myVar (which contains the source XML)
localname: (leave it empty)
Namespace: http://x.y.com/z"

I'm quite sure you can do (or leave xpath as ".")
XPath: "./a"
In Variable: myVar (which contains the source XML)
localname: a
Namespace: http://x.y.com/z"

3 comments:

  1. ./Sites/Site[1]/site_group how to pass dynamic values instead of 1

    ReplyDelete



  2. 2002179
    2002179
    2002179 - Pinnacle Oncology Hematology
    United States of America USA


    2002180
    2002180
    2002180 - University of Colorado
    United States of America




    I am passing enteirer xml as in file and trying to replace content value in for activity but it is replacing in all place where tag appear but my requirement it replace based on index value first block with first loop , second black with second loop . how to pass index value dyanmic /Sites/Site[1]/site_group instead of '1' /Sites/Site[some dynamic value]/site_group

    ReplyDelete