119.11. 用于 IDoc 的 XML Serialization
IDoc 消息正文可以序列化为 XML 字符串格式,以帮助内置类型转换器。
119.11.1. XML 命名空间 复制链接链接已复制到粘贴板!
每个序列化 IDoc 都与 XML 命名空间关联,其具有以下通用格式:
http://sap.fusesource.org/idoc/repositoryName/idocType/idocTypeExtension/systemRelease/applicationRelease
repositoryName (远程 SAP 元数据存储库的名称)和 idocType (IDoc document type)都是强制的,但命名空间的其他组件可以留空。例如,您可以有一个类似如下的 XML 命名空间:
http://sap.fusesource.org/idoc/MY_REPO/FLCUSTOMER_CREATEFROMDATA01///
119.11.2. 内置类型转换器 复制链接链接已复制到粘贴板!
Camel SAP 组件具有一个内置类型转换器,能够将 Document 对象或 DocumentList 对象转换为 String 类型或从 String 类型转换。
例如,要将 Document 对象序列化为 XML 字符串,只需将以下行添加到 XML DSL 中的路由中:
<convertBodyTo type="java.lang.String"/>
您还可以使用此方法将 XML 消息序列化为 Document 对象。例如,如果当前消息正文是序列化 XML 字符串,您可以通过将以下行添加到 XML DSL 中的路由来将其转换为 Document 对象:
<convertBodyTo type="org.fusesource.camel.component.sap.model.idoc.Document"/>
119.11.3. XML 格式的 IDoc 消息正文示例 复制链接链接已复制到粘贴板!
当您将 IDoc 消息转换为 String 时,它将序列化为 XML 文档,其中 root 元素是 idoc:Document (单个文档)或 idoc:DocumentList (用于文档列表)。它显示,单个 IDoc 文档已序列化为 idoc:Document 元素。
例 119.2. XML 中的 idoc 消息正文
<?xml version="1.0" encoding="ASCII"?>
<idoc:Document
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:FLCUSTOMER_CREATEFROMDATA01---="http://sap.fusesource.org/idoc/XXX/FLCUSTOMER_CREATEFROMDATA01///"
xmlns:idoc="http://sap.fusesource.org/idoc"
creationDate="2015-01-28T12:39:13.980-0500"
creationTime="2015-01-28T12:39:13.980-0500"
iDocType="FLCUSTOMER_CREATEFROMDATA01"
iDocTypeExtension=""
messageType="FLCUSTOMER_CREATEFROMDATA"
recipientPartnerNumber="QUICKCLNT"
recipientPartnerType="LS"
senderPartnerNumber="QUICKSTART"
senderPartnerType="LS">
<rootSegment xsi:type="FLCUSTOMER_CREATEFROMDATA01---:ROOT" document="/">
<segmentChildren parent="//@rootSegment">
<E1SCU_CRE parent="//@rootSegment" document="/">
<segmentChildren parent="//@rootSegment/@segmentChildren/@E1SCU_CRE.0">
<E1BPSCUNEW parent="//@rootSegment/@segmentChildren/@E1SCU_CRE.0"
document="/"
CUSTNAME="Fred Flintstone" FORM="Mr."
STREET="123 Rubble Lane"
POSTCODE="01234"
CITY="Bedrock"
COUNTR="US"
PHONE="800-555-1212"
EMAIL="fred@bedrock.com"
CUSTTYPE="P"
DISCOUNT="005"
LANGU="E"/>
</segmentChildren>
</E1SCU_CRE>
</segmentChildren>
</rootSegment>
</idoc:Document>