Data structure construction method and device, and storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA UNITED NETWORK COMM GRP CO LTD
- Filing Date
- 2023-01-05
- Publication Date
- 2026-08-07
AI Technical Summary
[0004]本申请提供一种数据结构构建方法、装置及存储介质,能够解决建立的XML数据结构的节点数据较为冗余的问题
[0004]本申请提供一种数据结构构建方法、装置及存储介质,能够解决建立的XML数据结构的节点数据较为冗余的问题。
Smart Images

Figure CN118296187B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data structure technology, and in particular to a data structure construction method, apparatus and storage medium. Background Technology
[0002] Currently, when users construct Extensible Markup Language (XML) data structures through user devices, they can persist the data based on its characteristics and then read and parse it when needed. In related technologies, user devices can construct XML request parameters through Application Programming Interfaces (APIs).
[0003] However, in the above method, when constructing an XML data structure through an API, the inner XML node must be constructed first, and then the outer XML node must be constructed. This involves establishing the parent-child relationship between the inner and outer XML nodes, resulting in redundant node data in the constructed XML data structure. Summary of the Invention
[0004] This application provides a data structure construction method, apparatus, and storage medium that can solve the problem of redundant node data in the established XML data structure.
[0005] To achieve the above objectives, this application adopts the following technical solution:
[0006] In a first aspect, this application provides a data structure construction method, which includes: obtaining a first set, the first set including at least one node object, each node object being used to represent an Extensible Markup Language (XML) node, the first set being a single-column data set; storing node objects in the first set that meet preset conditions into a second set, the second set being a two-column data set; and performing transformation processing on the second set through a preset utility class to obtain a target XML data structure.
[0007] Based on the above technical solutions, the data structure construction method provided in this application, since this application is a method for constructing XML data structures based on single-column sets, uses the sequential structure of single-column sets to construct XML data structures sequentially from top to bottom, thus solving the code redundancy problem caused by the traditional method of creating XML objects.
[0008] In a first possible implementation of the first aspect, each node object in the at least one node object includes: a node identity ID, a node value, and a parent node ID of the node; storing node objects in the first set that meet the preset conditions into the second set includes: traversing the first set, and performing the following process for each node object in the at least one node object: if the current node ID of the current node object is empty and the second set does not contain the current node ID, creating an XML object corresponding to the current node, and storing the XML object and the node ID corresponding to the XML object into the second set.
[0009] In the second possible implementation of the first aspect, each of the 5 node objects in the at least one node object mentioned above includes: a node identity ID, a node value, and a parent node ID; storing the node objects in the first set that meet the preset conditions into the second set includes: traversing the first set, and performing the following process for each node object in the at least one node object: if the second set does not contain the parent node ID corresponding to the current node, creating the XML corresponding to the current node.
[0010] The object is then stored in a second collection along with the XML object and the ID of the parent node corresponding to the current node.
[0011] In the third possible implementation of the first aspect, each node object in the at least one node object includes: a node identity ID, a node value, and a parent node ID; storing node objects in the first set that meet preset conditions into the second set includes: traversing the first set, and performing the following process for each node object in the at least one node object: in the current node...
[0012] If the current node value of the point object is not empty, create the XML object corresponding to the current node, and store the XML object and the parent node ID corresponding to the current node in the second collection.
[0013] In the fourth possible implementation of the first aspect, after storing the node objects that meet the preset conditions in the first set into the second set, the method further includes: establishing the node relationship between each node object according to the position information of each node object in the second set, and removing the target node object in the second set, wherein the target node object is a duplicate non-leaf node object.
[0014] 0. In a second aspect, this application provides a data structure construction apparatus, comprising: an acquisition unit, a storage unit, and a processing unit. The acquisition unit is used to acquire a first set, the first set including at least one node object, each node object representing an Extensible Markup Language (XML) node, and the first set being a single-column data set. The storage unit is used to store data in the first set that meets preset conditions.
[0015] The conditional node objects are stored in the second collection, which is a two-column data collection. Processing unit 5 is used to transform the second collection using a preset utility class to obtain the target XML data structure.
[0016] In the first possible implementation of the second aspect, each node object in the at least one node object mentioned above includes: a node identity ID, a node value, and the node's parent node ID; storage
[0017] The unit is specifically used to traverse the first set, and for each node object 0 in at least one node object, the following process is performed: if the current node ID of the current node object is empty and the current node ID is not contained in the second set, create the XML object corresponding to the current node, and store the XML object and the node ID corresponding to the XML object in the second set.
[0018] In the second possible implementation of the second aspect, each node object in the at least one node object includes: a node identity ID, a node value, and a parent node ID of the node; a storage unit is specifically used to traverse the first set, and for each node object in the at least one node object, the following process is performed: if the second set does not contain the parent node ID corresponding to the current node, an XML object corresponding to the current node is created, and the XML object and the parent node ID corresponding to the current node are stored in the second set.
[0019] In the third possible implementation of the second aspect, each node object in the at least one node object includes: node identity ID, node value, and parent node ID of the node; a storage unit is specifically used to traverse the first set, and the following process is performed on each node object in the at least one node object: if the current node value of the current node object is not empty, create an XML object corresponding to the current node, and store the XML object and the parent node ID corresponding to the current node in the second set.
[0020] In the fourth possible implementation of the second aspect, the processing unit is further configured to store the node objects that meet the preset conditions in the first set into the second set, establish the node relationship between each node object according to the position information of each node object in the second set, and remove the target node object in the second set, wherein the target node object is a duplicate non-leaf node object.
[0021] Thirdly, this application provides a data structure construction apparatus, which includes: a processor and a communication interface; the communication interface and the processor are coupled, and the processor is used to run computer programs or instructions to implement the data structure construction method as described in the first aspect and any possible implementation thereof.
[0022] Fourthly, this application provides a computer-readable storage medium storing instructions that, when executed on a terminal, cause the terminal to perform the data structure construction method described in the first aspect and any possible implementation thereof.
[0023] Fifthly, embodiments of this application provide a computer program product containing instructions that, when run on a data structure construction apparatus, cause the data structure construction apparatus to perform the data structure construction method as described in the first aspect and any possible implementation thereof.
[0024] In a sixth aspect, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface and the processor being coupled, the processor being used to run computer programs or instructions to implement the data structure construction method as described in the first aspect and any possible implementation of the first aspect.
[0025] Specifically, the chip provided in this application embodiment also includes a memory for storing computer programs or instructions. Attached Figure Description
[0026] Figure 1 A flowchart illustrating a data structure construction method provided in this application embodiment;
[0027] Figure 2 This is a schematic diagram of a data structure construction device provided in an embodiment of this application;
[0028] Figure 3 A schematic diagram of another data structure construction apparatus provided in an embodiment of this application;
[0029] Figure 4 This is a schematic diagram of the structure of a chip provided in an embodiment of this application. Detailed Implementation
[0030] The data structure construction method, apparatus, and storage medium provided in the embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0031] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can represent three situations: A exists alone, A and B exist simultaneously, and B exists alone.
[0032] The terms "first" and "second," etc., used in the specification and drawings of this application are used to distinguish different objects or to distinguish different treatments of the same object, rather than to describe a specific order of objects.
[0033] Furthermore, the terms "comprising" and "having," and any variations thereof, used in the description of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the steps or units listed, but may optionally include other steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus.
[0034] It should be noted that in the embodiments of this application, the words "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of the words "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0035] Currently, XML data structures can be persisted based on their characteristics and then read and parsed when needed. In software system development, API request bodies often use XML format. Currently, constructing XML request parameters, based on API requirements, generally involves the following four steps:
[0036] The first step is to create a doc object to store the XML structure information.
[0037] The second step is to create all XML nodes and write values to the leaf nodes.
[0038] The third step is to establish the parent-child relationships between all nodes according to the required XML structure.
[0039] The fourth step is to generate the XML data structure.
[0040] The second and third steps above may involve creating XML nodes while simultaneously establishing parent-child relationships between them, requiring the parent-child relationships between inner XML nodes to be established first, followed by those between outer XML nodes. However, this method necessitates repeatedly creating XML nodes to generate the XML data structure, resulting in bloated code. Furthermore, as the hierarchy and number of request nodes increase, the parent-child relationships between nodes become increasingly chaotic and difficult to maintain. Moreover, the traditional method of constructing XML request parameters requires creating inner XML nodes first, then outer XML nodes, and finally establishing parent-child relationships between them. This contradicts the habit of viewing tree structures from top to bottom, making it prone to errors when constructing hierarchical relationships and resulting in high maintenance costs.
[0041] To address the problem of redundant node data in existing XML data structures, which cannot be resolved in the current technology, this application provides a data structure construction method. The method involves obtaining a first set, which includes at least one node object, each representing an Extensible Markup Language (XML) node. The first set is a single-column data set. Node objects in the first set that meet preset conditions are stored in a second set, which is a two-column data set. A preset utility class is used to transform the second set to obtain the target XML data structure. In this solution, because the method is based on a single-column set, the XML data structure is constructed sequentially from top to bottom using the sequential structure of the single-column set. This eliminates the need to repeatedly create nodes during the construction of the XML data structure, solving the code redundancy problem caused by traditional methods of creating XML objects. Furthermore, the top-down sequential construction of the XML data structure facilitates subsequent maintenance.
[0042] like Figure 1 The diagram shows a flowchart of a data structure construction method provided in an embodiment of this application. The method includes the following steps S101 to S103:
[0043] S101, The data structure construction device obtains the first set.
[0044] In this embodiment of the application, the first set includes at least one node object, each node object representing an Extensible Markup Language (XML) node, and the first set is a single-column data set.
[0045] For example, the first set mentioned above can be a list collection.
[0046] Optionally, in the embodiments of this application, each of the above-mentioned at least one node object includes a target field, which may include at least one of the following: node identifier (ID), node value, and the parent node ID of the node.
[0047] It should be noted that the values of the target fields mentioned above are obtained and entered by the user in advance.
[0048] For example, node objects are created from top to bottom according to the XML request parameters. Node creation process: The first node object is created, with its parent node ID (hereinafter referred to as ParentKey) being the root node field of the request parameters, and its node ID (hereinafter referred to as Key) being the second-level node field of the request parameters. If the second-level node is a non-leaf node, the value is null; otherwise, it is set to the value of the second-level node. The node object is then added to a list collection. The second node object is created, with its ParentKey being the first non-leaf node in the request parameters moving from the second level towards the root node, and its Key being the third-level node field of the request parameters. If the third-level node is a non-leaf node, the value is null; otherwise, it is set to the value of the third-level node. The node object is then added to a single-column collection. The nth node object is created, with its ParentKey being the first non-leaf node in the request parameters moving from the nth level towards the root node, and its Key being the (n+1)th level node field of the request parameters. If the (n+1)th level node is a non-leaf node, the value is null; otherwise, it is set to the value of the (n+1)th level node. The node object is then added to a single-column collection.
[0049] Step S102: The data structure construction device stores the node objects in the first set that meet the preset conditions into the second set.
[0050] In this embodiment of the application, the second set is a two-column data set.
[0051] For example, the second set mentioned above can be a ResultMap collection.
[0052] Optionally, in this embodiment, each node object in the at least one node object includes: node ID, node value, and parent node ID; step S102 can be specifically implemented through the following step S201:
[0053] S201. The data structure construction device traverses the first set and performs the following process for each node object in at least one node object: if the current node ID of the current node object is empty and the second set does not contain the current node ID, create an XML object corresponding to the current node and store the XML object and the node ID corresponding to the XML object in the second set.
[0054] For example, the data structure building device traverses the first set, determines whether the key of the node object exists in the ResultMap, and if it does not exist, creates an XML object and stores it in the ResultMap along with the key.
[0055] In this embodiment, the data structure construction device can traverse the first set and store node objects with empty node IDs in the first set into the second set. This avoids the situation where the data structure construction device fails to obtain the node object when the node ID in the first set is empty, thereby improving the accuracy of the data structure construction device in constructing the data structure.
[0056] Optionally, in this embodiment, each node object in the at least one node object includes: node ID, node value, and parent node ID; step S102 can be specifically implemented through the following step S301:
[0057] S301. The data structure construction device traverses the first set and performs the following process for each node object in at least one node object: if the second set does not contain the parent node ID corresponding to the current node, create the XML object corresponding to the current node and store the XML object and the parent node ID corresponding to the current node in the second set.
[0058] For example, when traversing the first set, the data structure building device can determine in real time whether the ParentKey of the current node object exists in the ResultMap. If it does not exist, an XML object is created and stored in the ResultMap along with the ParentKey.
[0059] In this embodiment, the data structure construction device can traverse the first set and determine in real time whether the ParentKey of the current node object exists in the second set. If it does not exist, it is stored in the second set, which avoids the problem of not being able to find the parent node of the node in the first set in the second set, thus improving the accuracy of the data structure construction device in constructing the data structure.
[0060] Optionally, in this embodiment, each node object in the at least one node object includes: node ID, node value, and parent node ID; step S102 can be specifically implemented through the following step S401:
[0061] S401. The data structure construction device traverses the first set and performs the following process for each node object in at least one node object: if the current node value of the current node object is not empty, create the XML object corresponding to the current node and store the XML object and the parent node ID corresponding to the current node in the second set.
[0062] For example, when the data structure building device sequentially traverses the first set, if the value of a node object is not null, it creates an XML object corresponding to the current node and stores the XML object and the parent node ID corresponding to the current node in the second set.
[0063] In this embodiment, the data structure construction device can traverse the first set and determine in real time whether there is a case where the value of the current node in the first set is not empty. If it is not empty, the current node and its corresponding ParentKey are stored in the second set, thus avoiding the inability to find the parent node of the node in the first set in the second set and improving the accuracy of the data structure construction device in constructing the data structure.
[0064] Optionally, in this embodiment of the application, after step S102 above, the data structure construction method provided in this embodiment of the application further includes the following step S501:
[0065] S501, the data structure construction device establishes the node relationship between each node object based on the position information of each node object in the second set, and removes the target node object from the second set. The target node object is a duplicate non-leaf node object.
[0066] In this embodiment of the application, the data structure construction device can determine the parent-child relationship between each node object by using the node ID of each node and the ParentKey corresponding to that node.
[0067] In this embodiment of the application, after obtaining the node relationships between each node, the data structure construction device can delete duplicate non-leaf node objects, thereby avoiding a large amount of redundancy in the node data in the obtained target data structure.
[0068] Step S103: The data structure construction device transforms the second set using a preset tool class to obtain the target XML data structure.
[0069] For example, the utility class mentioned above can be a tool class.
[0070] Optionally, in this embodiment of the application, after obtaining the second set after redundancy removal, the data structure construction device can transform the second set into a second set object.
[0071] For example, after obtaining the second set object, the data structure construction device can input the second set object into the tool class, thereby transforming the second set object through the tool class to obtain a standard XML string.
[0072] This application provides a data structure construction method. A first set is obtained, comprising at least one node object, each node object representing an Extensible Markup Language (XML) node. The first set is a single-column data set. Node objects in the first set that meet preset conditions are stored in a second set, which is a two-column data set. A preset utility class is used to transform the second set to obtain the target XML data structure. In this solution, because this application uses a method for constructing an XML data structure based on a single-column set, the XML data structure is constructed sequentially from top to bottom using the sequential structure of the single-column set. This eliminates the need to repeatedly create nodes during the construction of the XML data structure, solving the code redundancy problem caused by traditional methods of creating XML objects. Furthermore, the top-down sequential construction of the XML data structure facilitates subsequent maintenance.
[0073] This application embodiment can divide the data structure construction device into functional modules or functional units according to the above method examples. For example, each function can be divided into a separate functional module or functional unit, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or in software functional modules or functional units. The module or unit division in this application embodiment is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.
[0074] like Figure 2 The diagram shown is a schematic diagram of a data structure construction device provided in an embodiment of this application. The device includes: an acquisition unit 401, a storage unit 402, and a processing unit 403.
[0075] The system includes an acquisition unit 401, which acquires a first set containing at least one node object, each representing an Extensible Markup Language (XML) node. The first set is a single-column data set. A storage unit 402 stores node objects from the first set that meet preset conditions into a second set, which is a two-column data set. A processing unit 403 uses a preset utility class to transform the second set to obtain the target XML data structure.
[0076] In one possible implementation, each node object in the at least one node object includes: node ID, node value, and parent node ID of the node; storage unit 402 is specifically used to traverse the first set and perform the following process for each node object in the at least one node object: if the current node ID of the current node object is empty and the second set does not contain the current node ID, create an XML object corresponding to the current node and store the XML object and the node ID corresponding to the XML object in the second set.
[0077] In one possible implementation, each node object in the at least one node object includes: a node identity ID, a node value, and a parent node ID; the storage unit 402 is specifically used to traverse the first set and perform the following process for each node object in the at least one node object: if the second set does not contain the parent node ID corresponding to the current node, create an XML object corresponding to the current node and store the XML object and the parent node ID corresponding to the current node in the second set.
[0078] In one possible implementation, each node object in the at least one node object includes: a node identity ID, a node value, and a parent node ID; the storage unit 402 is specifically used to traverse the first set and perform the following process for each node object in the at least one node object: if the current node value of the current node object is not empty, create an XML object corresponding to the current node and store the XML object and the parent node ID corresponding to the current node in the second set.
[0079] In one possible implementation, the processing unit 403 is further configured to store the node objects that meet the preset conditions in the first set into the second set, establish the node relationship between each node object according to the position information of each node object in the second set, and remove the target node object in the second set, wherein the target node object is a duplicate non-leaf node object.
[0080] This application provides a data structure construction device. Since the data structure construction device is a method for constructing XML data structures based on a single-column set, it constructs the XML data structure sequentially from top to bottom by using the sequential structure of the single-column set. When constructing the XML data structure, there is no need to repeatedly create nodes, which solves the code redundancy problem caused by the traditional method of creating XML objects. Moreover, by constructing the XML data structure sequentially from top to bottom, it is convenient for subsequent maintenance.
[0081] When implemented in hardware, the communication unit in this embodiment can be integrated onto the communication interface, and the processing unit 403 can be integrated onto the processor. Specific implementation methods are as follows: Figure 3 As shown.
[0082] Figure 3A schematic diagram of another possible structure of the data structure construction apparatus involved in the above embodiments is shown. This data structure construction apparatus includes a processor 302 and a communication interface 303. The processor 302 is used to control and manage the operation of the data structure construction apparatus, for example, executing the steps performed by the processing unit 403, and / or performing other processes of the technology described herein. The communication interface 303 is used to support communication between the data structure construction apparatus and other network entities, for example, executing the steps performed by the communication unit. The data structure construction apparatus may also include a memory 301 and a bus 304, the memory 301 being used to store the program code and data of the data structure construction apparatus.
[0083] The memory 301 may be a memory in a data structure construction device, and the memory may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as read-only memory, flash memory, hard disk or solid-state drive; the memory may also include a combination of the above types of memory.
[0084] The processor 302 described above can implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor can be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
[0085] Bus 304 can be an Extended Industry Standard Architecture (EISA) bus, etc. Bus 304 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 3 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0086] Figure 4 This is a schematic diagram of the structure of chip 170 provided in an embodiment of this application. Chip 170 includes one or more (including two) processors 1710 and communication interfaces 1730.
[0087] Optionally, the chip 170 also includes a memory 1740, which may include read-only memory and random access memory, and provides operation instructions and data to the processor 1710. A portion of the memory 1740 may also include non-volatile random access memory (NVRAM).
[0088] In some implementations, memory 1740 stores elements such as execution modules or data structures, or subsets thereof, or extended sets thereof.
[0089] In this embodiment of the application, the corresponding operation is executed by calling the operation instructions stored in the memory 1740 (the operation instructions can be stored in the operating system).
[0090] The processor 1710 described above can implement or execute various exemplary logic blocks, units, and circuits described in conjunction with the disclosure of this application. The processor can be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute various exemplary logic blocks, units, and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0091] The memory 1740 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as read-only memory, flash memory, hard disk or solid-state drive; the memory may also include combinations of the above types of memory.
[0092] The Bus 1720 can be an Extended Industry Standard Architecture (EISA) bus, etc. The Bus 1720 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 4 The symbol is represented by only one line, but this does not mean that there is only one bus or one type of bus.
[0093] Through the above description of the embodiments, those skilled in the art will clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device, and unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0094] This application provides a computer program product containing instructions that, when run on a computer, cause the computer to execute the data structure construction method described in the above method embodiments.
[0095] This application also provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the data structure construction method in the method flow shown in the above method embodiments.
[0096] The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires; a portable computer disk drive; a hard disk drive; a random access memory (RAM); a read-only memory (ROM); an erasable programmable read-only memory (EPROM); a register; a hard disk drive; an optical fiber; a portable compact disk read-only memory (CD-ROM); an optical storage device; a magnetic storage device; or any suitable combination thereof; or any other form of computer-readable storage medium known in the art. An exemplary storage medium is coupled to a processor, enabling the processor to read information from and write information to the storage medium. Of course, the storage medium may also be a component of the processor. The processor and the storage medium may reside in an application-specific integrated circuit (ASIC). In the embodiments of this application, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0097] Embodiments of the present invention provide a computer program product containing instructions that, when executed on a computer, cause the computer to perform actions such as... Figures 1 to 4 The data structure construction method described in [the document].
[0098] Since the data structure construction apparatus, computer-readable storage medium, and computer program product in the embodiments of the present invention can be applied to the above methods, the technical effects obtained can also be referred to the above method embodiments. The embodiments of the present invention will not be repeated here.
[0099] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0100] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0101] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0102] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A data structure construction method, characterized in that, The method includes: Obtain a first set, which includes at least one node object, each node object representing an Extensible Markup Language (XML) node, and the first set is a single-column data set; each node object includes: node identity ID, node value, and parent node ID; store the node objects in the first set that meet the preset conditions into a second set, which is a double-column data set; The second set is transformed using a pre-defined utility class to obtain the target XML data structure. The step of storing node objects in the first set that meet preset conditions into the second set includes: Iterate through the first set, and perform the following procedure for each node object in the at least one node object: If the current node ID of the current node object is empty and the second set does not contain the current node ID, create an XML object corresponding to the current node, and store the XML object and the node ID corresponding to the XML object in the second set; If the second set does not contain the parent node ID corresponding to the current node, create an XML object corresponding to the current node, and store the XML object and the parent node ID corresponding to the current node in the second set; If the current node value of the current node object is not empty, create an XML object corresponding to the current node, and store the XML object and the parent node ID corresponding to the current node in the second set.
2. The method according to claim 1, characterized in that, After storing the node objects that meet the preset conditions in the first set into the second set, the method further includes: Based on the position information of each node object in the second set, establish the node relationship between each node object, and remove the target node object from the second set, wherein the target node object is a duplicate non-leaf node object.
3. A data structure construction device, characterized in that, The device includes: an acquisition unit, a storage unit, and a processing unit; The acquisition unit is used to acquire a first set, which includes at least one node object. Each node object is used to represent an Extensible Markup Language (XML) node. The first set is a single-column data set. Each node object in the at least one node object includes: a node identity ID, a node value, and a parent node ID. The storage unit is used to store node objects that meet preset conditions in the first set into a second set, where the second set is a two-column data set; The processing unit is used to transform the second set using a preset utility class to obtain the target XML data structure; The storage unit is specifically used to traverse the first set and perform the following process for each node object in the at least one node object: if the current node ID of the current node object is empty and the second set does not contain the current node ID, create an XML object corresponding to the current node and store the XML object and the node ID corresponding to the XML object in the second set; If the second set does not contain the parent node ID corresponding to the current node, create an XML object corresponding to the current node, and store the XML object and the parent node ID corresponding to the current node in the second set; If the current node value of the current node object is not empty, create an XML object corresponding to the current node, and store the XML object and the parent node ID corresponding to the current node in the second set.
4. The apparatus according to claim 3, characterized in that, The processing unit is further configured to store the node objects that meet the preset conditions in the first set into the second set, establish the node relationship between each node object according to the position information of each node object in the second set, and remove the target node object in the second set, wherein the target node object is a duplicate non-leaf node object.
5. A data structure construction apparatus, characterized in that, include: A processor and a communication interface; the communication interface is coupled to the processor, the processor being used to run computer programs or instructions to implement the data structure construction method as described in any one of claims 1-2.
6. A computer-readable storage medium storing instructions, characterized in that, When the computer executes the instruction, the computer performs the data structure construction method as described in any one of claims 1-2.
Citation Information
Patent Citations
Message conversion method and device
CN113268955A
Construction method and device of tree structure data and computer equipment
CN114186102A