MalformedURLException:没有Xalan转换器的协议

时间:2012-07-27 10:00:44

标签: java xml xerces xalan

我在editing an XML file in a stream上实施此问题的解决方案时遇到了问题。我收到MalFormedUrlException:没有协议。 XML文件编码为UTF-8,没有doctype但格式正确。我很难过为什么会这样。

以下是有问题的代码(byteArray有xml,UpdatingXmlReader是我的类):

    XMLReader reader =
        new UpdatingXmlReader(SAXParserFactory.newInstance().newSAXParser());
    Transformer xform = TransformerFactory.newInstance().newTransformer();

    InputSource inputSource = 
        new InputSource(new ByteArrayInputStream(byteArray));
    StreamResult streamResult = 
        new StreamResult(response.getOutputStream());

    SAXSource saxSource = new SAXSource(reader, inputSource);                       

    xform.transform(saxSource, streamResult);

我的测试中如何调用它:

    File file = new File("c:/test.xml");
    InputStream input = new FileInputStream(file);
    byte[] b = IOUtils.toByteArray(input);
    // in production the byte array will come from the database
    service.method(b, httpServletResponse ,httpServletRequest)

这是堆栈跟踪:

javax.xml.transform.TransformerException: 
    java.net.MalformedURLException: no protocol: 
    at org.apache.xalan.transformer.TransformerIdentityImpl.transform(Unknown Source)
Caused by: java.net.MalformedURLException: no protocol: [B@22732273
    at java.net.URL.<init>(URL.java:579)
    at java.net.URL.<init>(URL.java:476)
    at java.net.URL.<init>(URL.java:425)
    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)

1 个答案:

答案 0 :(得分:0)

尝试将“file://”附加到文件路径的开头。