on 07-14-2011 12:11 PM
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
Hi Kenneth,
I have exactly the same issue.
My target definition is build up by several xsd schemas and in the result message the namespace declaration is repeated on element level.
This increases the message size of the result message significantly
Do you find a solution for that issue?
If yes, could you please share it?
How should a XSLT mapping lokk like to remove ns declaration of element level and insert it in the root element.
The number of namespaces is dynamic
Best regards,
Jochen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have exactly the same problem. Does anyone have a solution?
With XSLT I can move the namespace declarations to the root element, but I need XSLT 2.0 for it, while SAP PI only supports XSLT 1.0 => solution cannot be used.
Anyone a XSLT 1.0 solution?
When I use Altova XMLSpy to generate an xml based on the XSD, then the namespace declarations at the right place, ie. in the xml root.
kr
Edmond Paulussen
Hi Mon,
You can use below xslt 1.0 mappings.
The first one will copy all namespaces (declared) to a newly created root element.
The seconde one will delete the 'old' root element.
=> The result will look like an xml where the namespacesare moved to the root element.
First xslt:
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns1="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:ns3="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ns4="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
<xsl:copy-of select="." />
</Invoice>
</xsl:template>
</xsl:stylesheet>
Second xslt:
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Invoice" >
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
Kind regards,
Lode
Hi Rohan!
I think where is nothing wrong in such representation unless the same namespace prefix is linked to different namespaces like that:
<ns0:Element xmlns:ns0="http://namespace1">
<ns0:Subelement xmlns:ns0="http://namespace2">
</ns0:Subelement>
</ns0:Element>
which is also possible but may lead to parsing errors.
Regards, Evgeniy.
Hi Rohan DCosta,
It is definetely not incorrect to have the namespace in the child node.
The namespace only says: the yyy:element belongs to namespace yyy
This way two elements with a different namespace can have the same name but they actually are different elements with possibly different properties...
fi: ns0:body <> ns1:body
The problem mostly is: The receiving system simply cannot handle it.
Kind regards,
Lode
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
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
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.