{"record":{"id":"ebf17b8a524103ba","repo":"pentaho/pentaho-kettle","slug":"unable-to-save-to-xml-file-filename","errorCode":null,"errorMessage":"Unable to save to XML file '\" + filename + \"'","messagePattern":"Unable to save to XML file '\" \\+ filename \\+ \"'","errorType":"exception","errorClass":"KettleXMLException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/TransMeta.java","lineNumber":6598,"sourceCode":"    this.transformationType = transformationType;\n  }\n\n  /**\n   * Utility method to write the XML of this transformation to a file, mostly for testing purposes.\n   *\n   * @param filename\n   *          The filename to save to\n   * @throws KettleXMLException\n   *           in case something goes wrong.\n   */\n  public void writeXML( String filename ) throws KettleXMLException {\n    FileOutputStream fos = null;\n    try {\n      fos = new FileOutputStream( filename );\n      fos.write( XMLHandler.getXMLHeader().getBytes( Const.XML_ENCODING ) );\n      fos.write( getXML().getBytes( Const.XML_ENCODING ) );\n    } catch ( Exception e ) {\n      throw new KettleXMLException( \"Unable to save to XML file '\" + filename + \"'\", e );\n    } finally {\n      if ( fos != null ) {\n        try {\n          fos.close();\n        } catch ( IOException e ) {\n          throw new KettleXMLException( \"Unable to close file '\" + filename + \"'\", e );\n        }\n      }\n    }\n  }\n\n  /**\n   * Checks whether the transformation has repository references.\n   *\n   * @return true if the transformation has repository references, false otherwise\n   */\n  public boolean hasRepositoryReferences() {\n    for ( StepMeta stepMeta : steps ) {","sourceCodeStart":6580,"sourceCodeEnd":6616,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/TransMeta.java#L6580-L6616","documentation":"TransMeta.saveToKtr(filename) (save-to-XML) opens a FileOutputStream, writes the XML header and getXML() body, and wraps any failure (file creation, encoding, serialization) in KettleXMLException 'Unable to save to XML file <filename>'. It indicates the transformation could not be written to disk.","triggerScenarios":"Calling TransMeta.saveToKtr(filename) (or File > Save As in Spoon) when new FileOutputStream(filename) or the write of getXML() bytes throws — e.g. directory missing, no write permission, disk full, or XML serialization failure.","commonSituations":"Saving a KTR to a non-existent directory; read-only filesystem or no permission; path too long on Windows; disk quota exceeded; Const.XML_ENCODING mismatch on exotic content.","solutions":["Verify the target directory exists and is writable; create it before saving (new File(dir).mkdirs()).","Check free disk space and user write permissions on the path.","Use an absolute path and confirm the filename has no illegal characters for the OS.","Catch KettleXMLException and inspect the cause for the exact filesystem error."],"exampleFix":"// before\ntransMeta.saveToKtr(\"transforms/mytrans.ktr\"); // dir missing\n// after\nnew File(\"transforms\").mkdirs();\ntransMeta.saveToKtr(\"/abs/path/transforms/mytrans.ktr\");","handlingStrategy":"validation","validationCode":"File target = new File(filename);\nif (!target.getParentFile().exists()) target.getParentFile().mkdirs();\nif (!target.getParentFile().canWrite()) throw new IllegalStateException(\"Directory not writable: \" + target.getParent());","typeGuard":null,"tryCatchPattern":"try {\n  transMeta.saveToKtr(filename);\n} catch (KettleXMLException e) {\n  log.error(\"Save to XML failed for \" + filename, e.getCause());\n}","preventionTips":["Create parent directories before saving","Check disk space and write permissions","Use absolute paths and OS-safe filenames"],"tags":["kettle","file-write","xml","io"],"backgroundTag":"file-write-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}