Performing complicated XPath queries in Scala

前端 未结 5 1170
灰色年华
灰色年华 2021-01-04 08:14

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         


        
5条回答
  •  失恋的感觉
    2021-01-04 09:03

    I think I'm going to go with lightly pimping XOM. It's a bit of a shame the XOM authors decided against exposing collections of child nodes and the like, but they had more work and less advantage to doing so in Java than in Scala. (And it is an otherwise well-designed library.)

    EDIT: I wound up pimping JDOM after all, because XOM doesn't compile XPath queries ahead of time. Since most of my effort was directed towards XPath this time, I was able to come up with a good model that sidesteps most of the generics issues. It shouldn't be too hard to come up with reasonable genericized versions of the methods getChildren and getAttributes and getAdditionalNamespaces in org.jdom.Element (by pimping the library with new methods that have slightly changed names.) I don't think there's a fix for getContent, and I'm not sure about getDescendants.

提交回复
热议问题