CN-121981106-A - Xml file analysis method, system and storage medium
Abstract
The application discloses an xml file analysis method, system and storage medium, wherein the method comprises the steps of scanning and reading node index information of each node in a target xml file and constructing a mapping file based on the node index information, acquiring a target node identifier, a target offset and a target content length corresponding to a target node from the mapping file when an analysis request aiming at the target xml file including the target node is received, acquiring target node data from the target xml file based on the target node identifier, the target offset and the target content length, and analyzing the target node data to obtain node attribute information of the target node. According to the method, the mapping file of the xml file is generated in the preprocessing stage, and then when the xml analysis request is received each time, only the mapping file is needed to be loaded to realize local access to the content needing to be analyzed in the original xml, and compared with the existing scheme of the original xml file with full analysis, the occupation of the system memory in the process of analyzing the xml file is effectively reduced.
Inventors
- SUN XU
- WANG LIANG
- WANG JIE
- YANG RUI
Assignees
- 航天银山电气有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20251219
Claims (10)
- 1. An xml file parsing method, comprising: Scanning a target xml file, reading node index information of each node in the target xml file, constructing a mapping file based on all node index information, and associating the mapping file to the target xml file, wherein any node index information comprises a node identifier of the corresponding node, a position offset of the node identifier in the target xml file and a node content length of the node, and the memory occupation of the mapping file is smaller than that of the target xml; receiving an analysis request aiming at the target xml file, wherein the analysis request comprises a target node; Acquiring a target node identifier, a target offset and a target content length corresponding to the target node from the mapping file; Acquiring target node data from the target xml file based on the target node identification, the target offset and the target content length; and analyzing the target node data to obtain node attribute information of the target node.
- 2. The xml file parsing method according to claim 1, wherein scanning a target xml file, reading node index information of each node in the target xml file, includes: Loading the target xml file into a memory; traversing the target xml file in the memory, and recording the node identification corresponding to any node, the position offset of the node identification in the corresponding target xml file and the node content length of the node when the node initiator of any node is detected; and determining the node identification, the position offset and the node content length as the node index information of the corresponding node.
- 3. The xml file parsing method according to claim 2, wherein after recording the node identifier corresponding to any one of the nodes, a position offset of the node identifier in the target xml file, and a node content length of the node, the method further comprises: recording pointers of the nodes traversed currently; when the pointer is larger than the character length of the target xml file in the memory, finishing the reading operation of node index information of each node of the target xml file; And when the pointer is smaller than the character length, continuing to detect the node initiator.
- 4. The xml file parsing method according to claim 1, wherein obtaining, from the mapping file, a target node identifier, a target offset, and a target content length corresponding to the target node, includes: Constructing the mapping file by using a DOM parser to obtain a DOM tree; and acquiring a target node identifier, a target offset and a target content length corresponding to the target node from the DOM tree.
- 5. An xml file parsing system, comprising: The mapping file generation module is used for scanning a target xml file, reading node index information of each node in the target xml file, constructing a mapping file based on all node index information, and associating the mapping file to the target xml file, wherein any node index information comprises a node identifier of the corresponding node, a position offset of the node identifier in the target xml file and a node content length of the node, and the memory occupation of the mapping file is smaller than that of the target xml; The analysis request receiving module is used for receiving an analysis request aiming at the target xml file, wherein the analysis request comprises a target node; The first data acquisition module is used for acquiring a target node identifier, a target offset and a target content length corresponding to the target node from the mapping file; The second data acquisition module is used for acquiring target node data from the target xml file based on the target node identification, the target offset and the target content length; And the xml file analysis module is used for analyzing the target node data to obtain the node attribute information of the target node.
- 6. The xml file parsing system of claim 4, wherein said mapped file generation module comprises: the first file loading module is used for loading the target xml file into the memory; The file scanning module is used for traversing the target xml file in the memory, and recording the node identification corresponding to any node, the position offset of the node identification in the corresponding target xml file and the node content length of the node when the node initiator of any node is detected; And the node index information generation module is used for determining the node identification, the position offset and the node content length as the corresponding node index information of the node.
- 7. The xml file parsing system of claim 4, wherein said mapped file generation module further comprises: The third data acquisition module is used for recording pointers of the nodes traversed currently; the first data processing module is used for completing the reading operation of node index information of each node of the target xml file when the pointer is larger than the character length of the target xml file in the memory; and the second data processing module is used for continuing to detect the node initiator when the pointer is smaller than the character length.
- 8. The xml file parsing system of claim 4, wherein said first data acquisition module comprises: The third data processing module is used for constructing the mapping file by using a DOM parser to obtain a DOM tree; And the fourth data acquisition module is used for acquiring the target node identification, the target offset and the target content length corresponding to the target node in the DOM tree.
- 9. An xml file parsing system comprising at least one control processor and a memory for communication with the at least one control processor, the memory storing instructions executable by the at least one control processor to enable the at least one control processor to perform an xml file parsing method according to any one of claims 1 to 4.
- 10. A computer-readable storage medium storing computer-executable instructions for causing a computer to perform the xml-based file-parsing method according to any one of claims 1 to 4.
Description
Xml file analysis method, system and storage medium Technical Field The present application relates to, but not limited to, the field of data processing technologies, and in particular, to a method, a system, and a storage medium for parsing an xml file. Background The existing analysis reading method for the xml file comprises a DOM analysis method, a SAX analysis method, a JAXB analysis method and the like, and when the analysis operation of the xml file is executed based on the analysis methods, even if the analysis requirement is only for one node in the xml file, the whole xml file must be completely scanned from beginning to end, so that a large memory of the system is occupied, and when more xml files are needed to be analyzed, the utilization rate of system resources is influenced. Disclosure of Invention The embodiment of the application provides an xml file analysis method, an xml file analysis system and a storage medium, which can effectively reduce the occupation of a system memory in the process of analyzing an xml file. In a first aspect, an embodiment of the present application provides a DOM-based xml file parsing method, including: Scanning a target xml file, reading node index information of each node in the target xml file, constructing a mapping file based on all node index information, and associating the mapping file to the target xml file, wherein any node index information comprises a node identifier of the corresponding node, a position offset of the node identifier in the target xml file and a node content length of the node, and the memory occupation of the mapping file is smaller than that of the target xml; receiving an analysis request aiming at the target xml file, wherein the analysis request comprises a target node; Acquiring a target node identifier, a target offset and a target content length corresponding to the target node from the mapping file; Acquiring target node data from the target xml file based on the target node identification, the target offset and the target content length; and analyzing the target node data to obtain node attribute information of the target node. In some embodiments, scanning a target xml file, and reading node index information of each node in the target xml file includes: Loading the target xml file into a memory; traversing the target xml file in the memory, and recording the node identification corresponding to any node, the position offset of the node identification in the corresponding target xml file and the node content length of the node when the node initiator of any node is detected; and determining the node identification, the position offset and the node content length as the node index information of the corresponding node. In some embodiments, after recording the node identifier corresponding to any one of the nodes, the position offset of the node identifier in the target xml file, and the node content length of the node, the method further includes: recording pointers of the nodes traversed currently; when the pointer is larger than the character length of the target xml file in the memory, finishing the reading operation of node index information of each node of the target xml file; And when the pointer is smaller than the character length, continuing to detect the node initiator. In some embodiments, obtaining the target node identifier, the target offset, and the target content length corresponding to the target node from the mapping file includes: Constructing the mapping file by using a DOM parser to obtain a DOM tree; and acquiring a target node identifier, a target offset and a target content length corresponding to the target node from the DOM tree. In a second aspect, an embodiment of the present application provides an xml file parsing system, including: The mapping file generation module is used for scanning a target xml file, reading node index information of each node in the target xml file, constructing a mapping file based on all node index information, and associating the mapping file to the target xml file, wherein any node index information comprises a node identifier of the corresponding node, a position offset of the node identifier in the target xml file and a node content length of the node; The analysis request receiving module is used for receiving an analysis request aiming at the target xml file, wherein the analysis request comprises a target node; The first data acquisition module is used for acquiring a target node identifier, a target offset and a target content length corresponding to the target node from the mapping file; The second data acquisition module is used for acquiring target node data from the target xml file based on the target node identification, the target offset and the target content length; And the xml file analysis module is used for analyzing the target node data to obtain the node attribute information of the target node. In some embodiments, the map-file generation module