Element temp=(Element)content.cloneNode(true);cloneNode()方法只能返回Node对象,可能java.lang.ClassCastException错出在此句

解决方案 »

  1.   

    我想应该不是这个问题,因为意外是出在service_attacheds.appendChild(temp)这一句。
      

  2.   

    Element temp=(Element)content.cloneNode(true);
            service_attacheds.appendChild(temp);
    你的强制类型转换多余
    cloneNode返回的是Node接口的对象,而appendChild的参数也是Node类型的
      

  3.   

    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);