{"record":{"id":"763b44b2a901a1a4","repo":"stanfordnlp/CoreNLP","slug":"org-xml-sax-saxexception","errorCode":null,"errorMessage":"org.xml.sax.SAXException","messagePattern":"org\\.xml\\.sax\\.SAXException","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/process/TransformXML.java","lineNumber":379,"sourceCode":"   * be buffered if desirable.  Internally, this Writer is wrapped as\n   * a PrintWriter.\n   *\n   * @param tags an array of <code>String</code>s, each an XML entity\n   *             within which the transformation should be applied\n   * @param fn   the {@link Function <code>Function</code>} to apply\n   * @param in   the <code>InputStream</code> to read from\n   * @param w    the <code>Writer</code> to write to\n   * @param saxInterface the sax handler you would like to use (default is SaxInterface, defined in this class, but you may define your own handler)\n   */\n  public void transformXML(String[] tags, Function<String,T> fn, InputSource in, Writer w, SAXInterface<T> saxInterface) {\n    saxInterface.outWriter = new PrintWriter(w, true);\n    saxInterface.function = fn;\n    saxInterface.elementsToBeTransformed = new ArrayList<>();\n    saxInterface.elementsToBeTransformed.addAll(Arrays.asList(tags));\n    try {\n      saxParser.parse(in, saxInterface);\n    } catch (Exception e) {\n      throw new RuntimeException(e);\n    }\n  }\n\n} // end class TransformXML\n","sourceCodeStart":361,"sourceCodeEnd":384,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/process/TransformXML.java#L361-L384","documentation":"TransformXML.transformXML runs the SAX parser and wraps any exception — including the application-supplied SAXException from the transform handler — in a RuntimeException. So any parse error or callback failure surfaces as this unchecked exception with the original as the cause.","triggerScenarios":"Calling transformXML on malformed XML input, or when the TransformXMLFunction applied to a matched element throws/SAXException is raised by a handler (e.g. the fn passed in fails, or an XMLTransformer.xmlTransform throws SAXException).","commonSituations":"Feeding non-XML or truncated files into transformXML; a user transform function throwing inside the handler; unescaped characters like a bare '&' in the XML.","solutions":["Read e.getCause() to find the real SAXException/parse error and its line number","Validate/repair the input XML before transforming (e.g. parse it once beforehand)","Ensure the TransformXMLFunction does not throw; wrap its body and convert errors appropriately","Escape raw '&' and '<' characters in the source document"],"exampleFix":"// before\ntransformXML(Arrays.asList(\"tag\"), fn, new FileInputStream(f));\n// after\ntry {\n  transformXML(Arrays.asList(\"tag\"), fn, new FileInputStream(f));\n} catch (RuntimeException e) {\n  e.getCause().printStackTrace(); // real SAX parse error\n}","handlingStrategy":"try-catch","validationCode":"// sanity check the document parses before transforming\nDocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);","typeGuard":null,"tryCatchPattern":"try {\n  tx.transformXML(tags, fn, in);\n} catch (RuntimeException e) {\n  Throwable cause = e.getCause(); // org.xml.sax.SAXException with line info\n  log.error(\"XML transform failed: \" + cause.getMessage());\n}","preventionTips":["Validate XML well-formedness before transforming","Ensure '&' and '<' in text content are escaped","Wrap your TransformXMLFunction body so it never throws raw exceptions"],"tags":["java","xml","sax","parsing"],"backgroundTag":"xml-parse-error","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}