基于App Connect Enterprise v11,如何为JSON数据制作DFDL Schema?
为App Connect Enterprise v11中的JSON数据创建DFDL Schema的实操方案
核心逻辑说明
和处理记录导向文本不同,JSON是层级化结构,DFDL无需手动定义分隔符,只需对应JSON的嵌套层级、键名和数据类型来映射即可。ACE v11的DFDL内置JSON解析能力,直接基于JSON结构编写Schema即可。
针对你的JSON示例的DFDL Schema编写步骤
1. 完整Schema代码
直接对应你的JSON结构编写如下XML格式的DFDL Schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dfdl="http://www.ibm.com/xmlns/prod/dfdl/1.0" targetNamespace="http://your-custom-namespace.com/complaint" xmlns="http://your-custom-namespace.com/complaint" elementFormDefault="qualified"> <!-- 全局JSON格式属性组,统一指定解析规则 --> <xs:attributeGroup name="jsonBaseProps"> <xs:attribute name="dfdl:format" type="xs:string" fixed="json"/> <xs:attribute name="dfdl:ignoreCase" type="xs:boolean" fixed="false"/> <xs:attribute name="dfdl:documentRoot" type="xs:boolean" fixed="true"/> </xs:attributeGroup> <!-- 根元素,对应整个JSON对象 --> <xs:element name="ComplaintReply" attributeGroup="jsonBaseProps"> <xs:complexType> <xs:sequence> <!-- 映射JSON中的YourComplaint子对象 --> <xs:element name="YourComplaint"> <xs:complexType> <xs:sequence> <xs:element name="Type" type="xs:string"/> <xs:element name="Reference" type="xs:string"/> <xs:element name="Text" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <!-- 映射JSON中的Reply子对象 --> <xs:element name="Reply"> <xs:complexType> <xs:sequence> <xs:element name="OurReference" type="xs:string"/> <xs:element name="Text" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
2. 关键配置要点
dfdl:format="json":告诉DFDL解析器按JSON语法规则处理数据,自动识别大括号、逗号、引号等符号- 元素名称必须和JSON中的键名完全匹配(大小写敏感,若需忽略大小写可设置
dfdl:ignoreCase="true") - 数据类型直接使用标准XML Schema类型(如
xs:string对应JSON字符串,xs:int对应数字等)
3. ACE中部署使用步骤
- 将上述代码保存为
.xsd格式文件 - 在ACE Toolkit中把该Schema导入到消息流项目
- 使用
DFDL Parser或DFDL Serializer节点,指定该Schema作为解析/序列化模板 - 测试时输入你的JSON示例,即可生成层级清晰的逻辑树结构
额外注意事项
- 若JSON存在可选字段,给对应元素添加
minOccurs="0"属性 - 处理JSON数组时,给数组元素节点设置
maxOccurs="unbounded" - 也可使用ACE Toolkit的DFDL可视化编辑器创建,减少手动编写XML的错误
内容的提问来源于stack exchange,提问作者Amr M.
相关产品推荐
相关产品推荐

