stanfordnlp/CoreNLP · error · RuntimeException
org.xml.sax.SAXException
Error message
org.xml.sax.SAXException
What it means
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.
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
Example fix
// before
transformXML(Arrays.asList("tag"), fn, new FileInputStream(f));
// after
try {
transformXML(Arrays.asList("tag"), fn, new FileInputStream(f));
} catch (RuntimeException e) {
e.getCause().printStackTrace(); // real SAX parse error
} Defensive patterns
Strategy: try-catch
Validate before calling
// sanity check the document parses before transforming DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
Try / catch
try {
tx.transformXML(tags, fn, in);
} catch (RuntimeException e) {
Throwable cause = e.getCause(); // org.xml.sax.SAXException with line info
log.error("XML transform failed: " + cause.getMessage());
} Prevention
- Validate XML well-formedness before transforming
- Ensure '&' and '<' in text content are escaped
- Wrap your TransformXMLFunction body so it never throws raw exceptions
When it happens
Trigger: 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).
Common situations: Feeding non-XML or truncated files into transformXML; a user transform function throwing inside the handler; unescaped characters like a bare '&' in the XML.
Related errors
- Error configuring XML parser
- TIMEX3 should only contain text
- unexpected element
- unexpected content
- Attempted to parse empty/null tag
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/763b44b2a901a1a4.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/process/TransformXML.java:379
* be buffered if desirable. Internally, this Writer is wrapped as
* a PrintWriter.
*
* @param tags an array of <code>String</code>s, each an XML entity
* within which the transformation should be applied
* @param fn the {@link Function <code>Function</code>} to apply
* @param in the <code>InputStream</code> to read from
* @param w the <code>Writer</code> to write to
* @param saxInterface the sax handler you would like to use (default is SaxInterface, defined in this class, but you may define your own handler)
*/
public void transformXML(String[] tags, Function<String,T> fn, InputSource in, Writer w, SAXInterface<T> saxInterface) {
saxInterface.outWriter = new PrintWriter(w, true);
saxInterface.function = fn;
saxInterface.elementsToBeTransformed = new ArrayList<>();
saxInterface.elementsToBeTransformed.addAll(Arrays.asList(tags));
try {
saxParser.parse(in, saxInterface);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
} // end class TransformXML
View on GitHub (pinned to 1b7edd19c4)