cancel
Showing results for 
Search instead for 
Did you mean: 

Avoid repeating namespace declaration in xml output

KennethEriksen
Participant
0 Kudos
1,142

Hi all,

I'm trying an IDoc -> XML File (specifically UBL-format) scenario, and it is working fine. But the resulting XML contains repeating namespace declarations for each element, instead of a "common" declaration at the root element.

How can I avoid this, so the message contains the namespace declarations in root node, and only uses the namespace prefix for each element?

The target format, external definition, is an XSD with several import statements, and all external references have been set up, meaning all referenced XSD's are imported too, and have the "Source"-field set according to the import statement.

Sample result file (top of file only):

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Invoice xmlns:ns0="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<ns2:UBLVersionID xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2.0</ns2:UBLVersionID>
<ns2:CustomizationID xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:www.cenbii.eu:transaction:BiiCoreTrdm001:ver1.0:extentionId</ns2:CustomizationID>
<ns2:ProfileID xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:www.cenbii.eu:profile:bii05:ver1.0</ns2:ProfileID>
<ns2:ID xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">9010045446</ns2:ID>
<ns2:IssueDate xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2011-04-19</ns2:IssueDate>
<ns2:InvoiceTypeCode...

PI version 7.11.

Thanks for all help.

Br,

Kenneth

View Entire Topic
former_member854360
Active Contributor
0 Kudos

Hi ,

You can remove the Unwanted namespace by using

SAP standard XMLAnonymizerBean Adapter module.

You use this module to anonymize XML elements and attributes by removing namespaces or namespace prefixes from the XML document of the main payload.

You can define a particular namespace prefix for each namespace. You can also change the encoding attribute of the XML declaration.

See this Blog

/people/stefan.grube/blog/2007/02/02/remove-namespace-prefix-or-change-xml-encoding-with-the-xmlanonymizerbean

See SAP Doc

http://help.sap.com/saphelp_nw04/helpdata/en/45/d169186a29570ae10000000a114a6b/content.htm

KennethEriksen
Participant
0 Kudos

Thanks for your quick response.

I'm aware of the XMLAnonymizerBean, but I need to keep the prefix for all namespaces, and I need to have all namespace declarations in the root node.

This usually happens automatically, but not for this scenario. Is it because of the structure of the external definition?

Any ways to fix this?

-Kenneth

former_member854360
Active Contributor
0 Kudos

You can write java or XSLT mapping to play with namespace.

/people/shabarish.vijayakumar/blog/2010/05/07/quick-tips-dealing-with-namespaces-in-xipi

baskar_gopalakrishnan2
Active Contributor
0 Kudos

The problem here is not for removing the namespace prefixes or modifying it. So to deal with repeated namespaces , I agree you might have to achieve your desired target structure only using mapping such as java or xslt mapping. In this case, XSLT mapping might be easier and lesser effort than java.

KennethEriksen
Participant
0 Kudos

So you're saying that PI cannot create this target structure without modifying the result with xslt or java?

I find it hard to believe that PI cannot create the target structure based on the namespace declarations in the external definition. There the multiple namespaces are declared at the root node, which is what I expect would be the result also after mapping to this target structure.

Although I know the XML is syntactically and semantically correct as it is, it is very hard to read the xml with the repeating namespace declarations.

-Kenneth