XOP 处理后的 Infoset
XOP 处理涉及到三个步骤。第一步,使用 Infoset 中的二进制元素替换文本元素。第二步,在包含已替换元素的 Infoset 前添加 MIME 包。第三步,在该 Infoset 后添加另一个包。
第 1 步:替换元素
XOP 包使用名为 xop:Include 的新元素信息项来替换删除的内容。xop: Include 元素包含一个属性信息项,带有指向 XOP 包部分的链接,XOP 包承载从原始元素中删除的数据的二进制表示。在清单 3 中,我突出显示了替换原始 Infoset 中的图片和签名元素的内容的 xop: Include。
清单 3: 替换后的元素
<m:photo xmlmime:content-type='image/png'>
<xop:Include href='cid:http://example.org/me.png'/>
</m:photo>
<m:sig xmlmime:content-type='application/pkcs7-signature'>
<xop:Include href='cid:http://example.org/my.hsh'/>
</m:sig>
正如您所看到的, href='cid:http://example.org/me.png'/ 是图片元素的属性信息项,而 href='cid:http://example.org/my.hsh' 是签名元素的属性信息项。
更新 Infoset 部分(请参见清单 4)。而行数保持不变。
清单 4: 更新后的 XML Infoset 部分
<soap:Envelope
xmlns:soap='http://www.w3.org/2003/05/soap-envelope'
xmlns:xop='http://www.w3.org/2003/12/xop/include'
xmlns:xmlmime='http://www.w3.org/2004/06/xmlmime'>
<soap:Body>
<m:data xmlns:m='http://example.org/stuff'>
<m:photo xmlmime:content-type='image/png'>
<xop:Include href='cid:http://example.org/me.png'/>
</m:photo>
<m:sig xmlmime:content-type='application/pkcs7-signature'>
<xop:Include href='cid:http://example.org/my.hsh'/>
</m:sig>
</m:data>
</soap:Body>
</soap:Envelope>
第2 步:在 Infoset 前添加 MIME 包
为了完成更新,需要使用 MIME Multipart/Related 包中的 XOP 对原始 Infoset 进行序列化。XOP 是一种更有效的方法,用于序列化包含特定类型的 Xquery 和 Xpath 2.0 元素内容的 XML Infoset。
在更新后的 Infoset 前后各添加一个 MIME 包,以分别描述包含文本格式和二进制格式的图片和签名的 XML 文档。在清单 5 中,我突出显示了 XOP 包识别 8 位文本格式的 XML Infoset 的代码。
清单 5: Infoset 前的 XOP 包部分
MIME-Version: 1.0
Content-Type: Multipart/Related;boundary=MIME_boundary;
type=text/xml;start="<mymessage.xml@example.org>"
Content-Description: An XML document with my picture and signature in it
![]()
--MIME_boundary
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: mymessage.xml@example.org
第 3 步:在 Infoset 后添加 MIME 包。
清单 6 显示了 XOP 包如何识别已被删除的数据的二进制表示。
清单 6: Infoset 后的 XOP 包部分
![]()
--MIME_boundary
Content-Type: image/png
Content-Transfer-Encoding: binary
Content-ID: <http://example.org/me.png>
![]()
// binary octets for png
![]()
--MIME_boundary
Content-Type: application/pkcs7-signature
Content-Transfer-Encoding: binary
Content-ID: <http://example.org/my.hsh>
![]()
// binary octets for signature
![]()
--MIME_boundary--
正如您所看到的,Infoset 后的 Content-ID 的二进制内容,xop: Include element 中提到的链接代替了 Infoset 前的消息的文本内容。
最终结果
在清单 7 给出了序列化为 XOP 包的整个 XML Infoset。尽管其中还有其他行,但是此包比原始 Infoset 的 XML 解析器的效率高得多。
清单 7: 序列化为 XOP 包的 XML Infoset
结束语MIME-Version: 1.0
Content-Type: Multipart/Related;boundary=MIME_boundary;
type=text/xml;start="<mymessage.xml@example.org>"
Content-Description: An XML document with my picture and signature in it
![]()
--MIME_boundary
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <mymessage.xml@example.org>
![]()
<soap:Envelope
xmlns:soap='http://www.w3.org/2003/05/soap-envelope'
xmlns:xop='http://www.w3.org/2003/12/xop/include'
xmlns:xmlmime='http://www.w3.org/2004/06/xmlmime'>
<soap:Body>
<m:data xmlns:m='http://example.org/stuff'>
<m:photo xmlmime:content-type='image/png'>
<xop:Include href='cid:http://example.org/me.png'/>
</m:photo>
<m:sig xmlmime:content-type='application/pkcs7-signature'>
<xop:Include href='cid:http://example.org/my.hsh'/>
</m:sig>
</m:data>
</soap:Body>
</soap:Envelope>
![]()
--MIME_boundary
Content-Type: image/png
Content-Transfer-Encoding: binary
Content-ID: <http://example.org/me.png>
![]()
// binary octets for png
![]()
--MIME_boundary
Content-Type: application/pkcs7-signature
Content-Transfer-Encoding: binary
Content-ID: <http://example.org/my.hsh>
![]()
// binary octets for signature
![]()
--MIME_boundary--
为了运行具有 XOP 包的 Web 服务,需要事先进行计划,以确定应该如何设计应用程序,从而避免高峰时过载。应该就优化 Web 服务时应采用何种编码技术与系统管理员团队进行沟通。
您会发现解决这些问题后,您的 Web 服务应用程序优化工作变得容易得多。您可以使用 IBM Relational Web Developer for WebSphere® Software 来开发基于业务流程的 Web 服务,然后在 SOA 内部及各个 SOA 之间将其与 XOP 包一起使用。管理员会发现,解决了这些问题也使得他们的网络管理工作变得更加轻松。他们能确定在不引起系统过载的前提下,可以将多少应用程序与 XOP 包一起使用。
