55,疯了原来程序中用的老包parser.jar和xerces.jar,加上xalan,serializer.jar, 以上的parseXML方法不会出错,但是在保存文件到有空格的目录就不行了。
保存文件的代码:
 public void saveXML(String fileName) throws Exception {
    if (fileName == null || fileName.equals("")) {
      fileName = this.qcmlFile;
    }
    fileName=fileName.replaceAll("20%", " ");
    File xmlFile = new File(fileName);
    DOMSource doms = new DOMSource(configuration);    Source inputXSL = new StreamSource(
          new File(this.xslTransformation));    StreamResult sr = new StreamResult(xmlFile);    TransformerFactory tf = TransformerFactory.newInstance();
    try {
      Transformer t = tf.newTransformer();
      Properties properties = t.getOutputProperties();
      properties.setProperty(OutputKeys.METHOD, "xml");
      properties.setProperty(OutputKeys.INDENT, "yes");
      t.setOutputProperties(properties);
      t.transform(doms, sr);//出错代码
    }
    catch (TransformerConfigurationException e) {
      e.printStackTrace();
      throw new TransformerConfigurationException();
    }  }出错信息为:
javax.xml.transform.TransformerException: java.io.FileNotFoundException: C:\Documents%20and%20Settings\IV\temp_tcosuite.2043\1195095607812\temp.qcml (系统找不到指定的路径。)
at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:296)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:329)
at com.alcatel.wtd.uls.qcmlhandler.QCMLHandler.saveXML(Unknown Source)
at com.alcatel.wtd.uls.wizard.PreviewPanel.send(Unknown Source)
at com.alcatel.wtd.uls.wizard.QuickInstallationSummaryPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Documents%20and%20Settings\IV\temp_tcosuite.2043

解决方案 »

  1.   

    很开心, 乱搞了1星期,今天好好检查了代码,终于解决了。
    对于org.xml.sax.SAXException:   error   comes   from   xml   parser   :Document   is   invalid:   no   grammar   found.这个异常, 在代码里明确指定了schema文件,就不会报这个错误了。
    原来没有用schema是因为在java1.4里不支持。修改代码
     //factory.setValidating(true); // set to false when setschema() used
    //      Schema is only Java 5 compatible  --Begin Add 23.11.2007
             Schema schema = null;
             SchemaFactory schemaFactory = null;
             schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
             try {
              System.out.println("set xml schema:"+schemaFile);
             schema =
             schemaFactory.newSchema(schemaFile);
             } catch (SAXException ex) {
             ex.printStackTrace();
             }
             factory.setSchema(schema);
             factory.setValidating(false);但是如果包里包含了xalan.jar时,还是解析不了路径中有空格的问题,把该包去掉,第2个问题也解决了。happy :)