XML Anonymizer Bean in Communication Channel to remove namespace prefix in XML P

本文介绍如何使用SAP的XML匿名化组件在适配器中去除XML Payload中命名空间前缀,同时保留命名空间内容。通过配置XML匿名化组件,可以将XML消息中的命名空间前缀'ns0'去除,简化XML文档结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转:http://www.saptechnical.com/Tutorials/XI/XMLPayload/Index.htm

There are situations where additional functions are demanded to satisfy a requirement. The requirement could be to remove namespace prefix in XML Payload. Modules equipped in the adapter come for rescue without having the developer to do much.

The modules are the basis of the adapter configuration on the Parameters tab page, located in the module processor and are displayed in the module processor once a communication channel has been created.

A little about Namespaces…

One of the primary motivations for defining an XML namespace is to avoid naming conflicts when using and re-using multiple times. XML Schema is used to create vocabulary for an XML instance, and uses namespaces.

Namespaces are like package in Java, has many reusable elements and attributes.

For eg: <ns0:ShipNotice xmlns:ns0="urn:cidx:names:specification:ces:schema:all:4:0" Version="4.0">

In the attribute xmlns:ns0, xmlns is a reserved word, used to declare a namespace. That is the above example is read as binding the prefix ‘ns0’ with the namespace ‘urn:cidx:names:specification:ces:schema:all:4:0’.

It is convention in PI to use ns0 as the prefix for the XML Schema namespace. And wherever the prefix ‘ns0’ is used in the entire message, they are used only as a placeholder and must be expanded by the namespace. This way all the elements used in the message are associated to the namespace using the prefix.

The example message is given below, where every element (Header, DocumentIdentifier etc..) are associated with the namespace ‘urn:cidx:names:specification:ces:schema:all:4:0’.

<?xml version="1.0" encoding="UTF-8"?>
<ns0:ShipNotice xmlns:ns0="urn:cidx:names:specification:ces:schema:all:4:0" Version="4.0">
<ns0:Header>
<ns0:ThisDocumentIdentifier>
<ns0:DocumentIdentifier>0000000010576079</ns0:DocumentIdentifier>
</ns0:Header>
</ns0:ShipNotice>
However, business partner who receives this message may think that XML document is cluttered with prefix ns0 and want to avoid. Or it could be that the software used does not support this prefix and will not process the messages successfully. So now the requirement dictates the removal of prefix without removing the namespace. As explained, in PI it is possible to remove the namespace prefix using XML Anonymizer bean in module that is equipped in adapter.
Find below the screenshot that illustrates the configuration of the communication channel.

[img]http://dl.iteye.com/upload/attachment/0071/2612/840bd0a8-e113-3f21-80ec-bf9be3e613f2.jpg[/img]

Procedure:
Add the Module in the Processing Sequence
1. Insert the module before the adapter module.
Module Name : AF_Modules/XMLAnonymizerBean
Module Key: 0
The module name ‘CallSapAdapter’ is default one that can be left as it is.
Add Parameters in the Module Configuration
2. Module Key: 0
Parameter Name: anonymizer.acceptNamespaces
Parameter Value: <namespace> ‘’
Enter a list of namespaces and their prefixes that are to be kept in the target XML document and to result a namespace without a prefix, enter ‘ ‘ (two single quotation marks).
3. Module Key: 0
Parameter Name: anonymizer.quote
Parameter Value: ‘
Here specify the character to be used to enclose the attribute values. The default value is ‘.
When scenario is executed, the target message contains the namespace with no prefix.
<?xml version="1.0" encoding="UTF-8"?>
<ShipNotice xmlns="urn:cidx:names:specification:ces:schema:all:4:0" Version="4.0">
<Header>
<ThisDocumentIdentifier>
<DocumentIdentifier>0000000010576079</DocumentIdentifier>
</Header>
</ShipNotice>
There are generic modules for adapters provided by SAP for different requirements. Navigate to http://help.sap.com/saphelp_nwpi711/helpdata/en/cd/5af7c0c994e24fb0d0088443513de2/frameset.htm for more details.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值