0

In one of my projects I'm using

  • XQuery 3.0
  • Saxon HE 9.8 (transitive because of Camel)
  • Spring Boot 2.1.0
  • Apache Camel 2.22.0

I consume a XML message in which the following element occurs:
<mytimeelement></mytimeelement>

As you can see it is empty so I thought that the following XQuery-Expression would return an empty sequence:

$transaction/*:flags/*:mytimeelement

Unfortunately this seems not to be the case because calling the XQuery-Expression from above in an xs:time($arg) like:

xs:time($transaction/*:flags/*:mytimeelement)

does not return an empty sequence as I would have expected but instead returns an exception:

Invalid time "" (too short)

The thing is: I want to use the xs:time($arg) as validation that if a value is in the element it has to have the correct format, but if it's empty it doesn't matter. So I did this not only with xs:time but also with xs:date and xs:decimal.

My question now is: Why is the expression not returning an empty sequence but an empty string? Or should I better use a cast as xs:time instead?

the hand of NOD
  • 1,639
  • 1
  • 18
  • 30
  • 1
    Why would a path like `$transaction/*:flags/*:mytimeelement` selecting `mytimeelement` elements select an empty sequence if such an element exists? You would need to add a predicate `$transaction/*:flags/*:mytimeelement[normalize-space()]` to select an empty sequence if the element contains only white space or nothing. Of couse you can also try a cast `$transaction/*:flags/*:mytimeelement[. castable as xs:time]` if that is what you are looking for. – Martin Honnen Jun 13 '19 at 12:47
  • Yes you're absolute right. I guess I was missing the forest through the trees. Thanks a lot for the answer – the hand of NOD Jun 13 '19 at 13:01

0 Answers0