stanfordnlp/CoreNLP · error · SsurgeonParseException

XML failure while reading " + file

Error message

XML failure while reading " + file

What it means

readFromFile (the surrounding method) loads an ssurgeon XML file from disk and parses it; ParserConfigurationException or SAXException from reading/parsing the file is wrapped in SsurgeonParseException naming the file path. Unlike readFromString, IOException may propagate separately, so this specifically signals XML parsing problems.

Solutions

  1. Verify the file is well-formed XML (open in an XML validator or xmllint)
  2. Confirm the correct file path and format — ssurgeon files must be XML
  3. Read the chained cause for the parser's line/column error

Example fix

# before: passing a plain-text rules file
ssurgeon.readFromFile(new File("rules.txt"));
# after
ssurgeon.readFromFile(new File("rules.xml")); // valid ssurgeon XML
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check: file exists and parses as XML
boolean isParseableXml(java.io.File f) throws java.io.IOException {
  try {
    javax.xml.parsers.DocumentBuilderFactory.newInstance()
      .newDocumentBuilder().parse(f);
    return true;
  } catch (org.xml.sax.SAXException e) { return false; }
}

Try / catch

try {
  List<SsurgeonPattern> pats = ssurgeon.readFromFile(file);
} catch (SsurgeonParseException e) {
  log.severe("XML failure in " + file + ": " + e.getCause());
}

Prevention

When it happens

Trigger: Ssurgeon.readFromFile(file) on a file containing invalid XML: truncated file, wrong root element encoding issues, or binary content with an .xml extension.

Common situations: Pointing Ssurgeon at a text/plain ssurgeon rules file instead of XML, or a partially-written/corrupted XML resource.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/c869d44eb3e8b184. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java:815

      throw new SsurgeonParseException("XML failure while reading string", e);
    }
  }

  /**
   * Given a path to a file containing a list of SsurgeonPatterns, returns
   *
   * TODO: deal with resources
   */
  public List<SsurgeonPattern> readFromFile(File file) {
    try {
      Document doc = XMLUtils.readDocumentFromFile(file.getPath());

      if (VERBOSE)
        System.out.println("Reading ssurgeon file="+file.getAbsolutePath());

      return readFromDocument(doc);
    } catch (ParserConfigurationException | SAXException e) {
      throw new SsurgeonParseException("XML failure while reading " + file, e);
    }
  }

  public List<SsurgeonPattern> readFromDocument(Document doc) {
    List<SsurgeonPattern> retList = new ArrayList<>();

    NodeList patternNodes = doc.getElementsByTagName(SsurgeonPattern.SSURGEON_ELEM_TAG);
    for (int i=0; i<patternNodes.getLength(); i++) {
      Node node = patternNodes.item(i);
      if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element elt = (Element) node;
        SsurgeonPattern pattern = ssurgeonPatternFromXML(elt);
        retList.add(pattern);
      }
    }

    NodeList resourceNodes = doc.getElementsByTagName(SsurgeonPattern.RESOURCE_TAG);
    for (int i=0; i < resourceNodes.getLength(); i++) {

View on GitHub (pinned to 1b7edd19c4)