Reputation: 1724
Is there any way to select following sibling element in xml using Scala?
So if I have xml like this:
<root>
<childA>A</childA>
<randomElementName>B</randomElementName>
</root>
I would like to do selection like this:
(root \ "childA") followingSibling text
that will give me "B"
Upvotes: 0
Views: 271
Reputation: 38045
I guess it's not as elegant as you expected, but it works:
root.
child.
dropWhile{ _.label != "childA" }.
collect{ case e: xml.Elem => e }.
drop(1).
headOption.
map{ _.text }
// Option[String] = Some(B)
There is no XPath
in scala.xml
, so you should work with it as with collection.
Upvotes: 1