What would be the best and/or simplest way to remove an element from a XML document using anti-xml?
Asked
Active
Viewed 98 times
2 Answers
1
Here is one way:
(xml \ "nodeToRemove").filter { _.name != "nodeToRemove"}.unselect.head
Any others?
JWC
- 1,745
- 2
- 12
- 14
1
Not sure whether this is better or not, but you could use the drop method, like so:
(xml \\ 'nodeToRemove drop 1).unselect.head
which assumes a single occurrence of nodeToRemove; you can drop all items in the resulting Zipper if there is more than one occurrence.
Also, as the drop complements, the take and slice methods remove anything that's not included in their ranges.
ncreep
- 473
- 3
- 11