Reputation: 14550
i have list of maps and want to get all maps with id = 2. when i wrap the list in a holder object, all works correctly (kotlin code):
class Holder(val value : Any)
val list = listOf(mapOf("id" to 2), mapOf("id" to 3))
val context = Holder(list)
val xpath = "value[id = 2]"
JXPathContext.newContext(context).iterate(xpath)
but when i try to get rid of the holder object:
val context = list
val xpath = "[id = 2]"
i get jxpath syntax error: Invalid XPath
. how what's the correct syntax to work with collection as root object?
Upvotes: 0
Views: 144
Reputation: 111621
XML requires that there be a single root element, so XPath provides no way to select multiple root elements.
If you want to use XML, you'll have to wrap your collection of elements with a single root element.
Upvotes: 1