只知道节点的名称,如何把节点删除?

blackrye 2004-11-27 09:25:10
不知道该节点属于第几层节点,我可以用xpath取得该节点的内容,但是不知道怎么才能把该节点的所有子孙都删除,我用的是JDOM,谁知道怎么实现吗?
...全文
102 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
vcvj 2004-11-29
  • 打赏
  • 举报
回复
Node node=XPath.selectSingleNode(...

node.getParent().removeNode...(node)..

that's ok.
vcvj 2004-11-29
  • 打赏
  • 举报
回复
Xpath belongs in DOM of W3C, if you got the Node using Xpath, I feel you can use node.getParent().removeNode... directly (it's a operation of DOM).
zcjl 2004-11-29
  • 打赏
  • 举报
回复
楼主这样的问题很奇怪哦
jdom的Element类有很多remove方法的
如果在使用这些remove方法的时候有什么困难的话
请把问题说得更具体些
不然让人都不知道该如何回答
z3h 2004-11-27
  • 打赏
  • 举报
回复
org.w3c.dom.Node 中有一个方法 removeChild(Node oldChild)

public Node removeChild(Node oldChild)
throws DOMExceptionRemoves the child node indicated by oldChild from the list of children, and returns it.

Parameters:
oldChild - The node being removed.
Returns:
The node removed.
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised if oldChild is not a child of this node.

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧