System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
 
DocumentBuilderFactory domfac=DocumentBuilderFactoryImpl.newInstance();// 从DOM工厂获得DOM解析
DocumentBuilder dombuilder=domfac.newDocumentBuilder();
//解析XML文档,得到一个Document
Document doc=dombuilder.parse(file);
//获得文档的根节点
Element root=doc.getDocumentElement();
//得到节点的子节点
NodeList childRoot=root.getChildNodes();
请教这个有问题吗?
错误提示:
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R org.apache.xerces.util.ObjectFactory$ConfigurationError: Provider org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl could not be instantiated: java.lang.NullPointerException
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.util.ObjectFactory.newInstance(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.impl.dv.DTDDVFactory.getInstance(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.impl.dv.DTDDVFactory.getInstance(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.parsers.DTDConfiguration.createDatatypeValidatorFactory(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.parsers.DTDConfiguration.<init>(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.parsers.StandardParserConfiguration.<init>(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.parsers.IntegratedParserConfiguration.<init>(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.parsers.XML11Configuration.<init>(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.parsers.XML11Configuration.<init>(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at java.lang.Class.newInstance2(Native Method)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at java.lang.Class.newInstance1(Class.java(Compiled Code))
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.util.ObjectFactory.newInstance(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.util.ObjectFactory.findJarServiceProvider(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.util.ObjectFactory.createObject(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.util.ObjectFactory.createObject(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.jaxp.DocumentBuilderImpl.<init>(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(Unknown Source)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at com.yss.ciss.socket.bus.impl.SocketImpl.writeFile(SocketImpl.java:109)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at com.yss.ciss.socket.bus.impl.SocketImpl.runSocketImpl(SocketImpl.java:69)
[09-3-25 10:33:11:422 CST] 49f50d26 SystemErr     R  at com.yss.ciss.socket.bus.impl.SocketThread.run(SocketThread.java:45)

解决方案 »

  1.   

    没用过这种方式
    System.setProperty("javax.xml.parsers.DocumentBuilderFactory", 
    "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); 
    DocumentBuilderFactory domfac=DocumentBuilderFactoryImpl.newInstance(); 
    可能加载没成功,工厂类有问题,也可能这里提到的两个类没有加载jar
      

  2.   

    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
    都加载了
      

  3.   

    建议先写个小程序测试一下吧参考别人xml成功的例子