xml相关……!?
<Topic>
<Replys>
<Reply>
<ReplyID>30194585</ReplyID>
<Point>5</Point>
<Content>内容1</Content>
</Reply>
<Reply>
<ReplyID>30198235</ReplyID>
<Point>15</Point>
<Content>内容2</Content>
</Reply>
</Replys>
</Topic>
应该如何将ReplyID为30194585的Reply元素删除掉
我用的是jdom……
问题点数:60、回复次数:7Top
1 楼yonghar(http://www.xio.name)回复于 2005-09-22 17:17:06 得分 20
先获得Element:
<Reply>
<ReplyID>30194585</ReplyID>
<Point>5</Point>
<Content>内容1</Content>
</Reply>
以及他的父节点:
然后removeContent(Content child)Top
2 楼hugoon(MyServices)回复于 2005-09-22 17:47:11 得分 20
学习Top
3 楼jsp_servlet_javabean(我绝对是一个优秀的程序员,我并非浪得虚名!)回复于 2005-09-22 17:59:25 得分 0
yonghar(ohno)
你是说先得到Element(ReplyID)
然后得到Element(Reply)
最后Element(Reply).removeContent(Element(ReplyID))
那么就是先得到所有的Reply然后循环查看ReplyID的text,看是否是30194585
如果是Replys.removeContent(Reply)
有没快速的查找方式,这样很慢,有没直接能定位的方式……Top
4 楼jsp_servlet_javabean(我绝对是一个优秀的程序员,我并非浪得虚名!)回复于 2005-09-22 18:00:29 得分 0
错了
先得到Element(Reply)
然后得到Element(Replys)Top
5 楼fanhibernate()回复于 2005-09-22 18:33:25 得分 20
建议使用dom4j比jdom好用的多Top
6 楼jsp_servlet_javabean(我绝对是一个优秀的程序员,我并非浪得虚名!)回复于 2005-09-23 10:18:06 得分 0
java.util.List list=parent.getChildren();
java.util.Iterator it=list.iterator();
while(it.hasNext())
{
Element child=(Element)it.next();
if(child.getChild("ReplyID").getText().equals("30194585"))
{element.removeContent(child);break;}
}
这样居然会有错
Exception in thread "main" java.util.ConcurrentModificationException
at org.jdom.ContentList$FilterListIterator.checkConcurrentModification(C
ontentList.java:1041)
at org.jdom.ContentList$FilterListIterator.hasNext(ContentList.java:752)
at zaiu.util.XMLProperties.delete1Property(XMLProperties.java:40)
at zaiu.util.XMLProperties.main(XMLProperties.java:23)Top
7 楼jsp_servlet_javabean(我绝对是一个优秀的程序员,我并非浪得虚名!)回复于 2005-09-23 20:41:57 得分 0
java.util.List list=element.getChildren();
java.util.Iterator it=list.iterator();
while(it.hasNext())
{
Element child=(Element)it.next();
if(child.getChild(name).getText().equals(value))
{
element.removeContent(child);
}
如何一下子删除父元素下的两个子元素后再保存……Top




