What\'s the simplest API to use in scala to perform the following XPath queries on a document?
//s:Annotation[@type=\'attitude\']/s:Content/s:Parameter[@role
//s:Annotation[@type='attitude']/s:Content/s:Parameter[@role='type' and not(text())]
Well, I don't understand the s:
notation, and couldn't find it on XPath spec either. However, ignoring that this would look like this:
(
(xml
\\ "Annotation"
filter (_ \ "@type" contains Text("x"))
)
\ "Content"
\ "Parameter"
filter (el => (el \ "@type" contains Text("type")) && el.isInstanceOf[Text])
)
Note the necessity of parenthesis because of higher precedence of \
over filter
. I have changed the formatting to a multi-line expression as the Scala equivalent is just way too verbose for a single line.
I can't answer about namespaces, though. No clue how to work with them on searches, if it's even possible. The docs mention @{uri}attribute
for prefixed attributes, not does not mention anything about prefixed elements. Also, note that you need to pass an uri which resolves to the namespace you want, as literal namespaces in search are not supported.