{"record":{"id":"8193a6d96227d1ee","repo":"stanfordnlp/CoreNLP","slug":"no-id-attribute-for-element-elt","errorCode":null,"errorMessage":"No ID attribute for element = \" + elt","messagePattern":"No ID attribute for element = \" \\+ elt","errorType":"exception","errorClass":"SsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java","lineNumber":949,"sourceCode":"      case SsurgeonPattern.PREDICATE_OR_TAG:\n        SsurgOrPred orPred = new SsurgOrPred();\n        for (Element childElt : getChildElements(elt)) {\n          SsurgPred childPred = assemblePredFromXML(childElt);\n          orPred.add(childPred);\n          return orPred;\n        }\n        break;\n      case SsurgeonPattern.PRED_WORDLIST_TEST_TAG:\n        String id = elt.getAttribute(SsurgeonPattern.PRED_ID_ATTR);\n        String resourceID = elt.getAttribute(\"resourceID\");\n        String typeStr = elt.getAttribute(\"type\");\n        String matchName = getEltText(elt).trim(); // node name to match on\n\n        if (matchName == null) {\n          throw new SsurgeonParseException(\"Could not find match name for \" + elt);\n        }\n        if (id == null) {\n          throw new SsurgeonParseException(\"No ID attribute for element = \" + elt);\n        }\n        return new WordlistTest(id, resourceID, typeStr, matchName);\n    }\n\n    // Not a valid node, error out!\n    throw new SsurgeonParseException(\"Invalid node encountered during Ssurgeon predicate processing, node name=\"+eltName);\n  }\n\n\n\n  /**\n   * Reads in the test file and prints readable to string (for debugging).\n   * Input file consists of semantic graphs, in compact form.\n   */\n  public void testRead(File tgtDirPath) throws Exception {\n    List<SsurgeonPattern> patterns = readFromDirectory(tgtDirPath);\n\n    System.out.println(\"Patterns, num = \"+patterns.size());","sourceCodeStart":931,"sourceCodeEnd":967,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java#L931-L967","documentation":"Ssurgeon.parseTest reads an XML element defining a WordlistTest predicate and requires an 'id' attribute naming the test. When the element has a match name but no id attribute, it throws SsurgeonParseException so the malformed Ssurgeon rule file fails fast at load time.","triggerScenarios":"Parsing a Ssurgeon .xml rules file where a <wordlist-test>-style element (or similar test node) has a resolvable match name but is missing the required id=\"...\" attribute.","commonSituations":"Hand-editing or copying rule XML and dropping the id attribute; generating rules programmatically and omitting id; older rule files written for a schema where id was optional.","solutions":["Add the required id=\"...\" attribute to the offending element in the Ssurgeon XML file","Validate the XML against the Ssurgeon schema / check element attributes before loading","Run Ssurgeon.init on the file and fix each reported element until the file parses"],"exampleFix":"// before\n<wordlist-test type=\"tag\" match-name=\"NN\" resource=\"mylist.txt\"/>\n// after\n<wordlist-test id=\"nounTest\" type=\"tag\" match-name=\"NN\" resource=\"mylist.txt\"/>","handlingStrategy":"validation","validationCode":"for (Element e : ruleEl.getChildren()) {\n  if (isTestElement(e) && e.getAttributeValue(\"id\") == null) {\n    throw new IllegalArgumentException(\"Missing id on element: \" + e.getName());\n  }\n}","typeGuard":"static boolean hasId(Element e) { return e.getAttributeValue(\"id\") != null; }","tryCatchPattern":"try {\n  Ssurgeon.init(resource);\n} catch (SsurgeonParseException e) {\n  log.error(\"Bad Ssurgeon rule XML: \" + e.getMessage());\n}","preventionTips":["Always include id attributes on every test element in rule XML","Validate rule files against the Ssurgeon XML schema in CI","Keep rule files under version control so regressions surface in diffs"],"tags":["xml","parsing","ssurgeon"],"backgroundTag":"missing-required-argument","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"}