Saturday, September 14, 2013

Subtracting Times in OSB using XQuery expression

If there is a need to calculate the Round Trip time of incoming and outgoing message in a Proxy Service of OSB we have an approach.

To subtract times you can use op:subtract-times() xquery function in OSB.

Example:

assing fn:current-time() to variable requestInTime.

Now to calculate the round trip time you can do the following in which we use the $requestInTime variable.

fn:substring-before(fn:substring(string(op:subtract-times(fn:current-time(),xs:time($requestInTime))), 3),'S')

Use above function in XQUERY expression in required action like assign, insert,replace.

Here, I've done some amount of formatting based on my requirement.
Essentially we need to use the op:subtract-times() function.

Hope this helps when you have a situation.

Friday, September 13, 2013

How to access an XML element with unknown name space prefix

We may come across a situation in which we are not sure of the namespace prefix of certain element. To retrieve such an element using XPATH we can use the wild character *

Example:

Say we have information of employees of an organization in an XML. XSD corresponding to employees.xml is employees.xsd. Also address details are separately defined in an XSD ,address.xsd and this XSD is referred in employees.xsd.

I am trying to access City of the first employee among multiple employees, and I do not know the namespace prefix of the Address element. Then I would write an Xpath as follow.


ns0:Employees/ns0:Employee[1]/*:Address/*:City/text()


This situation has helped me in writing an xquery expression in OSB.

However, it is always better to know what are all the namespaces and their prefixes that we are dealing with.