Best way to remove an element in an XML using anti-xml

104 views Asked by At

What would be the best and/or simplest way to remove an element from a XML document using anti-xml?

2

There are 2 answers

0
JWC On

Here is one way:

(xml \ "nodeToRemove").filter { _.name != "nodeToRemove"}.unselect.head

Any others?

0
ncreep On

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.