Search

CN-115510843-B - XML file comparison method and device, electronic equipment and storage medium

CN115510843BCN 115510843 BCN115510843 BCN 115510843BCN-115510843-B

Abstract

The embodiment of the application provides an XML file comparison method, an XML file comparison device, electronic equipment and a storage medium, wherein the method comprises the steps of obtaining a first XML file and a second XML file, converting the first XML file into first tree dictionary data, converting the second XML file into second tree dictionary data, wherein nodes in the first tree dictionary data comprise configuration tables, the configuration tables are used for describing a comparison mode among first nodes in the first tree dictionary data, second nodes in the second tree dictionary data and corresponding to the first nodes, traversing the first tree dictionary data, and comparing the first nodes in the current traversal with the second nodes corresponding to the first nodes in the current traversal according to the configuration tables corresponding to the first nodes in the current traversal to obtain a comparison result. By implementing the embodiment, the accuracy of comparison can be improved, so that the comparison result is more accurate.

Inventors

  • LIANG WENLAN
  • LUO WEI

Assignees

  • 广东三维家信息科技有限公司

Dates

Publication Date
20260505
Application Date
20221013

Claims (8)

  1. 1. An XML document comparison method, comprising: Acquiring a first XML file and a second XML file; Converting the first XML file into first tree dictionary data; converting the second XML file into second tree dictionary data; Setting a corresponding configuration table for each node in the first tree dictionary data, wherein the configuration table is used for describing an comparison method between a first node in the first tree dictionary data and a second node corresponding to the first node in the second tree dictionary data; traversing the first tree dictionary data, and comparing the first node traversed currently with the second node corresponding to the first node traversed currently according to a configuration table corresponding to the first node traversed currently to obtain a comparison result; the first node and the second node respectively comprise fields, the configuration table comprises filtering fields in the fields and comparison identifiers between the first node and the second node, and the method for generating the filtering fields comprises the following steps: acquiring a test case corresponding to the first XML file; Executing the test case twice under the same environment to respectively obtain a third XML file and a fourth XML file; Performing difference analysis according to the third XML file and the fourth XML file to obtain difference data; adding the difference data as a filtering field to the configuration table in the first tree dictionary data; The configuration table comprises a comparison identifier between the first node and the second node; the step of comparing the first node traversed currently with the second node corresponding to the first node traversed currently to obtain the comparison result comprises the following steps: Judging whether the first node which is currently traversed and the corresponding second node are to be compared or not according to the comparison identification of the configuration table of the first node which is currently traversed.
  2. 2. The XML file comparison method of claim 1, wherein the configuration table comprises an anchor field of the fields; the step of traversing the first tree dictionary data, comparing the first node traversed currently with the second node corresponding to the first node traversed currently according to a configuration table corresponding to the first node traversed currently, and obtaining a comparison result, wherein the step comprises the following steps: determining the second node in the second tree dictionary data according to the anchor field of the first node currently traversed; And comparing the first node with the second node which is traversed currently to obtain the comparison result.
  3. 3. The method for comparing XML files according to claim 1, wherein the first node and the second node further comprise attribute values of the fields, and the step of comparing the currently traversed first node with the second node corresponding to the currently traversed first node to obtain the comparison result comprises the steps of: Acquiring a filtering field of the first node in the configuration table; Determining a non-filtering field of the first node according to the filtering field; and comparing the attribute values of the non-filtering fields in the first node and the corresponding second node which are traversed currently to obtain the comparison result.
  4. 4. The XML file comparison method of claim 3, wherein the data of the configuration table comprises a precision field in the fields and a precision of the precision field; the step of comparing the attribute values of the non-filtered fields in the first node and the corresponding second node to obtain the comparison result includes: And if the non-filtering field is a precision field, comparing the precision field of the first node with the precision field of the corresponding second node according to the precision of the precision field to obtain a comparison result.
  5. 5. The XML file comparison method of claim 1, wherein the first node further comprises data of a child node of the first node, the second node further comprises data of a child node of the second node, the first node and the second node further comprise node names, respectively; the step of comparing the first node traversed currently with the second node corresponding to the first node traversed currently to obtain the comparison result comprises the following steps: Generating a first dictionary according to the child node names of the first node currently traversed; generating a second dictionary according to the child node names of the corresponding second nodes; and comparing the first dictionary with the second dictionary to obtain the comparison result.
  6. 6. An XML document alignment apparatus for implementing the method of any one of claims 1-5, comprising: The acquisition module is used for acquiring the first XML file and the second XML file; The conversion module is used for converting the first XML file into first tree dictionary data; the conversion module is further used for converting the second XML file into second tree dictionary data; Setting a corresponding configuration table for each node in the first tree dictionary data, wherein the configuration table is used for describing an comparison method between a first node in the first tree dictionary data and a second node corresponding to the first node in the second tree dictionary data; and the comparison module is used for traversing the first tree dictionary data, and comparing the first node which is traversed currently with the second node which is traversed currently and corresponds to the first node according to the configuration table which is traversed currently and corresponds to the first node, so that a comparison result is obtained.
  7. 7. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, the processor implementing the steps of the method according to any one of claims 1-5 when the computer program is executed.
  8. 8. A computer readable storage medium having instructions stored thereon which, when run on a computer, cause the computer to perform the method of any of claims 1-5.

Description

XML file comparison method and device, electronic equipment and storage medium Technical Field The application relates to the technical field of data analysis, in particular to an XML file comparison method, an XML file comparison device, electronic equipment and a storage medium. Background XML is a common format for computers and is widely available in web pages, configuration, data storage, and other applications. When information is stored, memory data is often required to be stored in a common data format after serialization, after program iteration, the data structure is often faced with the structure, the attribute and the numerical value which are difficult to perceive, and sequencers or testers are difficult to effectively perceive data output by programs of two different iteration versions under the condition of the same data input, whether differences exist, what differences exist, which differences exist are effective, and which differences are noise. The common two XML data are compared, an XML data tree-turning structure is adopted, and then all leaves are traversed to carry out one comparison. Disclosure of Invention In view of this, an object of the embodiments of the present application is to provide an XML file comparison method, apparatus, electronic device, and storage medium, which can solve the comparison of XML files with disordered structures, and improve the accuracy of the comparison result. In a first aspect, an embodiment of the present application provides an XML method, including: Acquiring a first XML file and a second XML file; Converting the first XML file into first tree dictionary data; converting the second XML file into second tree dictionary data; The nodes in the first tree dictionary data comprise a configuration table, and the configuration table is used for describing the comparison method among the first nodes in the first tree dictionary data and the second nodes corresponding to the first nodes in the second tree dictionary data; Traversing the first tree dictionary data, and comparing the first node which is traversed currently with the second node which is traversed currently and corresponds to the first node according to a configuration table which is traversed currently and corresponds to the first node, so that a comparison result is obtained. In the implementation process, unlike the prior art, the embodiment of the application sets the corresponding configuration table for each node in the first tree structure, so that the comparison accuracy is improved, and the comparison result is more accurate. Further, the first node and the second node each include a field; The configuration table comprises an anchoring field in the fields; the step of traversing the first tree dictionary data, comparing the first node traversed currently with the second node corresponding to the first node traversed currently according to a configuration table corresponding to the first node traversed currently, and obtaining a comparison result, wherein the step comprises the following steps: Determining the second node in the second tree dictionary data according to the anchor field of the first node currently traversed; And comparing the first node with the second node which is traversed currently to obtain the comparison result. In the implementation process, the second node can be quickly determined in the second tree dictionary data by setting the anchoring field, so that the problem of inaccurate comparison result caused by disordered comparison is avoided. Further, the configuration table comprises comparison identifications of the first node and the second node; The step of comparing the first node and the second node which are currently traversed to obtain the comparison result comprises the following steps: Judging whether the first node and the second node which are currently traversed are compared according to the comparison identification of the configuration table of the first node which is currently traversed, and obtaining the comparison result. In the implementation process, whether to compare the data in the first tree dictionary data can be flexibly set by changing different values of the comparison mark, so that the comparison of the first XML file and the second XML file is more targeted, and the comparison speed of the first XML file and the second XML file can be improved. Further, the first node and the second node further comprise attribute values of the fields, and the configuration table comprises filtering fields in the fields; The step of comparing the first node and the second node which are currently traversed to obtain the comparison result comprises the following steps: Acquiring a filtering field of the first node in the configuration table; Determining a non-filtering field of the first node according to the filtering field; and comparing the attribute values of the non-filtering fields in the first node and the second node which are traversed cur