user3758298
user3758298

Reputation: 380

WSO2 ESB Xpath and getting child nodes

I'm using a payload Factory and I want to select all the child nodes of the parent node. The problem is when I select all the child nodes using different Xpath expressions it returns the values but none of the nodes.

so rather than getting what I want

    <child1>value1</child1>
    <child2>value2</child2>
    <child3>value3</child3>

I'm getting this

value1value2value3

The different Xpath expressions I've tried so far are

parent/child::node()
parent/node()
parent//*

Upvotes: 2

Views: 2559

Answers (1)

Jean-Michel
Jean-Michel

Reputation: 5946

If you refer leaf nodes, you will get their values. If you refer nodes having child nodes, you will get xml fragments.

Input message :

<parent>
  <child>value1</child>
  <child>value2</child>
  <child>value3</child>
</parent>

Payload factory :

<payloadFactory media-type="xml">
<format>
      <result xmlns="">
        $1
      </result>
</format>
<args>
   <arg evaluator="xml" expression="//parent"/>
</args>
</payloadFactory>

Result :

<result>
  <parent>
    <child>value1</child>
    <child>value2</child>
    <child>value3</child>
  </parent>
</result>

Payload factory :

...
<arg evaluator="xml" expression="//child"/>
...

Result :

<result>value1value2value3</result>

Don't know how to solve that with payloadFactory, but you can use XSLT or javascript

Sample using javascript :

<script language="js"><![CDATA[
  mc.setPayloadXML(<result>{mc.getPayloadXML()..*::child}</result>);
]]></script>

Upvotes: 1

Related Questions