首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

用JDOM的同名标签如何删除?

2012-01-24 
用JDOM的同名标签怎么删除?急localeslocalelanguage-country zh_CN pairlabel-key 1111 label-

用JDOM的同名标签怎么删除?急
<locales>
                  <locale   language-country= "zh_CN ">
<pair   label-key= "1111 "   label-value= "aaaa "   />
                  <pair   label-key= "2222 "   label-value= "bbbb "   />
                  <pair   label-key= "3333 "   label-value= "dddd "   />

                  </locale   language-country= "zh_CN ">

</locales>


如上面的XML文件   用JDOM读成DOC对象后怎么删除   比如我要删除

<pair   label-key= "2222 "   label-value= "bbbb "   />

这个Element   怎么删除?


[解决办法]
在JDOM的API中(可能存在版本不一致的问题)
1./////////
removeChild
public boolean removeChild(Element element)
This will remove the specified Element.

Parameters:
child - Element to delete.
Returns:
boolean - whether deletion occurred.
2.///////////
public boolean removeChild(java.lang.String name)
This will remove the Element with the specified name. If multiple Elements exist with that name, the first matching child is removed.

Note:Currently, this does not assume that you want the default namespace. I can perform removeChild( "foo:bar "), and it does the right thing. But if I have a document with elements <foo:bar> as well as <bar> , this currently removes the first of those when removeChild( "bar ") is invoked. Do we want to explicitly enforce the default namespace (none) if no prefix is given? (brett)

Parameters:
name - String name of child to delete.
Returns:
boolean - whether deletion occurred.

热点排行