什么xml错:java.lang.ClassCastException: org.apache.xerces.dom.DeferredDocumentImpl you are trying to cast some variable to a non-compatible type 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你把一个不是org.apache.xerces.dom.DeferredDocumentImpl的造型为一个DeferredDocumentImpl了,仔细看看出错那行有没有造型操作。 程序如下:import java.io.*;import javax.xml.parsers.*;import org.xml.sax.*;import org.w3c.dom.*;import com.sun.xml.tree.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 1998</p> * <p>Company: </p> * @author mzer * @version 1.0 */public class xmldo { public xmldo() { } public static void main(String[] args) { try { //turn xmlfile to byte[] File f = new File("E:\\work\\tool\\src\\tool\\postoffice.xml"); FileInputStream fin = new FileInputStream(f); byte[] byteIN = new byte[(int)f.length()]; fin.read(byteIN); fin.close(); System.out.println("xmlFile open..."); //append node DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); ByteArrayInputStream bf=new ByteArrayInputStream(byteIN); Document m_dDoc=db.parse(bf); //Document m_dDoc=db.getDOMImplementation(); Element eRoot=m_dDoc.getDocumentElement(); Element e1,e2; e1=m_dDoc.createElement("id"); e2=m_dDoc.createElement("sql"); e1.appendChild(m_dDoc.createTextNode("111")); eRoot.appendChild(e1); ByteArrayOutputStream buf=new ByteArrayOutputStream(); //FileOutputStream fo=new FileOutputStream("E:\\work\\tool\\src\\tool\\postoffice.xml"); //System.out.println("xmlFile open...4"); ((XmlDocument)m_dDoc).write(buf); byte[] bArray=buf.toByteArray(); FileOutputStream fo=new FileOutputStream("E:\\work\\tool\\src\\tool\\postoffice.xml"); fo.write(bArray); fo.close(); } catch(Exception e) { e.printStackTrace(); } }} lucene搜索返回内容的一个问题 中文乱码问题 求救,linux下启动tomcat的问题 JMS小问题 我到Hibernate官方网站下的middlegen-hibernate包,怎么用winrar解压缩不了啊?这是什么原因啊? 请问如何把这个对象重新加入到session范围内呢? java 排序问题,高手进。 我的JBOSS出怪事了,大家快来看,散分 hibernate一对多映射怎样存储? 静态代码块有什么用? 高分求助:xml问题!!! 请用一个小的实例来证明为什么要用XML?
import java.io.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import com.sun.xml.tree.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 1998</p>
* <p>Company: </p>
* @author mzer
* @version 1.0
*/public class xmldo { public xmldo() {
}
public static void main(String[] args) {
try
{
//turn xmlfile to byte[]
File f = new File("E:\\work\\tool\\src\\tool\\postoffice.xml");
FileInputStream fin = new FileInputStream(f);
byte[] byteIN = new byte[(int)f.length()];
fin.read(byteIN);
fin.close();
System.out.println("xmlFile open..."); //append node DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
ByteArrayInputStream bf=new ByteArrayInputStream(byteIN);
Document m_dDoc=db.parse(bf);
//Document m_dDoc=db.getDOMImplementation();
Element eRoot=m_dDoc.getDocumentElement();
Element e1,e2;
e1=m_dDoc.createElement("id");
e2=m_dDoc.createElement("sql");
e1.appendChild(m_dDoc.createTextNode("111"));
eRoot.appendChild(e1);
ByteArrayOutputStream buf=new ByteArrayOutputStream();
//FileOutputStream fo=new FileOutputStream("E:\\work\\tool\\src\\tool\\postoffice.xml");
//System.out.println("xmlFile open...4");
((XmlDocument)m_dDoc).write(buf);
byte[] bArray=buf.toByteArray();
FileOutputStream fo=new FileOutputStream("E:\\work\\tool\\src\\tool\\postoffice.xml");
fo.write(bArray);
fo.close();
}
catch(Exception e)
{
e.printStackTrace();
} }
}