{"record":{"id":"0c9ee456d09a0dd3","repo":"antlr/antlr4","slug":"unknowth-path-element-el-0c9ee4","errorCode":null,"errorMessage":"Unknowth path element ${el}","messagePattern":"Unknowth path element (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"runtime/CSharp/src/Tree/Xpath/XPath.cs","lineNumber":162,"sourceCode":"                    }\n\n                    case XPathLexer.TokenRef:\n                    case XPathLexer.RuleRef:\n                    case XPathLexer.Wildcard:\n                    {\n                        elements.Add(GetXPathElement(el, false));\n                        i++;\n                        break;\n                    }\n\n                    case TokenConstants.EOF:\n                    {\n                        goto loop_break;\n                    }\n\n                    default:\n                    {\n                        throw new ArgumentException(\"Unknowth path element \" + el);\n                    }\n                }\n            }\nloop_break: ;\n            return elements.ToArray();\n        }\n\n        private sealed class _XPathLexer_87 : XPathLexer\n        {\n            public _XPathLexer_87(ICharStream baseArg1)\n                : base(baseArg1)\n            {\n            }\n\n            public override void Recover(LexerNoViableAltException e)\n            {\n                throw e;\n            }","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/CSharp/src/Tree/Xpath/XPath.cs#L144-L180","documentation":"XPath.Split() accepts only the small XPath dialect understood by the ANTLR tree XPath support: '/', '//', '*', token references, rule references, and optional '!' inversion immediately after a separator. The default branch of the token switch is reached when the lexer produced a token that is not one of those expected top-level elements. This almost always means the path syntax is valid enough to lex but is not valid for this XPath subset.","triggerScenarios":"A path begins with '!' without a preceding '/' or '//' (for example \"!ID\"); a quoted string is used as the first element (for example \"'ID'\" instead of \"/ID\" or \"/'ID'\"); or stray characters/tokens such as a top-level Bang appear after a word. Full XPath features such as predicates, '..', or axes are not supported and can also lead here or to the invalid-character error.","commonSituations":"Developers mistake Antlr4.Runtime.Tree.Xpath.XPath for a full XPath engine; hand-built path strings contain a trailing separator or misplaced '!'; paths are assembled by string concatenation; or documentation examples from a different runtime version are copied.","solutions":["Use only supported forms: '/rule', '//rule', '/TOKEN', '//TOKEN', '*', and '/!' or '//!' before the element for inversion.","Remove a leading or misplaced '!' and place inversion directly after a separator.","If quoting a token name, keep the leading separator, e.g. \"/'TOKEN'\" rather than \"'TOKEN'\".","Inspect the generated XPathLexer token types if the path still fails, and remove unsupported XPath constructs."],"exampleFix":"// before\nvar p = new Antlr4.Runtime.Tree.Xpath.XPath(parser, \"!ID\");\n\n// after\nvar p = new Antlr4.Runtime.Tree.Xpath.XPath(parser, \"/!ID\");","handlingStrategy":"validation","validationCode":"static bool IsSupportedXPathShape(string path) {\n    if (string.IsNullOrWhiteSpace(path)) return false;\n    return !path.StartsWith(\"!\") && System.Text.RegularExpressions.Regex.IsMatch(\n        path,\n        \"^(\\/\\/?!?[A-Za-z_\\u00C0-\\uFFFF][A-Za-z0-9_\\u00C0-\\uFFFF]*|\\/\\/?'?[^']*'?|\\\\*)*$\");\n}","typeGuard":null,"tryCatchPattern":"try { var p = new Antlr4.Runtime.Tree.Xpath.XPath(parser, xpath); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Unknowth path element\")) { /* reject xpath */ }","preventionTips":["Keep XPath strings limited to '/', '//', names, '*', and optional '!' immediately after a separator.","Do not use full XPath predicates, axes, or '..' with this class.","Build paths from a whitelist of components rather than raw concatenation."],"tags":["antlr","csharp","xpath","input-validation"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}