IICS中处理返回首字符为数字的XML REST API响应问题求助
问题:处理XML中首字符为数字的元素时XPath无效错误
问题背景
处理基于XML的REST API数据,需将返回结果保存至平面文件。API返回的XML包含首字符为数字的元素,示例响应如下:
<sg_response> <sgscore> <scores> <score> <period>2022-07</period> <score>650</score> <min>405</min> <25th>585</25th> <50th>660</50th> <75th>710</75th> <max>830</max> </score> </scores> </sgscore> </sg_response>
创建映射时因元素命名问题报错,尝试为输出字段添加前缀p后仍未解决,运行映射时出现以下错误:
[FATAL] Service Info not found for the service 'WebServices_h2r_udt_1i5fk_ONLY_H2R_XMAP_H2R - 4 m.contains.i0.contains.i3 Map: './25th' is not a valid XPath. (Invalid literal found: 25th [err:XPST0003]).- for more information see file://D:/SecureAgent/apps/Data_Integration_Server/data/CMReports/Tmp/2023-07-04/CmInternal_ServiceValidator_A7d55926e-5699-4473-aee4-7829973da881/Events.cme <log_file>D:/SecureAgent/apps/Data_Integration_Server/data/CMReports/Tmp/2023
错误核心是XPath语法不允许直接使用以数字开头的元素名,./25th属于无效表达式。
解决方案
XPath规范中,元素名不能以数字开头,需通过local-name()函数匹配元素名称:
修改XPath表达式
将原来的直接引用元素名写法,替换为通过local-name()定位的格式:- 原错误XPath:
./25th - 修改后XPath:
./node()[local-name()='25th']或./score/*[local-name()='25th'](根据实际XML层级结构调整)
- 原错误XPath:
Informatica映射配置
在XML Source Qualifier或映射的XPath配置中,对所有首字符为数字的元素(如25th、50th、75th)应用上述修改后的XPath。输出字段名保持已添加的前缀(如p25th)即可,无需额外调整。验证XPath有效性
可通过Informatica内置的XPath测试工具,或第三方XPath验证工具确认修改后的表达式能正确提取对应元素的值。
内容的提问来源于stack exchange,提问作者Lan
相关产品推荐
相关产品推荐

