2
votes

My code looks as the following:

  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()};

`

I'm trying to transform xml message i get to a text file. I keep get the following exception

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)

1
Which line of your code gives the error?Martin Honnen
transformer.transform(lSB_MessageInput, lS_outputMsgBody);Nir

1 Answers

1
votes

The overload of the StreamSource constructor taking a String (https://docs.oracle.com/javase/8/docs/api/javax/xml/transform/stream/StreamSource.html#StreamSource-java.lang.String-) expects a String with a URI while you seem to pass in a String with some XML constructed on the fly. If you want to read in a String with XML then construct a StreamSource over a StringReader over that String.