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"

1 comment: