Ho bisogno di rimuovere gli attributi da un nodo del corpo in un HTML analizzato (convertito in XML).Come si rimuovono gli attributi da un nodo usando Groovy's XMLSlurper e GPathResult?
6
A
risposta
5
Chiamare lo attributes()
sull'elemento che contiene l'attributo e quindi chiamare remove('attr name')
come illustrato di seguito.
attributes().remove('attr name')
Qui puoi leggere maggiori dettagli.
2
/**
* 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()
}
Ah, non ho potuto vedere il metodo attributes() nella documentazione. Grazie per il puntatore e anche vedere il metodo finale che mi è venuto in mente. –