This is my problem. Im receiving the following xml from a DS that has an event trigger to the ESB.
<messageCollection xmlns="http://services.core.solution.com/ds/queue">
<message>
<messageid>3083e5b9-f8fd-426f-a017-42439f47eefc</messageid>
<messagetypeid>1</messagetypeid>
<message>''</message>
<processed>false</processed>
<createddate>2014-12-30T14:38:11.782-04:00</createddate>
<modifieddate>2014-12-30T14:38:11.782-04:00</modifieddate>
<count>7</count>
</message>
<message>
<messageid>2283e5b9-f8fd-426f-a017-42439f47eefc</messageid>
<messagetypeid>2</messagetypeid>
<message>''</message>
<processed>false</processed>
<createddate>2014-12-30T14:38:11.782-04:00</createddate>
<modifieddate>2014-12-30T14:38:11.782-04:00</modifieddate>
<count>7</count>
</message>
</messageCollection>
and in a payload mediation Im implementing this:
<payloadFactory media-type="xml">
<format>
<p:updateLastPollingControl xmlns:p="http://services.core.solution.com/ds/queue">
<xs:lastpolling xmlns:xs="http://services.core.solution.com/ds/queue">$1</xs:lastpolling>
</p:updateLastPollingControl>
</format>
<args>
<arg evaluator="xml" expression="//ns:message[last()]/ns:createddate" /> </args>
</payloadFactory>
Why it is always returning null value. If I harcoded the date everything works fine.
In a desperate move I also tried:
> //ns:message[last()]/ns:createddate/text()
> /*/ns:message[last()]/ns:createddate
> //ns:message[last()]/createddate
> /*/message[last()]/createddate
but nothing seems to work.
Any ideas? Thanks
(Disclaimer: I am not familiar with WSO2, only with XML/XPath.)
It seems to me that your problem is due to the default namespace in your XML input:
<messageCollection xmlns="http://services.core.solution.com/ds/queue">
This default namespace not only applies to the messageCollection
element, but all of its descendants, too, including the message
element. Also, even if it is in a namespace, the element name of message
remains "message", and is not "ns:message".
Further, I cannot see where you declare or register the namespace http://services.core.solution.com/ds/queue
, i.e. associate it with the prefix ns:
. If you don't, there is no connection between the prefix and the namespace.
To test this hypothesis, try
//*:message[last()]/*:createddate
and
//*[local-name() = 'message'][last()]/*[local-name() = 'createddate']
and let me know if those expressions return anything.
The above expressions do not really take into account namespaces, rather, they disregard them. The proper way to deal with namespaces is to declare them. According to this page, perhaps the correct way to register this namespace is
<args>
<arg evaluator="xml" expression="//ns:message[last()]/ns:createddate" xmlns:ns="http://services.core.solution.com/ds/queue"/>
</args>