通过 xslt 使用从 xml 到文本文件的转换时抛出异常
Exception being thrown when using Transform from xml to text file via xslt
我的代码如下所示:
protected String[] parseXMLRecievedMsg(StringBuffer iSB_plainMessage) throws Exception {
Source xslt = new StreamSource(new File("sample.xslt"));
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer transformer = transFact.newTransformer(xslt);
StringWriter outWriter = new StringWriter();
StreamResult lS_outputMsgBody = new StreamResult( outWriter );
iSB_plainMessage =iSB_plainMessage.delete(0,iSB_plainMessage.indexOf("\n"));
iSB_plainMessage =iSB_plainMessage.reverse();
iSB_plainMessage =iSB_plainMessage.delete(0, iSB_plainMessage.indexOf("\n"));
iSB_plainMessage =iSB_plainMessage.reverse();
StringBuilder SB_plainMessage = new StringBuilder(iSB_plainMessage.toString());
SB_plainMessage.insert(0,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r");
Source lSB_MessageInput = new StreamSource(SB_plainMessage.toString());
transformer.setOutputProperty(OutputKeys.METHOD, "text");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(lSB_MessageInput, lS_outputMsgBody);
return new String []{ lS_outputMsgBody.getWriter().toString()};
`
我正在尝试将收到的 xml 消息转换为文本文件。
我一直收到以下异常
java.io.FileNotFoundException: C:\alltra_apps\BIC\base_domain\allNETTImport\
(The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:120)
at java.io.FileInputStream.(FileInputStream.java:79)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
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 com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:440)
at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:234)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(TransformerImpl.java:524)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:709)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
采用 String
(https://docs.oracle.com/javase/8/docs/api/javax/xml/transform/stream/StreamSource.html#StreamSource-java.lang.String-) 的 StreamSource
构造函数的重载期望带有 URI 的 String
而您似乎传入带有一些 XML 即时构建。如果你想用 XML 读取 String
,那么在 String
.
的 StringReader
上构造一个 StreamSource
我的代码如下所示:
protected String[] parseXMLRecievedMsg(StringBuffer iSB_plainMessage) throws Exception {
Source xslt = new StreamSource(new File("sample.xslt"));
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer transformer = transFact.newTransformer(xslt);
StringWriter outWriter = new StringWriter();
StreamResult lS_outputMsgBody = new StreamResult( outWriter );
iSB_plainMessage =iSB_plainMessage.delete(0,iSB_plainMessage.indexOf("\n"));
iSB_plainMessage =iSB_plainMessage.reverse();
iSB_plainMessage =iSB_plainMessage.delete(0, iSB_plainMessage.indexOf("\n"));
iSB_plainMessage =iSB_plainMessage.reverse();
StringBuilder SB_plainMessage = new StringBuilder(iSB_plainMessage.toString());
SB_plainMessage.insert(0,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r");
Source lSB_MessageInput = new StreamSource(SB_plainMessage.toString());
transformer.setOutputProperty(OutputKeys.METHOD, "text");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(lSB_MessageInput, lS_outputMsgBody);
return new String []{ lS_outputMsgBody.getWriter().toString()};
`
我正在尝试将收到的 xml 消息转换为文本文件。 我一直收到以下异常
java.io.FileNotFoundException: C:\alltra_apps\BIC\base_domain\allNETTImport\ (The filename, directory name, or volume label syntax is incorrect) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:120) at java.io.FileInputStream.(FileInputStream.java:79) at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70) at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161) 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 com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:440) at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:234) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(TransformerImpl.java:524) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:709) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
采用 String
(https://docs.oracle.com/javase/8/docs/api/javax/xml/transform/stream/StreamSource.html#StreamSource-java.lang.String-) 的 StreamSource
构造函数的重载期望带有 URI 的 String
而您似乎传入带有一些 XML 即时构建。如果你想用 XML 读取 String
,那么在 String
.
StringReader
上构造一个 StreamSource