Announcement Announcement Module
Collapse
No announcement yet.
xpath-splitter and empty xpath result Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • xpath-splitter and empty xpath result

    Hello.

    My goal is to process some XML like
    Code:
      <items>
        <item>value1</item>
        <item>value2</item>
        <item>value3</item>
      </items>
    And convert it to a List of my beans that could be created with static MyBean.create(String).
    Here is a context fragment:
    Code:
        <int:chain input-channel="..." output-channel="...">
            <int-xml:xpath-splitter>
                <int-xml:xpath-expression expression="/items/item" />
            </int-xml:xpath-splitter>
            <int-xml:xpath-transformer evaluation-type="STRING_RESULT" xpath-expression="/" />
            <int:transformer expression="T(MyBean).create(payload)" />
            <int:aggregator />        
        </int:chain>
    It works quite well when the input message contains some items. But I'm failed to get an empty list when the message doesn't contains any items.
    As far as I understand from code, XPathMessageSplitter throws an exception when the result collection is empty. Is there any way to work around that?

    Regards,
    -- Alexey

  • #2
    Add an xpath-filter upstream of the splitter...

    Code:
        <int:chain input-channel="..." output-channel="...">
            <int-xml:xpath-filter>
                <int-xml:xpath-expression expression="/items/item" />
            </int-xml:xpath-filter>
            <int-xml:xpath-splitter>
                <int-xml:xpath-expression expression="/items/item" />
            </int-xml:xpath-splitter>
            <int-xml:xpath-transformer evaluation-type="STRING_RESULT" xpath-expression="/" />
            <int:transformer expression="T(MyBean).create(payload)" />
            <int:aggregator />        
        </int:chain>

    Comment


    • #3
      I'm using a gateway around that chain and it is not happy, when filter gobbles the request. I've added an xpath-router to check if there are any items or not. If no, I manually generate an empty list.

      Comment

      Working...
      X