6

我需要从一些已解析的 HTML(转换为 XML)中的正文节点中删除属性。

4

2 回答 2

5

在包含该属性的元素上调用attributes(),然后调用remove('attr name')如下所示。

attributes().remove('attr name')

您可以在此处阅读更多详细信息。

于 2011-12-20T22:41:27.247 回答
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()
}
于 2011-12-20T23:01:37.947 回答