在 ESQL 中使用动态标记从 XML 获取值

Fetch value from XML using dynamic tag in ESQL

我有一个xml

<family>
   <child_one>ROY</child_one>
   <child_two>VIC</child_two>
</family>

我想根据 ESQL 中的动态标记从 XML 中获取值。我试过这样

SET dynamicTag = 'child_'||num;
SET value = InputRoot.XMLNSC.parent.(XML.Element)dynamicTag;

这里的 num 是从输入接收到的值,它可以是 onetwo。如果 numone,结果应该是 value = ROY,如果 numtwo,那么结果应该是 VIC

ESQL field reference overview 章描述了这个用例:

Because the names of the fields appear in the ESQL program, they must be known when the program is written. This limitation can be avoided by using the alternative syntax that uses braces ( { ... } ).

所以可以像这样更改您的代码:

SET value = InputRoot.XMLNSC.parent.(XMLNSC.Element){dynamicTag};

还要注意元素类型的变化,请参阅@kimbert 的评论。