{"record":{"id":"360d2ab854e68ce1","repo":"baomidou/mybatis-plus","slug":"unknown-element-s-in-sql-statement","errorCode":null,"errorMessage":"Unknown element <%s> in SQL statement.","messagePattern":"Unknown element <(.+?)> in SQL statement\\.","errorType":"exception","errorClass":"BuilderException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisXMLScriptBuilder.java","lineNumber":171,"sourceCode":"            if (child.getNode().getNodeType() == Node.CDATA_SECTION_NODE || child.getNode().getNodeType() == Node.TEXT_NODE) {\n                String text = cacheStr(child.getStringBody(\"\"));\n                if (text.trim().isEmpty()) {\n                    StaticTextSqlNode staticTextSqlNode = CACHE_EMPTY_SQL_NODE.computeIfAbsent(text, StaticTextSqlNode::new);\n                    contents.add(staticTextSqlNode);\n                    continue;\n                }\n                TextSqlNode textSqlNode = new TextSqlNode(text);\n                if (textSqlNode.isDynamic()) {\n                    contents.add(textSqlNode);\n                    isDynamic = true;\n                } else {\n                    contents.add(new StaticTextSqlNode(text));\n                }\n            } else if (child.getNode().getNodeType() == Node.ELEMENT_NODE) { // issue #628\n                String nodeName = child.getNode().getNodeName();\n                NodeHandler handler = nodeHandlerMap.get(nodeName);\n                if (handler == null) {\n                    throw new BuilderException(\"Unknown element <\" + nodeName + \"> in SQL statement.\");\n                }\n                handler.handleNode(child, contents);\n                isDynamic = true;\n            }\n        }\n        return new MixedSqlNode(contents);\n    }\n\n    private interface NodeHandler {\n        void handleNode(XNode nodeToHandle, List<SqlNode> targetContents);\n    }\n\n    private class BindHandler implements NodeHandler {\n        public BindHandler() {\n            // Prevent Synthetic Access\n        }\n\n        @Override","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisXMLScriptBuilder.java#L153-L189","documentation":"While parsing a mixed dynamic SQL node, MybatisXMLScriptBuilder encountered an element child that is not one of the supported node handlers (trim, where, set, foreach, if, choose, when, otherwise, bind). Any other tag inside a SQL statement is rejected at parse time.","triggerScenarios":"Placing a custom or mistaken element inside <select>/<update> SQL, e.g. <column>, <sql> include misuse, a stray HTML tag pasted in, or a typo like <iffe> instead of <if>; also custom tags intended for other templating engines left in the mapper XML.","commonSituations":"Copy-pasting SQL from documentation/HTML that carries formatting tags; dialect-specific XML fragments; a custom tag from a homegrown preprocessor that is no longer run.","solutions":["Remove or rename the offending element named in the message to a supported one (if/choose/foreach/where/set/trim/bind)","If the tag is reusable SQL text, move it into a <sql id=\"...\"> fragment and reference it with <include refid=\"...\"/>","If the tag was a typo of a supported element, correct the tag name"],"exampleFix":"<!-- before -->\n<select id=\"list\" resultType=\"User\">\n  <columns>id, name</columns> FROM user\n</select>\n<!-- after -->\n<sql id=\"userCols\">id, name</sql>\n<select id=\"list\" resultType=\"User\">\n  SELECT <include refid=\"userCols\"/> FROM user\n</select>","handlingStrategy":"validation","validationCode":"// During build, assert only whitelisted dynamic-SQL tags appear inside statements:\nSet<String> OK = Set.of(\"if\",\"choose\",\"when\",\"otherwise\",\"trim\",\"where\",\"set\",\"foreach\",\"bind\",\"include\",\"sql\");\nNodeList kids = stmtElement.getChildNodes();\nfor (int i = 0; i < kids.getLength(); i++) {\n    Node n = kids.item(i);\n    if (n.getNodeType() == Node.ELEMENT_NODE && !OK.contains(n.getNodeName()))\n        throw new IllegalStateException(\"Unsupported tag <\" + n.getNodeName() + \"> in \" + stmtElement.getAttribute(\"id\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Paste SQL as plain text inside the statement body, never rich/HTML markup","Put reusable fragments in <sql id> and reference via <include>","Validate mapper XML in CI with the official DTD"],"tags":["mybatis","dynamic-sql","xml","parsing"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}