Method and device for performing static SQL reduction analysis on XML file and storage medium
By automating the parsing of MyBatis XML configuration files and SQL statements, the system detects and resolves issues where database fields and Java DTO fields do not match, improving data consistency and stability in the banking system, reducing the risk of system crashes, and saving development and maintenance costs.
Patent Information
- Application Number
- CN202511257523.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-04
- Publication Date
- 2025-12-19
AI Technical Summary
In banking systems, inconsistencies between database column types and field types within Java applications can cause large-amount transfers to fail. Existing technologies cannot effectively detect and resolve this issue, impacting system reliability.
A method and apparatus for static SQL parsing of XML files are provided. The engine automatically parses MyBatis XML configuration files and SQL statements, detects and resolves type mismatches between database fields and Java DTO fields, including obtaining XML file elements, constructing a syntax tree, generating a class diagram, and extracting field mapping relationships from the ResultMap for matching checks.
Improve data consistency and accuracy, enhance system stability, reduce development and maintenance costs, and improve system reliability by detecting type mismatch issues early, avoiding data mapping errors and system crashes.
Smart Images

Figure CN121166716A_ABST
Abstract
Claims
1. A method for static SQL decomposition and parsing of XML files, characterized in that, The method includes the following steps: Obtain the XML file to be parsed, parse the XML file to obtain multiple elements contained in the XML file, and obtain multiple node categories corresponding to multiple elements according to the preset mapping relationship between elements and node categories; The process involves parsing each node category in multiple node categories one by one to obtain sub-nodes under each node category. Specifically, this includes: taking a node category as a parent node, parsing the XML text under the parent node in sequence to obtain at least one child node under the parent node, constructing a syntax tree for the at least one child node in the order, and generating a class diagram after processing multiple syntax trees. The class diagram is traversed to obtain the final SQL. The field mapping relationship is extracted from the ResultMap to obtain the first attribute corresponding to the field. The final SQL is parsed to obtain the second attribute of the SQL field. It is determined whether the first attribute and the second attribute match. If they do not match, an alarm will be issued for the field.
2. The method for static SQL decomposition and parsing of XML files according to claim 1, characterized in that, The process of determining whether the first attribute and the second attribute match specifically includes: Configure the database and Java type mapping relationship. If the first attribute and the second attribute belong to one of the database and Java type mapping relationships, then a match is determined. If the first attribute and the second attribute do not belong to either of the database and Java type mapping relationships, then a mismatch is determined.
3. The method for static SQL decomposition and parsing of XML files according to claim 1, characterized in that, The process of parsing the XML text under the parent node sequentially to obtain at least one child node under the parent node, constructing a syntax tree from the at least one child node in the specified order, and generating a class diagram after processing multiple syntax trees specifically includes: Obtain the XML text of the corresponding paragraph under the parent node, extract the first text according to the order of the XML text, and perform a parsing operation on the first text. Specifically, this includes: obtaining the first child node corresponding to the first text according to a preset mapping relationship between elements and node categories, taking the first child node as a child node under the parent node, identifying whether the child node has a corresponding sub-paragraph, and if it has a corresponding sub-paragraph, extracting the first sub-text of the sub-paragraph, obtaining the grandchild node corresponding to the first sub-text according to the preset mapping relationship between elements and node categories, taking the grandchild node as a node under the first child node, and extracting subsequent text according to the order of the XML text and performing a parsing operation to obtain the syntax tree.
4. The method for static SQL decomposition and parsing of XML files according to claim 1, characterized in that, The method further includes: Identify all nodes in the syntax tree. If all nodes contain a NestedNode, obtain the other syntax tree pointed to by the NestedNode and merge the syntax tree and the other syntax tree into a single tree.
5. The method for static SQL decomposition and parsing of XML files according to claim 4, characterized in that, The step of merging the syntax tree and the other syntax tree into a single tree specifically includes: Obtain the first position of the NestedNode in the syntax tree, extract the other syntax tree pointed to by the NestedNode, and concatenate the other syntax tree to the first position to obtain a merged tree.
6. The method for static SQL decomposition and parsing of XML files according to claim 1, characterized in that, The method further includes: Obtain the current node in the syntax tree that requires a preset operation, add the current node to the first path, recursively traverse all child nodes of the current node, transmit the first path to the child nodes, and the child nodes return the current complete path to the visitor of the preset operation.
7. The method for static SQL decomposition and parsing of XML files according to claim 1, characterized in that, The method further includes: When the syntax tree contains a selection node, traversing the syntax tree to obtain the traversal result specifically includes: When traversing to a condition node, the condition node is marked (the marking method is not limited), and the marked node is split. The splitting includes: splitting the other child nodes of the condition node as independent root nodes to obtain multiple split trees, comparing each of the multiple split trees in order to obtain multiple traversal trees, obtaining the first tree containing the condition node in the multiple traversal trees, and replacing the condition node in the first tree with the remaining traversal trees to obtain the final traversal result.
8. An apparatus for static SQL parsing of XML files, characterized in that, The device includes: The parsing unit is used to obtain the XML file to be parsed, parse the XML file to obtain multiple elements contained in the XML file, obtain multiple node categories corresponding to multiple elements according to the preset mapping relationship between elements and node categories, and parse each node category one by one to obtain sub-nodes under each node category. Specifically, it includes: taking a node category as a parent node, parsing the XML text under the parent node in sequence to obtain at least one child node under the parent node, constructing a syntax tree for the at least one child node in the order, and generating a class diagram after processing multiple syntax trees. The traversal and parsing unit is used to traverse and access the class diagram to obtain the final SQL, extract the field mapping relationship from the ResultMap to obtain the first attribute corresponding to the field, parse the final SQL to obtain the second attribute of the SQL field, and determine whether the first attribute and the second attribute match. If they do not match, an alarm will be issued for the field.
9. The apparatus for static SQL decomposition and parsing of XML files according to claim 8, characterized in that, The traversal parsing unit is specifically used to configure the database and Java type mapping relationship. If the first attribute and the second attribute belong to one of the database and Java type mapping relationships, then a match is determined. If the first attribute and the second attribute do not belong to either of the database and Java type mapping relationships, then a mismatch is determined.
10. A computer storage medium storing a computer program for electronic data interchange, characterized in that, The computer program causes the computer to perform the steps of the method as described in any one of claims 8-9.