[XML Records] Handling namespaces with XML Records

[XML Records] Handling namespaces with XML Records

  
Forge Component
(32)
Published on 5 Feb by Afonso Carvalho
32 votes
Published on 5 Feb by Afonso Carvalho
Pedro Miranda wrote:
is it possible to tranform the first node from something like

<Group>


into

<n1:Group xmlns:ns1="http://..." xmlns:n1="http://...">

using the configuration file?
 
 
No, it isn't.
The configuration file only allows you to add a xmlns attribute to a particular element.
It would make it possible to transform 
<Group>
into
<Group xmlns="http://blabla">

which semantically is the same as what Pedro was trying to achieve, only that you don't name that particular element.
To do what Pedro is requesting, you'd have to do some kind of post processing to the XML text.

An approach I usually use is to name my attributes with a prefix (e.g. call it n1Group instead of Group) and afterwards replace all existences of n1Group with n1:Group.

All the namespace declarations are usually added in the first xml element. Something like

<xml xmlns:n1="http://blabla">
 <n1:Group>...</n1:Group>
</xml>

There is some processing overhead... but usually not relevant unless you're dealing with very large XML files, in which case, this extension might not be the best approach, as you should use an XML Reader/Writer approach instead.
Hi Goncalo,
I am using record to xml and the generated xml doesnt have namespace. Could you please let me know how to add the namespaces to the xml.

Thanks,
Thiru

Thirupathi Rao Veerla wrote:

Hi Goncalo,
I am using record to xml and the generated xml doesnt have namespace. Could you please let me know how to add the namespaces to the xml.Thanks,
Thiru

Hi Thiru,


You probably solved it by now but i had a similar problem with UBL2.1 salesorders.
Instead of using the "Records to XML" extension i use the "Xml" extension.
The only downside is that I created the whole xml file manually.

The whole flow looks like this:

I declared the namespaces like this:

I create the prefix + element with an underscore in between:

At last i replace the prefix to the right one.


This works for me, hopefully it's helpful for you.

Regards,
Cars