How to remove attributes from node using Groovy XMLSlurper and GPathResult?

I need to remove attributes from the node body in some parsed HTML (converted to XML).

+6
source share
2 answers

Call attributes() on the element that contains the attribute, and then call remove('attr name') , as shown below.

 attributes().remove('attr name') 

Here you can read more detailed information.

+5
source
 /** * Remove all attributes from the root body tag */ def removeBodyAttributes() { def attributeNames = bodyXml.attributes().collect {it.key} println attributeNames println bodyXml.attributes() attributeNames.each {bodyXml.attributes().remove(it)} println bodyXml.attributes() } 
+2
source

Source: https://habr.com/ru/post/904199/


All Articles