Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » WebService/XML/JSON/SOAP/SOA » XML  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请教jdom修改xml的问题
souhou





发贴: 4
积分: 1
于 2005-08-01 16:37 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
jdom读xml文件时,找到某个结点后停止遍历,对它做了修改,然后更新,更新后的文件丢失了该修改了的结点的所有子结点.^_^我觉得是我概念上理解有问题.请教是哪里出了错?谢谢啦:)
代码如下:
类里有一个私有Element变量foundE
//找到具有特定名称的结点
public void navigate(String s, Element e){
if(e.getName().equals(s)){
foundE = e;
}else{
for(Iterator it = e.getChildren().iterator();it.hasNext();){
Element ele = (Element)it.next();
navigate(s,ele);
}
}
}
//修改找到的结点并更新
public void modify(){
try{
SAXBuilder saxB = new SAXBuilder();
Document circles = saxB.build("Employees.xml");
Element root = circles.getRootElement();
//Jack是Employees.xml里的一个元素,所以不存在找不到的问题
navigate("Jack",root);
foundE.setText("1");
XMLOutputter outPut = new XMLOutputter();
OutputStream out = new FileOutputStream("Employees.xml");
outPut(circles,out);
}catch(JDOMException jdomE){
System.out.println(jdomE);
}catch(IOException ioE){
Sysem.out.println(ioE);
}
}



作者 Re:请教jdom修改xml的问题 [Re:souhou]
ranchgirl



版主


发贴: 801
积分: 132
于 2005-08-23 13:05 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
"jdom读xml文件时,找到某个结点后停止遍历,对它做了修改,然后更新,更新后的文件丢失了该修改了的结点的所有子结点"

Is that it supposed to do?



作者 Re:请教jdom修改xml的问题 [Re:souhou]
souhou





发贴: 4
积分: 1
于 2005-09-08 07:59 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
除了更新的结点其他结点的信息应该不变.可是我写的程序却丢失了该修改了的结点的所有子结点.是navigate(s,e)找到要修改后的结点就退出了,没有遍历该结点的所有子节点.
对不起,找到哪错了后忘了说问题已经解决了,也一直没上来看Smile还是谢谢版主^_^



作者 Re:请教jdom修改xml的问题 [Re:souhou]
bluejerry





发贴: 1
积分: 0
于 2005-09-15 11:19 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
没有访问到子节点呀。


作者 Re:请教jdom修改xml的问题 [Re:souhou]
xhxasdf





发贴: 57
积分: 0
于 2005-09-15 11:58 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
修改没有这个必要把?
还要重新写入文件啊?
直接元素修改 修改("name","value");
有这个方法的呀~




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923