向Elment中添加元素,用appendChild()方法时碰到的问题 Element temp=(Element)content.cloneNode(true);cloneNode()方法只能返回Node对象,可能java.lang.ClassCastException错出在此句 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我想应该不是这个问题,因为意外是出在service_attacheds.appendChild(temp)这一句。 Element temp=(Element)content.cloneNode(true); service_attacheds.appendChild(temp);你的强制类型转换多余cloneNode返回的是Node接口的对象,而appendChild的参数也是Node类型的 Element register=doc1.getDocumentElement();NodeList list=register.getElementsByTagName("service_attached");Element content=(Element)list.item(0);Element rootElmt=doc2.getDocumentElement();NodeList serviceatts=rootElmt.getElementsByTagName("service_attacheds");Element service_attacheds=(Element)serviceatts.item(0);//你这样试一下//Element temp=(Element)content.cloneNode(true);Node temp = doc2.importNode(content, true);service_attacheds.appendChild(temp); 想用java ee做个毕业设计,有什么好项目介绍? jstl 问题 struts2怎么判断session中某个属性为null? 求助~ JasperReport压缩重复值问题。 webwork2.2+spring+hibernate的问题!大家帮忙看看 高分求救:关于xml移植到jsp问题!!解答后立即给分! ajax+json+jquery的小项目放在struts2里就可以,为什么放在spring里就不行? .net 转 Java,请教如何入手 Spring返回视图名后 界面没有跳转 交换代码用于学习! 请各位推荐几本J2EE的书?
service_attacheds.appendChild(temp);
你的强制类型转换多余
cloneNode返回的是Node接口的对象,而appendChild的参数也是Node类型的
NodeList list=register.getElementsByTagName("service_attached");
Element content=(Element)list.item(0);
Element rootElmt=doc2.getDocumentElement();
NodeList serviceatts=rootElmt.getElementsByTagName("service_attacheds");
Element service_attacheds=(Element)serviceatts.item(0);
//你这样试一下
//Element temp=(Element)content.cloneNode(true);
Node temp = doc2.importNode(content, true);
service_attacheds.appendChild(temp);