SMA*_*AVA 1 java attributes dom
我需要从文档中的特定元素中删除所有属性。
我如何拥有 xml :
<Book>
<Chapter TotalNoOfWords="2000" NoOfPages="5">
<Line LineNo="1" NumberOfWords="50"/>
</Chapter>
</Book>
Run Code Online (Sandbox Code Playgroud)
我需要它如何:
<Book>
<Chapter>
<Line LineNo="1" NumberOfWords="50"/>
</Chapter>
</Book>
Run Code Online (Sandbox Code Playgroud)
我知道 removeAttribute() 方法。但是此方法只会删除名称已作为参数传递给此方法的属性。我正在寻找可以删除元素中所有属性的东西。对此有任何帮助。
假设你已经有了指定的Node元素,遍历所有元素并删除它们......
while (node.getAttributes().getLength() > 0) {
Node att = node.getAttributes().item(0);
node.getAttributes().removeNamedItem(att.getNodeName());
}
Run Code Online (Sandbox Code Playgroud)
例如...
| 归档时间: |
|
| 查看次数: |
3992 次 |
| 最近记录: |