Reputation: 1605
I am currently trying to run an XQuery file via Java. Since I am very new to XQuery, not sure how to debug it. When i run the XQ, i get the following error:
XQuery Processor Exception: Exception while calling Saxon: Required item type of first operand of '/' is node(); supplied value has item type xs:anyAtomicType; SystemID: ; Line#: 301; Column#: -1; Cause: Error on line 301 XPTY0019: Required item type of first operand of '/' is node(); supplied value has item type xs:anyAtomicType
Now I want to know how do i pin point the line which is throwing the error?
EDIT:
if ($ipItems) then (
for $item in $ipItems
let $ipAddress := data ($item/nc:IpAddressList/nc:ipAddress)
After numurous attempts i finally pinpointed the root casue to the let command, if i remove it, the code runs fine. Can you please let me know, what i did wrong in there.
Upvotes: 0
Views: 1162
Reputation: 163262
I'm having trouble understanding exactly why you are struggling with this. The code fragment you have shown us is presumably somewhere around line 301 of the query. The error message refers to the "/" operator, and there are only two "/" operators in your query. The first operand of the first "/" operator (A) is $item
, and the first operand of the second "/" operator (B) is $item/nc:IpAddressList
. If B returns anything, it can only return nodes, so its static type is node()*, so B is not the problem. So the problem must be A. The item type of $item
is the same as the item type of $ipItems
, so the error message is telling you that $ipItems
contains atomic values rather than nodes. Saxon might give you this error at compile time if it can work out that the value of $ipItems
will always contain atomic values, or it might give you the error at run-time if the run-time value is atomic. In this case I suspect it's a compile-time error, because for a run-time error the message would be more specific, e.g. it would tell you that $item is an xs:decimal
, perhaps, or an xs:date
.
At this stage we can't help you any more because we need to see how $ipItems
is initialized. Chances are, it's initialized to a value that can only ever be atomic: an example might be let $ipItems := distinct-values(xx/yy/zz)
. An atomic value can't have a child element named nc:IpAddressList
, so this can never make sense.
Upvotes: 2
Reputation: 3517
The problem is almost certainly this path expression $item/nc:IpAddressList
. The problem is that $item
binds to a value of xs:anyAtomicType
whereas path expressions only operate on nodes. You should do some debugging to see what the value of $item
is at runtime.
Upvotes: 2