cancel
Showing results for 
Search instead for 
Did you mean: 

How to clean out namespace element in message mapping

prasanthi_chavala
Active Contributor
0 Kudos

Hi All,

I have a requirement where my input message should be mapped to one field in the target structure and the condition here is the namespace element should not be used.

So my first part in the requirement can be achieved by using "return as xml" in the context change. But i am stuck in my second step where i need to remove the namespace.

The output from the source node will be in the xml string and i have tried with replacestring text function but it is throwing error.

Can you please suggest if i can achieve this through standard functions/UDF in the message mapping or i should only go by java mapping?

Thanks,

Prasanthi

Accepted Solutions (1)

Accepted Solutions (1)

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

it depends on which namespace you're trying to remove

a) if this is a main namespace them you can remove it with a substring/replace string

- you just need to escape the quotes

b) if you have filed level namespace them it's best to do it using a java mapping

Regards,

Michal Krawczyk

prasanthi_chavala
Active Contributor
0 Kudos

Hi Mike,

I am trying to remove the main namespace only.

My input xml message structure is something like this:

<ns0:Maintag xmlns:ns2="http://abc.com/pi/XYZ-System/DEF1">

<Field></Field>

<Field1></Field1>

.

.

.

</ns0:Maintag>

And expected output after return xml to target field is:

<Maintag>

<Field></Field>

<Field1></Field1>

.

.

.

</Maintag>

So in my mapping i am using something like:

Maintag-->(return as xml) --> replacestring --> replacestring --> output field

Can you please guide me how shud i pass the values in:

my second parameter of first replace string : ???

third input paramter of first replacestring function: ??

Second input parameter of second replacestring fuction:  ???

third parametervalue of second replacestring: ???

Thanks,

Prasanthi

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

there is even a simpler way - try the XSLT from this page:

http://stackoverflow.com/questions/4661154/how-do-i-remove-namespaces-from-xml-using-java-dom

copy&paste from the mentioned page:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
<xsl:template match="node()">
   
<xsl:copy>
       
<xsl:apply-templates select="node() | @*" />
   
</xsl:copy>
 
</xsl:template>

 
<xsl:template match="*">
   
<xsl:element name="{local-name()}">
       
<xsl:apply-templates select="node() | @*" />
   
</xsl:element>
 
</xsl:template>

 
<xsl:template match="@*">
   
<!-- Here! -->
   
<xsl:copy>
     
<xsl:apply-templates select="node() | @*" />
   
</xsl:copy>

 
</xsl:template>
</xsl:stylesheet>

set it before your message mapping in the operation mapping and let me know if this works,

Regards,

Michal Krawczyk

prasanthi_chavala
Active Contributor
0 Kudos

Hi Mike,

I just defined the below piece of code in the UDF and it is working as expected.

public static String removeXmlStringNamespaceAndPreamble(String xmlString) {
 
return xmlString.replaceAll("(<\\?[^<]*\\?>)?", ""). /* remove preamble */
  replaceAll
("xmlns.*?(\"|\').*?(\"|\')", "") /* remove xmlns declaration */
 
.replaceAll("(<)(\\w+:)(.*?>)", "$1$3") /* remove opening tag prefix */
 
.replaceAll("(</)(\\w+:)(.*?>)", "$1$3"); /* remove closing tags prefix */
}

I will also try the xslt way and let you know.

Thanks,

Prasanthi

Former Member
0 Kudos

Hi,

U can still use replace string function...try this:

my second parameter of first replace string :<?xml version="1.0" encoding="UTF-8"?>

third input paramter of first replacestring function: Constant ( ) -keep it as blank

Second input parameter of second replacestring fuction:

xmlns:ns2="http://abc.com/pi/XYZ-System/DEF1"

third parametervalue of second replacestring:Constant ( ) -keep it as blank

Thanks

Amit Srivastava

prasanthi_chavala
Active Contributor
0 Kudos

Hi Amit,

No..It is not working with replacestring function. As said, the only easy option i see is through UDF.

Thanks,

Prasanthi

Former Member
0 Kudos

Hi,

Yes indeed UDF is the option but seems strange RS is not working

BTW whats the error u r getting while using replace string??

Regards,

Amit Srivastava

prasanthi_chavala
Active Contributor
0 Kudos

Hi Amit,

I am not getting any error but in the target field, i still see the namespace values and all the '<' and '>' are showing as &lt and&gt.

Thanks,

Prasanthi

Former Member
0 Kudos

Hi,

>>values and all the '<' and '>' are showing as &lt and&gt.

I hope u r not viewing ur result using SRC tab...may be what u can do is after executing the test open the target field and right click on the value -> copy value

Pate it somehwere in the notepad and then chk

Thanks

Amit

prasanthi_chavala
Active Contributor
0 Kudos

Hi Amit,

Just tried as u suggested but no luck

It is still giving the entire payload with namespace in my target field when i viewed the output by pasting in the notepad.

Thanks,

Prasanthi

Former Member
0 Kudos

Hi,

Looks like we are working on different PI systems .

Please check the below screen shot and the ouput in XML string form without having namepsace ( i hope we are on the same track).

Thanks

Amit Srivastava

prasanthi_chavala
Active Contributor
0 Kudos

Hi Amit,

I was able to get this with replacesting funtion. I was giving some extra space in the value due to which it failed to give proper output. After correcting the value the output is coming fine.

Thank u for ur response.

Regards,

Prasanthi

Answers (0)