Skip to Content

Removing namespace prefix from xml file

Hi All,

Our scenarios is Proxy to mail.

SAP R/3 --> SAP GRC ---->SAP PI --> Business partners

We are sending xml file as a email attachment to business partners. It is convention in PI to use ns0 or nm as the prefix for the XML Schema namespace.

My client wants to remove the prefix "nm" when sending xml files to business partners.

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

<nm:nfeProc versao="3.10" xmlns:nm="http://www.portalfiscal.inf.br/nfe" xmlns="http://www.portalfiscal.inf.br/nfe">

-----

----

</nm:nfeProc>

--> We are using the SAP standard XSD.

--> I have tried using XML Anonymizer Bean in mail communication Channel to remove namespace prefix "nm" in XML Payload. please check the below configuration for your reference.

I also tried by placing the Anonymizer Bean before message transformebean but still no luck. please help us to resolve this issue.

Thanks in advance.

Regards

Bhargava Krishna

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Sep 20, 2017 at 08:16 AM

    Then you can try using UDF Krishna,We have similar req in CFDI where we need to change namespace prefix.

    StructureNode node = ((StructureNode) container.getParameter("STRUCTURE_NODE"));
    node.setNSDeclarations(" xmlns:" + prefix + "=" + namespace);
    node.setQName(prefix + "test");
    return"";

    In prefix you can pass empty value and namespace as per requirement. And in the place for test you can select the message type

    I tried to remove namespace prefix and seems working.

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 19, 2017 at 10:12 AM

    Paramter name for quote is wrong I believe,Try anonymizer.quote

    https://blogs.sap.com/2014/10/02/remove-namespace-by-xmlanonymizer-bean-in-communication-channel/

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Raghuraman,

      Thanks for your response.

      as specified in the link, i have configured the module key parameters in the communication channel, but still im prefix "nm" is not removed.

      Parameter Name: anonymizer.quote

      Parameter Value:

      Regards

      Bhargava Krishna

  • Sep 20, 2017 at 03:05 AM

    Hi Bhargava,

    Since the values of the target namespace and unqualified namespace are the same, you can:

    1. use a custom operation mapping (not the SAP provided one) to remove the namespace

    2. use a custom adapter module to remove the namespace

    Regards,

    Mark

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 19, 2017 at 10:19 AM

    Hi Bhargava Krishna!

    I don't understand why the same namespace is used both with prefix and without as default namespace.

    Anyway, did you try to place XMLAnonymizerBean bean the first in the chain and set the namespace with empty prefix in module's parameters?

    Like this: http://www.aaa.bbb/ccc '' (two single quotes).

    And why do you set single quote as quotation mark? Do you have any issues with default mark?

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 20, 2017 at 02:11 PM

    Hello Bhargava Krishna,

    You can also use this XSL map to remove any namespaces:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
        
        <xsl:template match="*">
            <xsl:element name="{local-name()}">
                <xsl:apply-templates select="@* | node()"/>
            </xsl:element>
        </xsl:template>
        
    </xsl:stylesheet>
    
    

    You can use it as a first mapping step in your operation mapping.

    Best regards, Peter

    Add comment
    10|10000 characters needed characters exceeded