首页 > 解决方案 > WSO2 EI 新的 xml 标签使用 Enrich 调解器和当 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>

这在丰富后给出了相同的有效载荷

标签: wso2wso2esbwso2eiei

解决方案


你可以用一些不同的方式来做。使用 xpath 表达式和函数创建您的“标签”作为属性类型 OM: concat,带编码字符

<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>

这应该可以按您的预期工作。


推荐阅读