gpt4 book ai didi

java - MalformedURLException : no protocol with Xalan transformer

转载 作者:行者123 更新时间:2023-12-01 05:13:26 24 4
gpt4 key购买 nike

我在 editing an XML file in a stream 上实现此问题的解决方案时遇到问题。我收到 MalFormedUrlException:无协议(protocol)。 XML 文件编码为 UTF-8,没有文档类型,但格式良好。我很困惑为什么会发生这种情况。

这是有问题的代码(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)

最佳答案

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

关于java - MalformedURLException : no protocol with Xalan transformer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11685561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com