0

I tried using "contains" function which is supposed to give a boolean if the nodeSeq contains an element, but its not working for me.

For example: seq =

<parent> <child1 /> <child2 /> </parent> 

If I use seq.contains("child1"), it gives me false. Am I missing something ?

1 Answer 1

1

NodeSeq seems to contain a single node (you're "parent" tag) which has children. This code seems to work:

nodeSeq.child.contains(<child1 />) 

Alternatively you can use xpath to find the children

(nodeSeq \\ "child3").nonEmpty == false (nodeSeq \\ "child2").nonEmpty == true (nodeSeq \\ "parent").nonEmpty == true 
Sign up to request clarification or add additional context in comments.

3 Comments

alvinalexander.com/scala/… has some more details around the xpath support.
Thanks @AngeloGenovese. (nodeSeq \\ "child3").nonEmpty worked.
@skhaapioloir, you say this worked, but the answer has not been "accepted". Is there something wrong?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.