【问题标题】:wso2 esb enrich text in xmlwso2 esb 丰富 xml 中的文本
【发布时间】:2017-12-07 22:37:00
【问题描述】:

我正在尝试使用 WSO2 ESB 版本 4.9.0 丰富 XML 节点的文本。

简单的 XML:

<enrich>
    <source type="inline">
        <query><where><order.id>0</order.id></where></query>
    </source>
    <target type="body" />
</enrich>

丰富:

<enrich>
    <source type="property" property="uri.var.processId" />
    <target action="replace" type="body" xpath="//order.id/text()" />
</enrich>

但输出看起来像这样:

<query xmlns="http://ws.apache.org/ns/synapse"><where><order.id>0</order.id></where>SOHBSS-000002</query>

当我期待这个时:

<query xmlns="http://ws.apache.org/ns/synapse"><where><order.id>SOHBSS-000002</order.id></where></query>

当我将给定的 XML 进一步简化为 &lt;order.id&gt;0&lt;/order.id&gt; 时,上面的相同丰富调解器会给出正确的 &lt;order.id xmlns="http://ws.apache.org/ns/synapse"&gt;SOHBSS-000002&lt;/order.id&gt; 输出。

xpath 错了吗?或者我是否将丰富的调解器用于它不适合的东西?

因为 XML 很简单,所以我试图不使用 XSLT 来进行更改。

【问题讨论】:

    标签: xml xpath wso2esb


    【解决方案1】:

    在您的第二次丰富中,尝试将目标类型从正文替换为自定义:

    <enrich>
        <source type="property" property="uri.var.processId" />
        <target action="replace" type="custom" xpath="//order.id/text()" />
    </enrich>
    

    【讨论】:

    • 当我使用 type="custom" 时出现以下错误:EnrichMediator Invalid Target object 要丰富(我没有在这两个丰富中介之间做任何其他事情,所以我不知道为什么会以错误结束)
    • 我必须另外为 XML 设置一个空的命名空间: - 现在它正在工作。谢谢
    【解决方案2】:

    我在尝试对带有名称空间的标签执行 xpath 时遇到了一些困难,所以这里是(感谢 Lesrac 为您提供关于 xmlns 的 cmets)

    <enrich>
        <source type="inline">
            <query namespace="http://www.fadata.bg/Insurance_Messages/v3.0/xml/">
              <where><order.id>0</order.id></where></query>
        </source>
        <target type="body" />
    </enrich>
    <enrich>
        <source type="property" property="uri.var.processId" />
        <target action="replace" type="custom" xpath="//fadata:order.id/text()"
           xmlns:fadata="http://www.fadata.bg/Insurance_Messages/v3.0/xml/"/>
    </enrich>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 2021-11-14
      相关资源
      最近更新 更多