XML DOM tree analysis method and system based on one-dimensional index, electronic equipment and storage medium

By converting XML files into DOM trees and generating node relationship index tables, the problems of low efficiency and poor accuracy of XML file query in the prior art are solved, and efficient and accurate node attributes and associated node queries are achieved.

CN119415738AInactive Publication Date: 2025-02-11BEIJING GLOBAL CROWN JINYANG TECH DEV CO LTD
View PDF 10 Cites 0 Cited by

Patent Information

Application Number
CN202411520504.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-02-11
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The prior art is inefficient and prone to querying node attributes and associated nodes in XML files, especially when processing large XML files.

Method used

By parsing the XML file, converting it to a DOM tree, and converting the DOM tree to a node relationship index table with a one-dimensional index structure. For each node, when a query request is received, the node relationship index table is traversed according to the node ID of the node, and the node relationship index of the node is queried and outputs.

Benefits of technology

Improve the query efficiency and accuracy of node attributes or associated nodes, avoiding the process of traversing XML files, thereby significantly improving performance when processing large XML files.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119415738A_ABST
    Figure CN119415738A_ABST
Patent Text Reader

Abstract

The invention provides an XML DOM (Extensible Markup Language Document Object Model) tree analysis method and system based on a one-dimensional index, electronic equipment and a storage medium, which are used for analyzing an XML file so as to convert the XML file into a DOM tree; converting the DOM tree into a node relation index table of a one-dimensional index structure; wherein the node relation index table comprises a node relation index of each node, the node relation index of each node comprises node information of the node and node information of other nodes having an incidence relation with the node, and the node information of each node at least comprises a node ID and a node attribute of the node; and for each node, when a query request of the node is received, traversing the node relation index table according to the node ID of the node indicated in the query request, and querying and outputting the node relation index of the node.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and more specifically, to an XML DOM tree parsing method, system, electronic device and storage medium based on one-dimensional indexing. Background Art

[0002] In order to provide people with a more universal and flexible markup language, XML files were developed, wherein XML (Extensible Markup Language) is a markup language for storing and transmitting data.

[0003] In the prior art, a user can query the node attributes corresponding to each node in the XML file and other nodes associated with the node by traversing the XML file, wherein the other nodes may be parent nodes, sibling nodes, and child nodes; however, due to the high complexity of XML files, especially large XML files, traversing the XML file each time to query the node attributes corresponding to the node and its associated nodes is not only inefficient but also prone to query errors. Summary of the invention

[0004] In view of this, the present invention provides an XML DOM tree parsing method, system, electronic device and storage medium based on one-dimensional indexing, so as to improve the efficiency and accuracy of querying node attributes or associated nodes for nodes in an XML file.

[0005] The first aspect of the present application provides an XML DOM tree parsing method based on a one-dimensional index, the method comprising:

[0006] Parsing the XML file to convert the XML file into a DOM tree;

[0007] Convert the DOM tree into a node relationship index table of a one-dimensional index structure; wherein the node relationship index table includes a node relationship index of each of the nodes, the node relationship index of the node includes node information of the node and node information of each other node associated with the node, and the node information of the node includes at least a node ID and a node attribute of the node;

[0008] For each of the nodes, when a query request for the node is received, the node relationship index table is traversed according to the node ID of the node indicated in the query request, and the node relationship index of the node is queried and output.

[0009] Optionally, before parsing the XML file, or during parsing the XML file, the method further includes:

[0010] Determine each character string in the XML file, and determine the file size and complexity of the XML file according to each character string in the XML file;

[0011] The buffer size of the XML file is determined according to the file size of the XML file and the complexity of the XML file, and a corresponding buffer is divided from the local cache according to the buffer size of the XML file.

[0012] Optionally, after converting the DOM tree into a node relationship index table of a one-dimensional index structure, the method further includes:

[0013] The node relationship index table is stored in the buffer.

[0014] Optionally, the complexity of the XML file includes the number of nodes and the number of attributes of the XML file;

[0015] The determining the file size and complexity of the XML file according to each character string in the XML file includes:

[0016] Determining the file size of the XML file according to the string length of each string in the XML file;

[0017] According to each preset keyword, a plurality of key character strings are determined from each character string in the XML file, and the number of nodes of the XML file is determined according to each key character string;

[0018] According to the preset target characters, a plurality of attribute character strings are determined from each character string in the XML file, and the number of attributes of the XML file is determined according to each of the attribute character strings.

[0019] Optionally, determining the buffer size of the XML file according to the file size of the XML file and the complexity of the XML file, and allocating a corresponding buffer from the local cache according to the buffer size of the XML file includes:

[0020] Calculate the corresponding initial buffer size according to the file size, the number of nodes and the number of attributes of the XML file;

[0021] Determine the hyper parameters of the XML file according to the initial buffer size, the number of nodes and the number of attributes of the XML file;

[0022] If the hyperparameter of the XML is within a preset hyperparameter range, determining the initial buffer size as the buffer size;

[0023] If the hyperparameter of the XML file is not within the hyperparameter range, the initial buffer size is adjusted according to the hyperparameter range to obtain the buffer size of the XML file.

[0024] Optionally, the method further includes:

[0025] For each of the nodes, obtaining the attribute query frequency of the node, and determining whether the attribute query frequency of the node is greater than a preset attribute query frequency;

[0026] If the attribute query frequency of the node is greater than the preset attribute query frequency, traverse the node relationship index table, query the node relationship index of the node, and obtain the node attribute of the node from the node relationship index of the node;

[0027] Performing hash mapping on the node ID of the node and the node attribute of the node to obtain a hash mapping result of the node;

[0028] The hash mapping result of the node is stored in the local cache.

[0029] Optionally, the method further includes:

[0030] For each of the nodes, detecting in real time whether an attribute query request of the node is received; wherein the attribute query request of the node at least includes a node ID of the node;

[0031] According to the node ID indicated in the attribute query request of the node, determining whether there is a hash mapping result matching the node among the hash mapping results stored in the local cache;

[0032] If a hash mapping result matching the node exists among the hash mapping results stored in the local cache, obtaining the node attribute of the node from the hash mapping result matching the node;

[0033] If there is no hash mapping result matching the node in the hash mapping results stored in the local cache, the node relationship index table is traversed to query the node relationship index of the node, and the node attribute of the node is obtained from the node relationship index of the node.

[0034] A second aspect of the present application provides an XML DOM tree parsing system based on a one-dimensional index, the system comprising:

[0035] A first parsing unit, used for parsing an XML file to convert the XML file into a DOM tree;

[0036] A conversion unit, configured to convert the DOM tree into a node relationship index table of a one-dimensional index structure; wherein the node relationship index table includes a node relationship index of each of the nodes, the node relationship index of the node includes node information of the node and node information of each other node associated with the node, and the node information of the node includes at least a node ID and a node attribute of the node;

[0037] The traversal unit is used for traversing the node relationship index table for each of the nodes according to the node ID of the node indicated in the query request when receiving a query request for the node, and querying and outputting the node relationship index of the node.

[0038] The third aspect of the present application provides an electronic device, comprising: a processor and a memory, wherein the processor and the memory are connected via a communication bus; wherein the processor is used to call and execute a program stored in the memory; and the memory is used to store a program, wherein the program is used to implement the XML DOM tree parsing method based on one-dimensional indexing as provided in the first aspect of the present application.

[0039] A fourth aspect of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions for executing an XML DOM tree parsing method based on a one-dimensional index as provided in the first aspect of the present application.

[0040] The present application provides an XML DOM tree parsing method, system, electronic device and storage medium based on one-dimensional indexing, which parses an XML file to convert the XML file into a DOM tree; converts the DOM tree into a node relationship index table of a one-dimensional index structure; wherein the node relationship index table includes a node relationship index of each node, the node relationship index of the node includes node information of the node and node information of each other node associated with the node, and the node information of the node includes at least a node ID and a node attribute of the node; for each node, when a query request for the node is received, the node relationship index table is traversed according to the node ID of the node indicated in the query request, and the node relationship index of the node is queried and output. The technical solution provided by the present application converts an XML file into a DOM tree, and converts the DOM into a node relationship index table of a one-dimensional index structure, so that when a query request for a node is received, the node relationship index of the node can be queried by traversing the node relationship index table according to the node ID of the node, and then the node attributes of the node and other nodes with which it has an associated relationship can be obtained, without traversing the XML file. This not only improves the efficiency of querying node attributes or associated nodes, but also improves the accuracy of the obtained node attributes and other associated nodes. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0042] Figure 1 A flowchart of an XML DOM tree parsing method based on a one-dimensional index provided in an embodiment of the present application;

[0043] Figure 2 A flowchart of another XML DOM tree parsing method based on one-dimensional indexing provided in an embodiment of the present application;

[0044] Figure 3 A schematic diagram of the structure of an XML DOM tree parsing system based on a one-dimensional index provided in an embodiment of the present application;

[0045] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0046] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0047] In this application, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

[0048] See also Figure 1 , shows a flow chart of an XML DOM tree parsing method based on one-dimensional indexing provided by an embodiment of the present application, the method specifically comprises the following steps:

[0049] S101: Parse the XML file to convert the XML file into a DOM tree.

[0050] In the specific process of executing step S101, the XML file to be parsed can be obtained and loaded into the memory; a corresponding DOM parser object is created, and the XML file in the memory is parsed using the created DOM parser object to convert the XML file into a corresponding DOM tree.

[0051] It should be noted that the DOM tree includes a root node, at least one parent node associated with the root node, at least one node associated with each parent node, and at least one child node associated with each node; each parent node, each node and each child node carries its own corresponding node ID and node attributes.

[0052] S102: Convert the DOM tree into a node relationship index table of a one-dimensional index structure; wherein the node relationship index table includes a node relationship index of each node, the node relationship index of the node includes node information of the node and node information of each other node associated with the node, and the node information of the node includes at least a node ID and node attributes of the node.

[0053] In the specific process of executing step S102, after obtaining the DOM tree corresponding to the XML file, the DOM tree can be converted into a node relationship index table of a one-dimensional index structure using a recursive descent parsing method. The node relationship index table includes a node relationship index of each node, and the node relationship index of the node includes the node information of the node and the node information of each other node associated with the node. The node information of the node includes at least the node ID and node attributes of the node, as shown in Table 1.

[0054] Table 1:

[0055]

[0056]

[0057] Among them, NodeTable is the node relationship index, ID is the node ID of the node, PID is the node ID of the parent node of the node, SID is the node ID of the node belonging to the same level as the node, CID is the node ID of the child node of the node, and Attributes represents the node attributes of the node.

[0058] It should be noted that the other nodes associated with the node may include the parent node, sibling nodes and at least one child node of the node; if the node only has a parent node and a sibling node, then the CID in the node relationship index corresponding to the node is a null value.

[0059] In some embodiments, the process of converting a DOM tree into a node relationship index table of a one-dimensional index structure using a recursive descent parsing method may specifically be: using the recursive descent parsing method to recursively analyze the DOM tree starting from the root node of the DOM tree through a top-down syntax analysis method, determine the node ID and node attributes corresponding to each node, and other nodes that have an associated relationship with the node, and finally generate a node relationship index table of the dimensionalized index nodes according to the node ID, node attributes of each node and the node IDs of other nodes that have an associated relationship.

[0060] It should be noted that using the recursive descent parsing method to convert the DOM tree into a node relationship index table with a one-dimensional index structure can effectively convert the complex DOM tree into a more intuitive and simple one-dimensional node relationship index table. The node information of each node and other nodes with which it has an associated relationship can be intuitively seen from the node relationship index table, so that when querying the node attributes of the node or other related nodes in the future, the node relationship index of the node can be queried from the node relationship index table using the node ID of the node, without traversing the complex XML file or DOM tree. This can not only improve the query efficiency of the node attributes or associated nodes, but also improve the accuracy of the obtained node attributes or associated nodes, especially when processing large XML files, it can greatly improve the corresponding query efficiency and accuracy.

[0061] It should also be noted that no matter what type of XML file it is, after converting the XML file into DOM, the DOM tree can be converted into a node relationship index table of a one-dimensional index structure using a recursive descent parsing method. It can be seen that the XML DOM tree parsing method based on one-dimensional indexing provided by this application is not only easy to expand, but also can adapt to XML files of different file types, and has high versatility. In addition, this application only needs to provide a simple API interface, and no other hardware or software needs to be configured, which is convenient for developers to call and integrate.

[0062] S103: For each node, when a query request of the node is received, the node relationship index table is traversed according to the node ID of the node indicated in the query request, and the node relationship index of the node is queried and output.

[0063] In the specific process of executing step S103, after obtaining the node relationship index table of the one-dimensional index structure of the XML file, for each node in the XML file, it can be detected in real time whether a query request sent by the user for the node is currently received, wherein the query request at least includes the node ID of the node; when a query request sent by the user for the node is detected, the node relationship index table can be traversed according to the node ID indicated in the query request, and the node relationship index with the same node ID as the query request can be queried, and the node relationship index can be output, so that the user can see the node attributes of the node and other nodes that have an associated relationship with the node at a glance from the output node relationship index.

[0064] The present application provides an XML DOM tree parsing method based on one-dimensional indexing, which converts the XML file into a DOM tree by parsing the XML file; converts the DOM tree into a node relationship index table of a one-dimensional index structure; wherein the node relationship index table includes a node relationship index of each node, the node relationship index of the node includes the node information of the node and the node information of each other node associated with the node, and the node information of the node includes at least the node ID and the node attribute of the node; for each node, when a query request for the node is received, the node relationship index table is traversed according to the node ID of the node indicated in the query request, and the node relationship index of the node is queried and output. The technical solution provided by the present application converts an XML file into a DOM tree, and converts the DOM into a node relationship index table of a one-dimensional index structure, so that when a query request for a node is received, the node relationship index of the node can be queried by traversing the node relationship index table according to the node ID of the node, and then the node attributes of the node and other nodes with which it has an associated relationship can be obtained, without traversing the XML file. This not only improves the efficiency of querying node attributes or associated nodes, but also improves the accuracy of the obtained node attributes and other associated nodes.

[0065] Furthermore, after obtaining the node relationship index table of the XML file, the obtained node relationship index table can also be stored in a corresponding buffer, such as Figure 2 As shown, the embodiment of the present application also provides another XMLDOM tree parsing method based on one-dimensional indexing, which specifically includes the following steps:

[0066] S201: Determine each character string in the XML file, and determine the file size and complexity of the XML file according to each character string in the XML file.

[0067] In the specific process of executing step S203, first, after determining the XML file to be parsed, the XML file can be traversed to determine all the character strings in the XML file; secondly, the file size of the XML file is determined according to the string length of each character string, and the complexity of the XML file is determined according to each character string, wherein the complexity of the XML file includes the number of nodes and the number of attributes of the XML file, so as to subsequently determine the buffer size corresponding to the XML file according to the determined file size, number of nodes and number of attributes of the XML file.

[0068] Optionally, the process of determining the file size and complexity of an XML file based on each character string in the XML file may specifically be as follows: determining the file size of the XML file based on the string length of each character string in the XML file; determining multiple key character strings from each character string in the XML file based on each pre-set keyword, and determining the number of nodes of the XML file based on each key character string; determining multiple attribute character strings from each character string in the XML file based on each pre-set target character, and determining the number of attributes of the XML file based on each attribute character string.

[0069] It should be noted that the string lengths of the determined strings may be accumulated to obtain the file size of the XML file.

[0070] In some embodiments, multiple keywords can be pre-set, where the keyword is a keyword that may exist in the field corresponding to the node in the XML file; for each keyword, each string in the XML file is traversed to determine multiple key strings containing the keyword from each string; the number of all key strings is counted to obtain the number of nodes in the XML file.

[0071] The number of nodes in the XML file includes the number of each node in the XML file and the number of other nodes associated with each node.

[0072] It should be noted that, since it is not clear how many nodes there are in the XML file before or during the parsing of the XML file, the keywords that may be contained in the fields of all nodes are pre-set based on practical experience, so as to determine the number of nodes in the XML file by counting the number of key strings of each keyword in each string in the XML file.

[0073] In some embodiments, a corresponding target character can be preset, wherein the target character is a character existing in a field corresponding to an attribute of a node in an XML file, for example, the target character can be: "", which is not limited in this embodiment of the present application. After determining each string in the XML file, the number of attribute strings containing the target character in each string can be counted to determine the number of attributes of the XML file.

[0074] The number of attributes of the XML file includes the number of attributes of each node of the XML file and the number of attributes of each other node associated with each node.

[0075] It should be noted that, since the node attributes corresponding to each node in the XML file are not clear before or during the parsing of the XML file, the target characters that will be included in the node attributes of all nodes are pre-set based on practical experience, so as to determine the number of attributes of the XML file by counting the number of attribute strings containing the target characters in each character string in the XML file.

[0076] S202: Determine the buffer size according to the file size of the XML file and the complexity of the XML file, and divide a corresponding buffer from the local cache according to the buffer size.

[0077] In the process of specifically executing step S202, after obtaining the file size of the XML file, the number of nodes in the XML file, and the number of attributes in the XML file, the buffer size of the buffer used to store the node key index table of the one-dimensional index structure subsequently generated according to the XML file can be calculated based on the file size, the number of nodes, and the number of attributes of the XML file, so as to reduce the occupancy of the local cache and improve the parsing efficiency of the XML file.

[0078] Optionally, the buffer size of the XML file is determined according to the file size of the XML file and the complexity of the XML file, and the process of allocating a corresponding buffer from the local cache according to the buffer size of the XML file can specifically be as follows: according to the file size of the XML file, the number of nodes and the number of attributes, a corresponding initial buffer size is calculated; according to the initial buffer size, the number of nodes and the number of attributes of the XML file, a hyperparameter of the XML file is determined; if the hyperparameter of the XML is within a preset hyperparameter range, the initial buffer size is determined as the buffer size; if the hyperparameter of the XML file is not within the hyperparameter range, the initial buffer size is adjusted according to the hyperparameter range to obtain the buffer size of the XML file.

[0079] It should be noted that in order to ensure the rationality of the determined buffer size of the XML file, the corresponding hyperparameter range can be set in advance based on practical application experience, so as to use the hyperparameter range to verify whether the calculated initial buffer size is reasonable, that is, to determine whether the initial buffer size is within the hyperparameter range. If it is, it is determined that the initial buffer size is reasonable, and the initial buffer size can be directly determined as the buffer size of the XML file; if it is not, it means that the initial buffer size is unreasonable and needs further adjustment, and then the initial buffer size can be adjusted according to the hyperparameter range to achieve dynamic adjustment of the buffer size of the buffer used to store the node key index table of the one-dimensional index structure subsequently generated according to the XML file, thereby achieving the purpose of reducing the occupancy of the local cache and improving the parsing efficiency of the XML file.

[0080] In some embodiments, the file type of each XML file and its corresponding buffer size calculation function can be pre-set, so that after the XML file to be parsed is determined, the file type of the XML file can be further determined, and according to the determined file type, the buffer size calculation function corresponding to the XML file can be determined from the pre-set buffer size calculation functions, and the initial buffer size of the XML file can be calculated using the buffer size calculation function corresponding to the XML file, the file size of the XML file, the number of nodes and the number of attributes, as shown in formula (1).

[0081] BufferSize=f(XMLSize,Complexity)(1)

[0082] Among them, BufferSize is the initial buffer size, f is the buffer size calculation function corresponding to the file type of XML file, XMLSize is the file size of the XML file, and Complexity is the complexity of the XML file, including the number of nodes and attributes of the XML file.

[0083] In some embodiments, after obtaining the initial buffer size of the XML file, the sum of the number of nodes and the number of attributes of the XML file can be calculated, and the initial buffer size can be divided by the sum of the number of nodes and the number of attributes of the XML file to obtain the hyperparameter of the XML file; if the hyperparameter of the XML file is within a preset hyperparameter range, it means that the obtained initial buffer size is reasonable, and the obtained initial buffer size can be directly used as the buffer size of the XML file; if the hyperparameter of the XML file is not within the hyperparameter range, and the hyperparameter of the XML file is greater than the maximum value in the hyperparameter range, it means that the obtained initial buffer size is too large and unreasonable. At this time, the initial buffer size can be adjusted based on the maximum value in the hyperparameter range to obtain the buffer size of the XML file; if the hyperparameter of the XML file is not within the hyperparameter range, and the hyperparameter of the XML file is less than the minimum value in the hyperparameter range, it means that the obtained initial buffer size is too small and unreasonable. At this time, the initial buffer size can be adjusted based on the minimum value in the hyperparameter range to obtain the buffer size of the XML file.

[0084] S203: Parse the XML file to convert the XML file into a DOM tree.

[0085] S204: Convert the DOM tree into a node relationship index table of a one-dimensional index structure; wherein the node relationship index table includes a node relationship index of each node, the node relationship index of the node includes node information of the node and node information of each other node associated with the node, and the node information of the node includes at least a node ID and node attributes of the node.

[0086] In the specific execution process of step S203 to step S204, the specific execution process and implementation method of step S203 to step S204 are the same as those disclosed in the above embodiment of the present application. Figure 1 The specific execution process and implementation method of step S101 to step S102 in are the same as shown in FIG. Figure 1 The corresponding parts in the embodiments of the present application will not be repeated here.

[0087] S205: Store the node relationship index table in a buffer.

[0088] In the specific process of executing step S205, when the node relationship index table of the one-dimensional index structure corresponding to the XML file is obtained, the obtained node relationship index table can be stored in the corresponding buffer.

[0089] S206: For each node, when a query request for the node is received, the node relationship index table stored in the buffer is traversed according to the node ID of the node indicated in the query request, and the node relationship index of the node is queried and output.

[0090] In an embodiment of the present application, for each node in an XML file, it is possible to detect in real time whether a query request sent by a user for the node is currently received, wherein the query request at least includes the node ID of the node; when a query request sent by a user for the node is detected, the node relationship index table corresponding to the XML file can be obtained from the buffer, so that according to the node ID indicated in the query request, the node relationship index table is traversed, and the node relationship index with the same node ID as the query request is queried, and the node relationship index is output, so that the user can see the node attributes of the node and other nodes associated with the node at a glance from the output node relationship index. In addition, the present application stores the obtained node relationship index table of the XML file in the corresponding buffer, so that when the corresponding query request is detected, the corresponding node relationship index table is directly obtained from the buffer, and the node relationship index of the corresponding node can be obtained by traversing the node relationship index table, without traversing the XML file every time, thereby improving the efficiency and accuracy of the node attribute or associated node query. In particular, for large and complex XML files, by traversing the node relationship index table to query the corresponding node attributes and other associated nodes, the corresponding query efficiency and accuracy can be greatly improved.

[0091] Furthermore, in the embodiment of the present application, in order to further improve the efficiency of node attribute query, for nodes with frequent attribute queries, the attributes of the node can be further stored using a hash map to achieve rapid location of the attributes of the node and improve the corresponding attribute query efficiency. The specific process is shown below:

[0092] For each node, obtain the attribute query frequency of the node, and determine whether the attribute query frequency of the node is greater than the preset attribute query frequency; if the attribute query frequency of the node is greater than the preset attribute query frequency, traverse the node relationship index table, query the node relationship index of the node, and obtain the node attribute of the node from the node relationship index of the node; hash map the node ID of the node and the node attribute of the node to obtain the hash mapping result of the node; store the hash mapping result of the node in the local cache.

[0093] For each node, detect in real time whether an attribute query request of the node is received; wherein the attribute query request of the node includes at least the node ID of the node; according to the node ID indicated in the attribute query request of the node, determine whether there is a hash mapping result matching the node in each hash mapping result stored in the local cache; if there is a hash mapping result matching the node in each hash mapping result stored in the local cache, obtain the node attribute of the node from the hash mapping result matching the node; if there is no hash mapping result matching the node in each hash mapping result stored in the local cache, traverse the node relationship index table, query the node's node relationship index, and obtain the node attribute of the node from the node's node relationship index.

[0094] In the embodiment of the present application, the corresponding preset attribute query frequency can be preset, for example, the preset attribute query frequency can be 10, 15, 20, etc., which can be set according to the actual application, and is not limited in the embodiment of the present application. For each node, the attribute query frequency of the node can be obtained, and it can be determined whether the attribute query frequency of the node is greater than the preset attribute query comment; if it is greater, it means that the node is a node with frequent attribute queries, and then the node attribute of the node can be hashed with the node ID using hash technology, as shown in formula (2), and the obtained hash mapping result is stored in the local cache, so that when the attribute query request of the node is received later, the node attribute of the node can be directly accessed from the local cache using the node ID indicated in the attribute query request, thereby improving the attribute query efficiency of the node.

[0095] AttrAMap[ID i ]=Attributes i (2)

[0096] Among them, AttrAMap[ID i ] is the node ID of the i-th node, Attributes i is the node attribute of the i-th node.

[0097] Based on the XML DOM tree parsing method based on one-dimensional indexing provided in the above embodiment of the present application, correspondingly, the embodiment of the present invention also provides an XML DOM tree parsing system based on one-dimensional indexing, such as Figure 3 As shown, the XML DOM tree parsing based on one-dimensional indexing includes:

[0098] A first parsing unit 31 is used to parse the XML file to convert the XML file into a DOM tree;

[0099] The conversion unit 32 is used to convert the DOM tree into a node relationship index table of a one-dimensional index structure; wherein the node relationship index table includes a node relationship index of each node, the node relationship index of the node includes node information of the node and node information of each other node associated with the node, and the node information of the node includes at least a node ID and a node attribute of the node;

[0100] The traversal unit 33 is used for traversing the node relationship index table according to the node ID of the node indicated in the query request for each node, and querying and outputting the node relationship index of the node when receiving a query request for the node.

[0101] The specific principles and execution processes of each unit in the XML DOM tree parsing method system based on one-dimensional index disclosed in the above embodiment of the present invention are the same as those of the XML DOM tree parsing method based on one-dimensional index disclosed in the above embodiment of the present invention. Please refer to the corresponding parts of the XML DOM tree parsing method based on one-dimensional index disclosed in the above embodiment of the present invention, and no further details will be given here.

[0102] The present application provides an XML DOM tree parsing system based on one-dimensional indexing, which converts an XML file into a DOM tree by parsing an XML file; converts the DOM tree into a node relationship index table of a one-dimensional index structure; wherein the node relationship index table includes a node relationship index of each node, the node relationship index of the node includes the node information of the node and the node information of each other node associated with the node, and the node information of the node includes at least the node ID and the node attribute of the node; for each node, when a query request for the node is received, the node relationship index table is traversed according to the node ID of the node indicated in the query request, and the node relationship index of the node is queried and output. The technical solution provided by the present application converts an XML file into a DOM tree, and converts the DOM into a node relationship index table of a one-dimensional index structure, so that when a query request for a node is received, the node relationship index of the node can be queried by traversing the node relationship index table according to the node ID of the node, and then the node attributes of the node and other nodes with which it has an associated relationship can be obtained, without traversing the XML file. This not only improves the efficiency of querying node attributes or associated nodes, but also improves the accuracy of the obtained node attributes and other associated nodes.

[0103] Optionally, before parsing the XML file, or during parsing the XML file, the XML DOM tree parsing system based on one-dimensional indexing provided by the embodiment of the present application further includes:

[0104] A first determining unit, used to determine each character string in the XML file, and determine the file size and complexity of the XML file according to each character string in the XML file;

[0105] The partitioning unit is used to determine the buffer size of the XML file according to the file size of the XML file and the complexity of the XML file, and to partition a corresponding buffer from the local cache according to the buffer size of the XML file.

[0106] Optionally, the XML DOM tree parsing system based on one-dimensional indexing provided in the embodiment of the present application further includes:

[0107] The first storage unit is used to store the node relationship index table in a buffer.

[0108] Optionally, the complexity of the XML file includes the number of nodes and the number of attributes of the XML file, and the first determination unit includes:

[0109] A second determining unit, used to determine the file size of the XML file according to the string length of each string in the XML file;

[0110] A third determining unit is used to determine a plurality of key character strings from the character strings in the XML file according to the preset keywords, and determine the number of nodes of the XML file according to the key character strings;

[0111] The fourth determining unit is used to determine a plurality of attribute character strings from each character string in the XML file according to a preset target character, and determine the number of attributes of the XML file according to each attribute character string.

[0112] Optionally, divide the unit into:

[0113] An initial buffer size calculation unit, used for calculating a corresponding initial buffer size according to a file size, a number of nodes and a number of attributes of an XML file;

[0114] a fifth determining unit, configured to determine a hyper parameter of the XML file according to the initial buffer size, the number of nodes and the number of attributes of the XML file;

[0115] A sixth determining unit, configured to determine the initial buffer size as the buffer size if the hyperparameter of the XML is within a preset hyperparameter range;

[0116] The seventh determining unit is used to adjust the initial buffer size according to the hyperparameter range to obtain the buffer size of the XML file if the hyperparameter of the XML file is not within the hyperparameter range.

[0117] Optionally, the XML DOM tree parsing system based on the one-dimensional structure provided in the embodiment of the present application further includes:

[0118] A first judgment unit is used to obtain the attribute query frequency of each node and judge whether the attribute query frequency of the node is greater than a preset attribute query frequency;

[0119] A first acquisition unit is used to traverse the node relationship index table to query the node relationship index of the node if the attribute query frequency of the node is greater than the preset attribute query frequency, and to acquire the node attribute of the node from the node relationship index of the node;

[0120] A hash mapping unit, used for performing hash mapping on the node ID of the node and the node attribute of the node to obtain a hash mapping result of the node;

[0121] The second storage unit is used to store the hash mapping result of the node in the local cache.

[0122] Optionally, the XML DOM tree parsing system based on the one-dimensional structure provided in the embodiment of the present application further includes:

[0123] A real-time detection unit, used for detecting in real time for each node whether an attribute query request of the node is received; wherein the attribute query request of the node at least includes a node ID of the node;

[0124] A second judgment unit is used to judge whether there is a hash mapping result matching the node among the hash mapping results stored in the local cache according to the node ID indicated in the attribute query request of the node;

[0125] A second acquisition unit is used to acquire a node attribute of a node from the hash mapping result matching the node if there is a hash mapping result matching the node among the hash mapping results stored in the local cache;

[0126] The third acquisition unit is used to traverse the node relationship index table, query the node relationship index of the node, and obtain the node attribute of the node from the node relationship index of the node if there is no hash mapping result matching the node in the hash mapping results stored in the local cache.

[0127] The present invention also provides a storage medium, in which program instructions are stored. When the program instructions are loaded and executed by a processor, any one of the above-mentioned XML DOM tree parsing method embodiments based on a one-dimensional structure is implemented.

[0128] The present invention also provides an electronic device, such as Figure 4 As shown, the device includes a processor 401 and a memory 402; the memory stores program instructions; the processor calls the program instructions in the memory to execute any one of the above-mentioned XML DOM tree parsing method embodiments based on a one-dimensional structure.

[0129] The processor in this article can be a CPU of a terminal, or an MCU integrated in the terminal, or a combination of a CPU and an MCU. Moreover, the processor includes a kernel, which calls a corresponding program from a memory, and one or more kernels can be set.

[0130] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0131] For the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the order of the actions described, because according to the present invention, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.

[0132] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0133] The modules and sub-modules in the methods and terminals of the various embodiments of the present invention may be combined, divided, or deleted according to actual needs.

[0134] In the several embodiments provided by the present invention, it should be understood that the disclosed terminals, devices and methods can be implemented in other ways. For example, the terminal embodiments described above are only schematic, for example, the division of modules or submodules is only a logical function division, and there may be other division methods in actual implementation, such as multiple submodules or modules can be combined or integrated into another module, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.

[0135] The modules or submodules described as separate components may or may not be physically separated, and the components of the modules or submodules may or may not be physical modules or submodules, that is, they may be located in one place, or they may be distributed on multiple network modules or submodules. Some or all of the modules or submodules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0136] In addition, each functional module or submodule in each embodiment of the present invention may be integrated into one processing module, or each module or submodule may exist physically separately, or two or more modules or submodules may be integrated into one module. The above-mentioned integrated modules or submodules may be implemented in the form of hardware or in the form of software functional modules or submodules.

[0137] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0138] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

[0139] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. An XML DOM tree parsing method based on one-dimensional indexing, characterized in that: The method comprises: Parsing the XML file to convert the XML file into a DOM tree; Convert the DOM tree into a node relationship index table of a one-dimensional index structure; wherein the node relationship index table includes a node relationship index of each of the nodes, the node relationship index of the node includes node information of the node and node information of each other node associated with the node, and the node information of the node includes at least a node ID and a node attribute of the node; For each of the nodes, when a query request for the node is received, the node relationship index table is traversed according to the node ID of the node indicated in the query request, and the node relationship index of the node is queried and output.

2. The method according to claim 1, characterized in that Before parsing the XML file, or during parsing the XML file, the method further includes: Determine each character string in the XML file, and determine the file size and complexity of the XML file according to each character string in the XML file; The buffer size of the XML file is determined according to the file size of the XML file and the complexity of the XML file, and a corresponding buffer is divided from the local cache according to the buffer size of the XML file.

3. The method according to claim 2, characterized in that After converting the DOM tree into a node relationship index table of a one-dimensional index structure, the method further includes: The node relationship index table is stored in the buffer.

4. The method according to claim 2, characterized in that: The complexity of the XML file includes the number of nodes and the number of attributes of the XML file; The determining the file size and complexity of the XML file according to each character string in the XML file includes: Determining the file size of the XML file according to the string length of each string in the XML file; According to each preset keyword, a plurality of key character strings are determined from each character string in the XML file, and the number of nodes of the XML file is determined according to each key character string; According to the preset target characters, a plurality of attribute character strings are determined from each character string in the XML file, and the number of attributes of the XML file is determined according to each of the attribute character strings.

5. The method according to claim 4, characterized in that Determining the buffer size of the XML file according to the file size of the XML file and the complexity of the XML file, and dividing a corresponding buffer from the local cache according to the buffer size of the XML file, includes: Calculate the corresponding initial buffer size according to the file size, the number of nodes and the number of attributes of the XML file; Determine the hyper parameters of the XML file according to the initial buffer size, the number of nodes and the number of attributes of the XML file; If the hyperparameter of the XML is within a preset hyperparameter range, determining the initial buffer size as the buffer size; If the hyperparameter of the XML file is not within the hyperparameter range, the initial buffer size is adjusted according to the hyperparameter range to obtain the buffer size of the XML file.

6. The method according to claim 2, characterized in that The method further comprises: For each of the nodes, obtaining the attribute query frequency of the node, and determining whether the attribute query frequency of the node is greater than a preset attribute query frequency; If the attribute query frequency of the node is greater than the preset attribute query frequency, traverse the node relationship index table, query the node relationship index of the node, and obtain the node attribute of the node from the node relationship index of the node; Performing hash mapping on the node ID of the node and the node attribute of the node to obtain a hash mapping result of the node; The hash mapping result of the node is stored in the local cache.

7. The method according to claim 6, characterized in that The method further comprises: For each of the nodes, detecting in real time whether an attribute query request of the node is received; wherein the attribute query request of the node at least includes a node ID of the node; According to the node ID indicated in the attribute query request of the node, determining whether there is a hash mapping result matching the node among the hash mapping results stored in the local cache; If a hash mapping result matching the node exists among the hash mapping results stored in the local cache, obtaining the node attribute of the node from the hash mapping result matching the node; If there is no hash mapping result matching the node in the hash mapping results stored in the local cache, traverse the node relationship index table, query the node relationship index of the node, and obtain the node attribute of the node from the node relationship index of the node.

8. An XML DOM tree parsing system based on one-dimensional indexing, characterized in that: The system comprises: A first parsing unit, used for parsing an XML file to convert the XML file into a DOM tree; A conversion unit, configured to convert the DOM tree into a node relationship index table of a one-dimensional index structure; wherein the node relationship index table includes a node relationship index of each of the nodes, the node relationship index of the node includes node information of the node and node information of each other node associated with the node, and the node information of the node includes at least a node ID and a node attribute of the node; The traversal unit is used for traversing the node relationship index table for each of the nodes according to the node ID of the node indicated in the query request when receiving a query request for the node, and querying and outputting the node relationship index of the node.

9. An electronic device, characterized in that: include: A processor and a memory, wherein the processor and the memory are connected via a communication bus; wherein the processor is used to call and execute a program stored in the memory; The memory is used to store a program, and the program is used to implement the XML DOM tree parsing method based on one-dimensional indexing as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to execute the XML DOM tree parsing method based on one-dimensional indexing according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method for analyzing XML file by indexing

    CN101777045A

  • Indexing method of tree-like data

    CN106339450A

  • File management method and system, electronic equipment and storage medium

    CN109597794A

  • XML data processing method and system and storage medium

    CN111125439A

  • Big data management method and system

    CN111708778A