Reputation: 55759
e.g.
Is it accurate to describe the folowing as a sequence of text nodes?
("foo", "bar", "baz")
Upvotes: 0
Views: 82
Reputation: 38712
No, they aren't. Strings are not equal to text nodes, this is a sequence of strings.
Text nodes are of type Node
, which again is an item
(these are the most general data type in XQuery). Strings are derived from xs:anyAtomicType
, which again is also an item
.
Have a look at XQuery's data type diagram.
A sequence of text nodes could be constructed using
(text { "foo" }, text { "bar" }, text { "baz" })
You can easily determine the type of a node using the typeswitch
construct:
for $item in (text { "foo" }, "bar", 42)
return
typeswitch($item)
case text()
return "text node"
case xs:string
return "string"
default
return "Something else"
You can also test for inherited types:
for $item in (text { "foo" }, "bar", 42)
return
typeswitch($item)
case node()
return "node"
case xs:anyAtomicType
return "anyAtomicType"
default
return "Something else"
Upvotes: 3