使用Simple Transformation(ST)能否取消XML属性自动排序?
如何取消SAP Simple Transformation(ST)中XML属性的自动排序
SAP Simple Transformation(ST)默认会对生成的XML属性按字母顺序排序,若要保留你在ST模板中定义的属性顺序,可通过以下方法实现:
解决方案:移除父元素的结构体绑定,手动逐个映射字段
当你在元素上使用tt:ref绑定整个结构体时,ST会自动遍历结构体字段并按字母顺序生成属性,覆盖你手动定义的顺序。因此需要:
- 移除父元素(如
Element1)上的tt:ref="TOP"属性 - 每个
tt:attribute的value-ref使用完整的结构体字段路径(如TOP-FIELD01)
修改后的ST代码示例:
<?sap.transform simple?> <tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <tt:root name="TOP" type="ddic:ZZ_STRUCTURE_XML"/> <tt:template> <Element1> <tt:attribute name="Name" value-ref="TOP-FIELD01"/> <tt:attribute name="Version" value-ref="TOP-FIELD02"/> <tt:attribute name="Tag" value-ref="TOP-FIELD03"/> </Element1> </tt:template> </tt:transform>
效果验证
修改后生成的XML将严格遵循你在ST模板中定义的属性顺序:
<?xml version="1.0" encoding="utf-8"?> <Element1 Name="xx" Version="xx" Tag="xx"/>
说明:ST的自动属性排序是默认行为,用于保证输出一致性,但通过手动逐个绑定字段的方式,可强制保留自定义的属性顺序。
内容的提问来源于stack exchange,提问作者Monsieurlxl
相关产品推荐
相关产品推荐

