javarosa
javarosa copied to clipboard
null = nodeName
You may not like reading this (likely a historical artefact).... ;)
Apparently this works in Collect as a check to see whether name1 has a value:
not(${name1} = null)
That is really quite wrong.
What I think should happen is that the XPath evaluator should look for the node <null>
that is a child of the evaluation context and compares the string value of that node (if it exists) with the string value of <name1>
.
You can test how null
is treated in a browser developer console:
-
document.evaluate('null', document.querySelector('body'), null, 3).booleanValue
returnsfalse
(<body>
has no child element<null>
) -
now create
<null>
element as a child of<body>
:document.querySelector('body').appendChild(document.createElement('null'))
-
and now the same evaluation as in 1, returns
true
! (regardless of whether the null element has a value which is correct and according to the boolean() spec).
So tl/dr; there is no concept of null
in XPath.
Very interesting! I'm curious to know how you've come across this quirk. Did someone stumble onto it?
Yes, someone was using this and wondered why it wasn't working in Enketo. (I advised to replace null
with ""
). First, I was surprised to see it didn't throw an Exception (in the browser XPath evaluator) and then realized it's just treated like a path to a node.