Reputation: 4262
I have an NodeSeq object and want to select a given node which is marked with an attribute. For example let's say there is a tag <div id="content">...</div>
within the NodeSeq.
I tried to select in with the method \\
on NodeSeq as well as with filter.
Let's say seq is my NodeSeq object.
seq \\ "div"
works, but this selects all <div>
elements.
seq.filter(_.attribute("id").equals("content"))
doesn't select any node at all, the resulting list is empty.
How can I select this node?
Upvotes: 1
Views: 1798
Reputation: 2222
Alternatively, you could try the following:
seq.filter(_.attribute("id").exists(_.text.equals("content")))
Upvotes: 0
Reputation: 9448
try
scala> var x= <b>
| <h id="bla"/>
| <h id="blub"/>
| </b>
x \\ "h" filter (h=>(h \ "@id" toString) == "bla")
This should work.
Upvotes: 2