In which cases does ParseJson of JsonBuilder return an XdmValue and not an XdmItem?
Added by Martin Honnen over 2 years ago
I am wondering why ParseJson of JsonBuilder in Saxon 11 returns an XdmValue (and not an XdmItem), it seems an XDM map is an XdmItem, as is an XDM array, as is any atomic boolean, string or double value.
Is that just for the JSON null which would map to an empty sequence and is therefore representend by an XdmEmptySequence,, a subclass of XdmValue?
Replies (4)
Please register to reply
RE: In which cases does ParseJson of JsonBuilder return an XdmValue and not an XdmItem? - Added by Michael Kay over 2 years ago
Yes, I think that's correct: XdmEmptySequence is a possible return value.
RE: In which cases does ParseJson of JsonBuilder return an XdmValue and not an XdmItem? - Added by Martin Honnen over 2 years ago
If I am using JsonBuilder.ParseJson and need to feed the result to an API that takes an XdmItem and not an XdmValue, what is the right and straightforward way to get from the returned XdmValue to an XdmItem? ParseJson(jsonString).Simplify() as XdmItem
?
RE: In which cases does ParseJson of JsonBuilder return an XdmValue and not an XdmItem? - Added by Michael Kay over 2 years ago
The simplest is probably value.itemAt(0)
.
RE: In which cases does ParseJson of JsonBuilder return an XdmValue and not an XdmItem? - Added by Michael Kay over 2 years ago
Afterthought: you shouldn't assume that an empty XdmValue
is always represented as an instance of XdmEmptySequence
.
For example, new XdmValue(EmptySequence.getInstance())
creates an empty XdmValue that is not an XdmEmptySequence.
(How nice it would be if Java allowed the constructor for a class to return an instance of a subclass...)
Please register to reply