290.13. IDoc 的 XML Serialization
概述
IDoc 消息正文可以序列化为 XML 字符串格式,并帮助内置类型转换器。
XML 命名空间
每个序列化 IDoc 都与 XML 命名空间关联,它有以下通用格式:
http://sap.fusesource.org/idoc/repositoryName/idocType/idocTypeExtension/systemRelease/applicationRelease
repositoryName (远程 SAP 元数据存储库的名称)和 idocType (IDoc 文档类型)都是必需的,但命名空间的其他组件可以留空。例如,您可以有一个类似如下的 XML 命名空间:
http://sap.fusesource.org/idoc/MY_REPO/FLCUSTOMER_CREATEFROMDATA01///
内置类型转换器
Camel SAP 组件有一个内置类型转换器,它能够将 Document 对象或 DocumentList 对象转换为字符串类型,以及从 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"/>
XML 格式的 IDoc 消息正文示例
当您将 IDoc 消息转换为 String 时,它将被序列化为 XML 文档,其中 root 元素是 idoc:Document (用于单个文档)或 idoc:DocumentList (用于文档列表)。例 290.2 “XML 中的 idoc 消息正文” 显示已序列化为 idoc:Document 元素的单一 IDoc 文档。
例 290.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>