0

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"

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.