WSO2 EI 使用 Enrich 中介器的新 xml 标签以及何时动态获取 xml 标签

问题描述

是否可以使用丰富介体将新的 xml 标记添加到 xml 负载

我的示例负载 -

<courses>
   <id>181</id>
   <formatted_name>Learning</formatted_name>
   <score>0</score>
   <status>in_progress</status>
   <issued_certificate />
   <from_timestamp>1626083705</from_timestamp>
   <to_timestamp />
</courses>

标签

<link> www.google.com </link>

我不能使用内联作为源,因为链接是动态获取的。 所以我将新标签添加到有效负载属性中。

<payloadFactory media-type="xml">
    <format>
        <link xmlns="">$1</link>
    </format>
    <args>
        <arg evaluator="xml" expression="get-property('login_link')"/>
    </args>
</payloadFactory>
<property description="Get login link payload" expression="//root/*" name="login_link_xml" scope="default" type="STRING"/>
// get original payload back
<enrich description="Restore original payload">
    <source clone="false" property="course_payload" type="property"/>
    <target type="body"/>
</enrich>
// assign property as a new node inside the courses
<enrich>
    <source clone="true" property="login_link_xml" type="property"/>
    <target action="child" type ="custom" xpath="//courses"/>
</enrich>

这在丰富后提供相同的有效载荷

解决方法

你可以用一些不同的方式来做到这一点。使用 xpath 表达式和函数:concat,使用编码字符

,将“标签”创建为 属性 类型的 OM
<property name="my_link" value="devintegra.com" scope="default" type="STRING"/>
<property name="linkNode" 
          type="OM" 
          expression="concat('&lt;link&gt;',get-property('my_link'),'&lt;/link&gt;')" 
          scope="default" />
        

有了这个属性,你可以丰富你的身体:

<enrich>
  <source type="property" clone="true" property="linkNode"/>
  <target action="child" xpath="//courses"/>
</enrich>

这应该如您所愿。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...