cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove xmlns in node level

Former Member
0 Kudos

Hi Experts!

How to remove xmlns in node level in response xml file. I tried to use AF_Modules/XMLAnonymizerBean, but it did not work.

Can you please help me out on this.

I want to remvoe xmlns tag in LEVICOM

Eg:

- <Addenda>

- <LEVICOM xmlns="">

Thanks,

Hari

Accepted Solutions (0)

Answers (8)

Answers (8)

Former Member
0 Kudos

Hi Experts!

How to remove xmlns tag in xml file, where only xmlns="".

I am using below xslt mapping, but it is removing all xmlns tags in a xml file. I want to remove only xmlns="" .

Here is the code:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns="http://www.arconw.com/XI/XSLT_Library/XmlNamespacePrefixRemoval"

version="1.0">

<xsl:output method = "xml" />

<xsl:template match="/">

<xsl:apply-templates select="*" mode="remprefix"/>

</xsl:template>

<xsl:template match="*" mode="remprefix">

<xsl:variable name="newname" select="local-name(.)"/>

<xsl:element name="{$newname}" namespace ="{namespace-uri()}">

<xsl:apply-templates mode="copyall" select="@*|comment()|processing-instruction()|text()"/>

<xsl:apply-templates select="*" mode="remprefix"/>

</xsl:element>

</xsl:template>

<xsl:template mode="copyall" match="@*|comment()|processing-instruction()|text()">

<xsl:copy>

<xsl:apply-templates mode="copyall" select="@*|comment()|processing-instruction()|text()"/>

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

Thanks,

Hari

Former Member
0 Kudos

Thanks SuraJ!

Its very helpful answer. I have given point to you.

Thanks,

Hari

Former Member
0 Kudos

Hi Expers!

Please help me out on this. The below xslt mapping working only to remove xmlns prefix in xml file, if parent having only one child. This code is not working if parent having multiple childs.

Eg: <parent>

<phild xmlns="">

test1

</phild>

</parent>

The above example working fine with below xslt mapping to remove xmlns tag.

Second scenarion not working

Eg: <parent>

<child1 xmlns="">

test1

</child1>

<child2 xmlns="">

test2

</child2>

</parent>

The above example is not working.

Here is the code:

You can remove the namespace prefixes using an XSLT mapping if they are causing problems with applications outside of XI.

Try the following code:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns="http://www.arconw.com/XI/XSLT_Library/XmlNamespacePrefixRemoval"

version="1.0">

<xsl:output method = "xml" />

<xsl:template match="/">

<xsl:apply-templates select="*" mode="remprefix"/>

</xsl:template>

<xsl:template match="*" mode="remprefix">

<xsl:variable name="newname" select="local-name(.)"/>

<xsl:element name="{$newname}" namespace ="{namespace-uri()}">

<xsl:apply-templates mode="copyall" select="@*|comment()|processing-instruction()|text()"/>

<xsl:apply-templates select="*" mode="remprefix"/>

</xsl:element>

</xsl:template>

<xsl:template mode="copyall" match="@*|comment()|processing-instruction()|text()">

<xsl:copy>

<xsl:apply-templates mode="copyall" select="@*|comment()|processing-instruction()|text()"/>

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

Thanks,

Hari

former_member187339
Active Contributor
0 Kudos

Hi Hari,

Use this XSLT:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no"/>

  <xsl:template match="/|comment()|processing-instruction()">
    <xsl:copy>
      <!-- go process children (applies to root node only) -->
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

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

  <xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>

</xsl:stylesheet>


Regards

Suraj

Former Member
0 Kudos

Thanks Vijay and Raj.

Raj,

if you are using JAVA Mapng use regex to remove the XMLNS...

Can you send sample code , how to regex in JAVA mapping?

Vijay,

Here is the ouput xml file,

<Parent>

<child xmlns="">

</child>

<parent>

I want to remove xmlns tag in child node.

Thanks,

Hari

Former Member
0 Kudos

Hi,

My scenario:

IDOC --> Java Mapping --> XML file.

In response xml file I am getting xmlns tag. How to remove that tag in Java mapping.

Thanks,

Hari

Shabarish_Nair
Active Contributor
0 Kudos

there is a sample xslt code that can help u in this thread -

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Hari,

we people suggested you to use XSLT Mapping or JAVA Mapping,

if you are using JAVA Mapng use regex to remove the XMLNS...

Regards,

Raj

Former Member
0 Kudos

Sorry , It did not help to my scenario.

Can you please help me on this.

Thanks,

Hari

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Hari,

If you know XSLT mapping its very easy to remove,

Give me the source structure i will try to give XSLT Mapping code.

Raj

Former Member
0 Kudos

Hi,

Can you please explain me how to remove xmlns by using JAVA mapping. Currenly I am using java mapping.

Thanks,

Hari

Former Member
Former Member
0 Kudos

Hari,

You can write a Java / XSLT mapping to handle this.

regards,

Neetesh