XML (Extensible Markup Language) file visual comparison method and device and electronic equipment
XML file comparison is performed through DiffBuilder.compare and CheckForSimilar methods, the problem of inaccurate comparison in the existing technology is solved, and the accurate comparison and intuitive display of XML file content is achieved, which improves the comparison efficiency and accuracy.
Patent Information
- Application Number
- CN202510048492.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-06-06
AI Technical Summary
When comparing XML files in the prior art, it is impossible to accurately identify node content with similar structures but different orders, resulting in inaccurate comparisons, and manual writing of style rules increases development workload and maintenance difficulty.
XML file comparison is performed through the DiffBuilder.compare method, use the CheckForSimilar method to find nodes with different structures but similar contents, record the initial difference information, build the Diff object, and obtain detailed difference information through ApplyDifference. Then, write an XSLT stylesheet, load the style file, create a converter, convert the XML file to an HTML file, and display the comparison results in the browser.
It realizes accurate comparison of XML file contents, can intuitively display the differences between the comparison files, reduces the user's comparison workload, improves the comparison efficiency, and ensures the accuracy of the final PDF style.
Smart Images

Figure CN120106038A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of electronic manual comparison, and in particular to an XML file visual comparison method, device and electronic equipment. Background Art
[0002] Aircraft, automobiles, large electronic equipment and other industries have begun to use electronic interactive manuals, following the manual standard rules (S1000D, Airbus FlightOps XML Exchange, Boeing FTID, ATAiSpec 2300), and comparing XML files can help companies and organizations quickly find differences between documents. When performing manual XML file comparison, staff need to have a certain understanding of the XML file comparison requirements. More importantly, manual comparison cannot ensure the consistency and accuracy of documents.
[0003] In traditional XML document comparison methods, usually only the structure and content of the documents can be compared to see if they are completely consistent, while ignoring the similar but different order node contents that may exist in actual applications, which causes the comparison of many key information to become inaccurate or unrecognizable; in the process of converting XML documents to HTML, if style rules need to be manually written for each tag and attribute, this will greatly increase the development workload and may lead to style inconsistencies and difficulties in maintenance.
[0004] However, there is currently no technical solution that can solve the above technical problems, and there is no XML file visual comparison method, device and electronic device. Summary of the invention
[0005] The present invention provides an XML file visual comparison method, device and electronic device, which compares two XML files, introduces XSL style, and finally converts them into HTML for display in a browser. This display page not only keeps consistent with the style of the target PDF sample, but also can clearly display the differences between the compared files, so that users can intuitively see the changes in content.
[0006] In a first aspect, the present invention provides an XML file visual comparison method, comprising:
[0007] The first Document object is specified as a comparison benchmark using the preset comparison method DiffBuilder.compare, the second Document object is specified as a to-be-compared object using the preset designation method WithTest, and similarity check method CheckForSimilar is used to determine similar nodes, wherein the similar nodes are nodes with completely or not completely the same structure and similar content, the first Document object is generated based on a first XML file, the second Document object is generated based on a second XML file, and the first XML file and the second XML file are electronic manual files;
[0008] Traverse the DOM trees of the first Document object and the second Document object, use the node ID as an anchor to process all similar nodes, determine the matching nodes, use the difference listener DifferenceListener to record each initial difference information corresponding to each matching node, call the preset construction method DiffBuilder.build to build and return all Diff objects, each Diff object contains the initial difference information between the first Document object and the second Document object, and the initial difference information includes content difference, attribute difference and child node data difference;
[0009] For each Diff object, call the preset difference acquisition method ApplyDifference to obtain each detailed difference information, the detailed difference information includes attribute node differences and attribute element differences, and add all detailed difference information to the attribute difference map of the XmlDiff object;
[0010] Analyze the file tags and file attributes parsed by the XSD rules using preset data standards, write an XSLT style sheet, load the style file according to the attribute difference mapping and the XSLT style sheet, create a converter, use the converter to convert the first XML file and the second XML file into the first HTML file and the second HTML file, and display the first HTML file and the second HTML file on a preset display interface.
[0011] According to the XML file visual comparison method provided by the present invention, before using the preset comparison method DiffBuilder.compare to specify the first Document object as a comparison reference, the method further includes:
[0012] receiving a user input, wherein the user input is generated after the user determines the first XML file and the second XML file in the preset display interface;
[0013] In response to the user input, the first XML file and the second XML file are converted into a first stream file and a second stream file, and the first stream file and the second stream file are parsed into a first Document object and a second Document object using a DocumentBuilder instance.
[0014] According to the XML file visual comparison method provided by the present invention, after using the similarity check method CheckForSimilar to determine similar nodes, the method further includes:
[0015] Use the first preset ignoring method IgnoreComments to ignore the comments in the first Document object and the second Document object;
[0016] Use the second preset ignore method NormalizeWhitespace to normalize whitespace characters by ignoring whitespace differences between nodes or in node content.
[0017] According to the XML file visual comparison method provided by the present invention, before traversing the DOM tree of the first Document object and the second Document object, the method further includes:
[0018] A node filter is configured, and a preset exclusion method WithNodeFilter is used to exclude preset nodes from all similar nodes, wherein the preset nodes include processing instruction nodes and document type nodes.
[0019] According to the XML file visual comparison method provided by the present invention, the use of a difference listener DifferenceListener to record difference information includes:
[0020] When the order of the matching nodes in the first Document object and the second Document object is different, the matching nodes are processed by using the preset matching method DefaultNodeMatcher and the preset comparison method ByAnchorElementSelector.
[0021] According to the XML file visual comparison method provided by the present invention, the calling of the preset difference acquisition method ApplyDifference to acquire each detailed difference information includes:
[0022] Call the preset selection method XPathUtil.selectNode, and use the preset expressions LeftDetail.getXPath and RightDetail.getXPath to obtain all first attribute nodes and all second attribute nodes from the Diff object, convert all first attribute nodes and all second attribute nodes to Attr type, and store them in LeftAttr and RightAttr variables respectively;
[0023] Using the preset element acquisition methods LeftAttr.getOwnerElement and RightAttr.getOwnerElement, respectively obtain the XML elements owned by all first attribute nodes and all second attribute nodes, obtain all first XML elements and all second XML elements, and store all first XML elements and all second XML elements in LeftElem and RightElem variables respectively;
[0024] Use the preset search method FindDifference to determine the difference object related to each attribute. If the difference object cannot be determined, create an XmlElementDiff object and set the object properties, which include left and right XPaths, anchor attribute, anchor value, element name, initially empty attribute difference mapping, and left and right elements. Add the XmlElementDiff object to the Differences collection.
[0025] According to the XML file visual comparison method provided by the present invention, after writing the XSLT style sheet, a custom CSS style is added to the file tag, and the custom CSS style includes page size, header attributes, footer attributes, editing content, page type, font type, color, label, table border type, and table merging.
[0026] According to the XML file visual comparison method provided by the present invention, the method of loading a style file according to the attribute difference mapping and the XSLT style sheet to create a converter includes:
[0027] Set the style sheet path Path, and create an input stream InputStream through the preset creation method New ClassPathResource(path).getInputStream, the input stream points to the XSLT style sheet file in the specified path in the class path;
[0028] The input stream is used to create a StreamSource object encapsulating an XSLT style sheet file, and the preset creation method TransformerFactory.newTemplates is called to create a Templates object according to the StreamSource object. The Templates object is used to be reused to perform multiple XSLT transformations.
[0029] In a second aspect, a device for visually comparing XML files is provided, comprising:
[0030] A determination unit, the determination unit is used to specify the first Document object as a comparison benchmark using a preset comparison method DiffBuilder.compare, specify the second Document object as a to-be-compared object using a preset designation method WithTest, and use a similarity check method CheckForSimilar to determine similar nodes, wherein the similar nodes are nodes with completely or not completely the same structure and similar content, the first Document object is generated based on a first XML file, the second Document object is generated based on a second XML file, and the first XML file and the second XML file are electronic manual files;
[0031] A traversal unit, the traversal unit is used to traverse the DOM trees of the first Document object and the second Document object, use the node ID as an anchor to process all similar nodes, determine matching nodes, use the difference listener DifferenceListener to record each initial difference information corresponding to each matching node, call the preset construction method DiffBuilder.build to build and return all Diff objects, each Diff object contains the initial difference information between the first Document object and the second Document object, and the initial difference information includes content difference, attribute difference and child node data difference;
[0032] A calling unit, the calling unit is used to call a preset difference acquisition method ApplyDifference for each Diff object to obtain each detailed difference information, the detailed difference information including attribute node difference and attribute element difference, and add all the detailed difference information to the attribute difference map of the XmlDiff object;
[0033] A display unit is used to analyze file tags and file attributes parsed by XSD rules using preset data standards, write an XSLT style sheet, load a style file according to the attribute difference mapping and the XSLT style sheet, create a converter, use the converter to convert the first XML file and the second XML file into the first HTML file and the second HTML file, and display the first HTML file and the second HTML file on a preset display interface.
[0034] In a third aspect, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the XML file visual comparison method when executing the program.
[0035] The electronic manual file comparison method disclosed in the present invention can efficiently and accurately identify the differences between two or more documents, including content additions and deletions, format changes, and error corrections, etc., which solves the time-consuming, labor-intensive, and error-prone problems of manual comparison for users, ensures the consistency of document content, and improves work efficiency and quality; it can focus more on the content differences themselves without having to meet excessively high professional and technical requirements. At the same time, since the present invention ensures the accuracy of the conversion process, there will be no problem that the final version of the PDF style does not meet expectations, which not only significantly reduces the user's comparison workload, but also greatly improves the comparison efficiency, bringing great convenience to users;
[0036] The present invention can automatically obtain the XML file to be compared, and convert it into a stream file form for parsing and comparison, thereby greatly improving the comparison efficiency and accuracy; using the CheckForSimilar method of DiffBuilder, it is possible to find nodes with similar contents even if the structures are not exactly the same for comparison; it is possible to ignore the comment parts in the XML file and the blank character differences between nodes or in the node content during the comparison process; it provides a wealth of comparison option configurations, such as the configuration of node filters and node matchers, which enables users to flexibly adjust the comparison strategy according to their own needs, so as to obtain a comparison result that is more in line with expectations. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0038] Figure 1 It is a flow chart of the XML file visual comparison method provided by the present invention;
[0039] Figure 2 It is a structural schematic diagram of the XML file visual comparison device provided by the present invention;
[0040] Figure 3 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are 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.
[0042] Figure 1 The figure is a flow chart of the XML file visual comparison method provided by the present invention, wherein the XML file visual comparison method comprises:
[0043] Step 101, using the preset comparison method DiffBuilder.compare to specify the first Document object as a comparison benchmark, using the preset designation method WithTest to specify the second Document object as an object to be compared, using the similarity check method CheckForSimilar to determine similar nodes, wherein the similar nodes are nodes with completely or not completely the same structure and similar content, the first Document object is generated according to a first XML file, the second Document object is generated according to a second XML file, and the first XML file and the second XML file are electronic manual files;
[0044] Step 102, traverse the DOM trees of the first Document object and the second Document object, use the node ID as an anchor to process all similar nodes, determine the matching nodes, use the difference listener DifferenceListener to record each initial difference information corresponding to each matching node, call the preset construction method DiffBuilder.build to build and return all Diff objects, each Diff object contains the initial difference information between the first Document object and the second Document object, and the initial difference information includes content difference, attribute difference and child node data difference;
[0045] Step 103: For each Diff object, call the preset difference acquisition method ApplyDifference to obtain each detailed difference information, wherein the detailed difference information includes attribute node differences and attribute element differences, and add all detailed difference information to the attribute difference map of the XmlDiff object;
[0046] Step 104: Analyze the file tags and file attributes parsed by the XSD rules using the preset data standard, write an XSLT style sheet, load the style file according to the attribute difference mapping and the XSLT style sheet, create a converter, use the converter to convert the first XML file and the second XML file into the first HTML file and the second HTML file, and display the first HTML file and the second HTML file on a preset display interface.
[0047] In step 101, before using the preset comparison method DiffBuilder.compare to specify the first Document object as a comparison reference, the method further includes:
[0048] receiving a user input, wherein the user input is generated after the user determines the first XML file and the second XML file in the preset display interface;
[0049] In response to the user input, the first XML file and the second XML file are converted into a first stream file and a second stream file, and the first stream file and the second stream file are parsed into a first Document object and a second Document object using a DocumentBuilder instance.
[0050] Optionally, the user selects the XML files to be compared in the preset display interface, the first XML file and the second XML file are electronic manual files, the system backend obtains the XML files to be compared and converts them into a streaming file format; then, a "DocumentBuilder" instance is created through the "DocumentBuilderFactory"; then, the "parse()" method of the "DocumentBuilder" instance is used to parse the XML data file into a Document object for subsequent access and operation of the content of this XML document.
[0051] Optionally, after determining the first Document object and the second Document object, create a "DiffBuilder" instance, convert the first Document object into an input format acceptable to "DiffBuilder", use the "DiffBuilder.compare()" method, and pass in the first Document object as a comparison basis; at the same time, specify the XML file for comparison, and use the "withTest()" method to specify the XML document to be compared with the first Document object, that is, the second Document object.
[0052] Optionally, after using the similarity check method CheckForSimilar to determine similar nodes, the method further includes:
[0053] Use the first preset ignoring method IgnoreComments to ignore the comments in the first Document object and the second Document object;
[0054] Use the second preset ignore method NormalizeWhitespace to normalize whitespace characters by ignoring whitespace differences between nodes or in node content.
[0055] Optionally, configure the comparison options, use ".checkForSimilar()" to enable similarity checking to find nodes with similar content even if the structure is not exactly the same; use ".ignoreComments()" to ignore the comments in the XML file during the comparison process; use ".normalizeWhitespace()" to normalize whitespace characters and ignore whitespace differences between nodes or in node content.
[0056] In step 102, before traversing the DOM trees of the first Document object and the second Document object, the method further includes: configuring a node filter, using a preset exclusion method WithNodeFilter to exclude preset nodes from all similar nodes, wherein the preset nodes include processing instruction nodes and document type nodes.
[0057] Optionally, the present invention uses a node filter, through the "withNodeFilter()" method, to exclude node types that do not need to participate in the comparison. Here, processing instruction nodes such as "<?xml-stylesheet...?>" and document type nodes such as "<!DOCTYPE html>" are excluded because these nodes usually do not contain the actual content or structural information of the document, and therefore may not need to be considered during comparison.
[0058] In step 102, a node matcher is specified through ".withNodeMatcher(...)", "DefaultNodeMatcher" is used, and "ByAnchorElementSelector" is passed to match nodes based on the element's anchor point (such as ID attribute). If two nodes have the same ID, they will be treated as matching nodes for comparison. By traversing the DOM trees of the two documents, the ID is used as an anchor point to ensure that the nodes in the two documents can be matched even if their contexts or orders are different. After the corresponding nodes are determined, the differences in node content, attributes, number of child nodes, etc. are compared. During the comparison process, the corresponding difference information will be recorded through the difference listener (DifferenceListener).
[0059] Optionally, the using a difference listener DifferenceListener to record the difference information includes:
[0060] When the order of the matching nodes in the first Document object and the second Document object is different, the matching nodes are processed by using the preset matching method DefaultNodeMatcher and the preset comparison method ByAnchorElementSelector.
[0061] In an optional embodiment, assume that there are two XML documents, one of which may have undergone some modifications (such as changes in the order of elements, addition of additional spaces, etc.), but currently want to ensure that the content of certain key elements (such as elements with specific IDs) is consistent.
[0062] You can refer to the following:
[0063] "<!--document1.xml-->
[0064] <root>
[0065] <element id="test1">Content 1
[0066] <element id="test2">Content 2
[0067] < / root>
[0068] <!--document2.xml-->
[0069] <root>
[0070] <element id="test2">Content 2
[0071] <element id="test1">Content 1
[0072] < / root> ”;
[0073] When comparing these two documents, you can use "DefaultNodeMatcher" and "ByAnchorElementSelector" to ensure that elements with id="test1" and id="test2" are matched and compared correctly, even if their order differs between the documents:
[0074] "DiffBuilder diffBuilder="
[0075] DiffBuilder.compare(Input.fromDocument(document1))
[0076] .withTest(Input.fromDocument(document2))
[0077] .withNodeMatcher(newDefaultNodeMatcher(new ByAnchorElementSelector()));
[0078] Diff diff=diffBuilder.build();”
[0079] This way, even if the structures of two documents differ, as long as the content of elements with the same ID is the same, they will be considered a match, allowing for more flexible and powerful comparison of XML documents.
[0080] In step 103, the calling of the preset difference acquisition method ApplyDifference to acquire each detailed difference information includes:
[0081] Call the preset selection method XPathUtil.selectNode, and use the preset expressions LeftDetail.getXPath and RightDetail.getXPath to obtain all first attribute nodes and all second attribute nodes from the Diff object, convert all first attribute nodes and all second attribute nodes to Attr type, and store them in LeftAttr and RightAttr variables respectively;
[0082] Using the preset element acquisition methods LeftAttr.getOwnerElement and RightAttr.getOwnerElement, respectively obtain the XML elements owned by all first attribute nodes and all second attribute nodes, obtain all first XML elements and all second XML elements, and store all first XML elements and all second XML elements in LeftElem and RightElem variables respectively;
[0083] Use the preset search method FindDifference to determine the difference object related to each attribute. If the difference object cannot be determined, create an XmlElementDiff object and set the object properties, which include left and right XPaths, anchor attribute, anchor value, element name, initially empty attribute difference mapping, and left and right elements. Add the XmlElementDiff object to the Differences collection.
[0084] Optionally, the present invention builds and returns a Diff object containing the difference information between the two documents by calling the "diffBuilder.build()" method according to the previous configuration and the two specified documents. It traverses all the differences contained in the Diff object and calls the "applyDifference" method for each difference to obtain detailed difference information, such as the type of difference, the elements or attributes involved, and the status of these elements or attributes in the original document and the comparison document, and marks the corresponding differences by adding custom attributes to these elements.
[0085] First, select and process attribute node differences by calling the "XPathUtil.selectNode" method and using "leftDetail.getXPath()" and "rightDetail.getXPath()", two XPath expressions pointing to specific attributes, to select the corresponding attribute nodes from the document. Then, convert these nodes to Attr type and store them in leftAttr and rightAttr variables respectively;
[0086] Then, get the elements to which the attributes belong and mark the differences. Use the "leftAttr.getOwnerElement()" and "rightAttr.getOwnerElement()" methods to get the elements owned by the two attributes, that is, the XML elements they belong to, and store them in the "leftElem" and "rightElem" variables respectively. In order to mark the differences between these elements, add some custom attributes to "leftElem" and "rightElem". These attributes are prefixed with "DIFF_ATTR" to indicate the type of difference, such as "TYPE_BEFORE_UPDATED" and "TYPE_AFTER_UPDATED", and set a special attribute, such as "DIFF_ATTRS", to mark that multiple attributes of the element are updated;
[0087] Next, process the difference objects. Use the custom "findDifference method" to find the difference objects related to the currently processed attribute. This method looks for existing difference objects in the differences collection based on the parent XPath. If not found, i.e., "xmlDiff == null", a new "XmlElementDiff" object is created and its related attributes are set, including the left and right XPaths, anchor attributes, anchor values, element names, an initially empty attribute difference mapping, and the left and right elements. Subsequently, this newly created difference object is added to the differences collection. If a difference object has been found, it is directly reused for subsequent operations;
[0088] Finally, record the attribute differences. Add the currently processed attribute differences to the attribute difference mapping of the xmlDiff object for subsequent processing and reporting. The currently processed attribute differences are determined with "leftAttr.getNodeName()" as the key and the difference type "XmlElementDiff.Type.UPDATED" as the value.
[0089] In step 104, write an XSLT style sheet. According to the S1000D data standard, analyze the XSD rules and parse out the tags. Since the XML file is composed of a tag hierarchical structure, first analyze the hierarchical structure of the DM file to obtain the tags and attributes. Use XPath expressions to select nodes in the XML document and use XSLT elements such as "xsl:value-of" and "xsl:for-each" to construct the structure and content of the target document.
[0090] Optionally, after writing the XSLT style sheet, add custom CSS styles to the file tags. The custom CSS styles include page size, header attributes, footer attributes, editable content, page type, font type, color, label, table border type, and table merging.
[0091] Optionally, based on the parsed tags and attributes, combined with the existing PDF styles, define the styles of the tags. For example, if there is a Title element in the XML file and there is a Title tag "<xs:element name = \"Title\">" in the XSD. For the tag, define "<xsl:template match = \"tag name\">", and for the attribute, define "<xsl:if test = \"@attribute name = 'attribute value'>". Add custom CSS styles to the tag, specifically such as page size, header attributes, footer attributes, editable content, page type, font type, color, label, table border type, and table merging.
[0092] The present invention does not require style processing for templates that directly read the content in tags, for example, when encountering the tag "para" in XML, there is no need to process the content style; for templates that need style processing for reading the content in tags, for example, when encountering the "title" element in XML, a "bold" attribute is added to the "title" to bold the "title" element; the color is selected through attributes according to the standard corresponding to the referenced "xsd", such as the "dispatchConditionTitle" tag can select different colors according to the "priorityLevel" attribute. When encountering the "dispatchConditionTitle" element in XML, there is a "priorityLevel" attribute under the "dispatchConditionTitle" tag, and the values of the "priorityLevel" attribute include 'CAUTION', 'WARNING', and 'STATUS'. When the value of the "priorityLevel" attribute is 'CAUTION', the font color of the element "dispatchConditionTitle" is set to "#ff8c00"; when the value of the "priorityLevel" attribute is 'WARNING', the font color of the element "dispatchConditionTitle" is set to "#FFFFFF"; when the value of the "priorityLevel" attribute is 'STATUS', the font color of the element "dispatchConditionTitle" is set to "#00FEF5".
[0093] For the image template setting, by defining the "template" template and the "match" definition tag "symbol", when the "symbol" element is encountered in XML, the image is introduced through the "img" tag, and the width and height of the image are set through "width" and "height"; for the hyperlink template setting, when the "dmRefIdent" element is encountered in XML, the content underline is set through the u tag, and the color is blue "color="blue"".
[0094] Optionally, the loading of a style file according to the attribute difference mapping and the XSLT style sheet to create a converter includes:
[0095] Set the style sheet path Path, and create an input stream InputStream through the preset creation method New ClassPathResource(path).getInputStream, the input stream points to the XSLT style sheet file in the specified path in the class path;
[0096] The input stream is used to create a StreamSource object encapsulating an XSLT style sheet file, and the preset creation method TransformerFactory.newTemplates is called to create a Templates object according to the StreamSource object. The Templates object is used to be reused to perform multiple XSLT transformations.
[0097] Optionally, first check the path prefix, set the stylesheet path path, create an "InputStream" through "new ClassPathResource(path).getInputStream()", which points to the XSLT stylesheet file at the specified path in the class path, use this input stream to create a "StreamSource" object, which encapsulates the input stream of the XSLT stylesheet, call "transformerFactory.newTemplates(...)" to create a Templates object based on the provided "StreamSource" (that is, the XSLT stylesheet), this Templates object can be reused to perform multiple XSLT transformations without reloading the stylesheet each time.
[0098] Then, perform the transformation. After preparing the Transformer object and setting all necessary parameters, the code performs the transformation operation. The "transform(Source input,Result output)" method accepts two parameters: input is the source of the DM document to be transformed, and output is the target of the transformation result. The transformation operation reads the data in the input, transforms it according to the XSLT stylesheet, and writes the result to the output.
[0099] Finally, the parsed HTML is returned to the front end and displayed in the browser; this display page is not only consistent with the style of the target PDF sample, but also can clearly display the differences between the compared files, so that users can intuitively see the changes in the content; users can focus more on the content differences themselves without having to meet excessively high professional technical requirements. At the same time, since the present invention ensures the accuracy of the conversion process, there will be no problem that the final PDF style does not meet expectations. The present invention not only significantly reduces the user's editing workload, but also greatly improves editing efficiency, bringing great convenience to users.
[0100] The electronic manual file comparison method disclosed in the present invention can efficiently and accurately identify the differences between two or more documents, including content additions and deletions, format changes, and error corrections, etc., which solves the time-consuming, labor-intensive, and error-prone problems of manual comparison for users, ensures the consistency of document content, and improves work efficiency and quality; it can focus more on the content differences themselves without having to meet excessively high professional and technical requirements. At the same time, since the present invention ensures the accuracy of the conversion process, there will be no problem that the final version of the PDF style does not meet expectations, which not only significantly reduces the user's comparison workload, but also greatly improves the comparison efficiency, bringing great convenience to users;
[0101] The present invention can automatically obtain the XML file to be compared, and convert it into a stream file form for parsing and comparison, thereby greatly improving the comparison efficiency and accuracy; using the CheckForSimilar method of DiffBuilder, it is possible to find nodes with similar contents even if the structures are not exactly the same for comparison; it is possible to ignore the comment parts in the XML file and the blank character differences between nodes or in the node content during the comparison process; it provides a wealth of comparison option configurations, such as the configuration of node filters and node matchers, which enables users to flexibly adjust the comparison strategy according to their own needs, so as to obtain a comparison result that is more in line with expectations.
[0102] Figure 2 It is a structural diagram of the XML file visualization comparison device provided by the present invention, the XML file visualization comparison device includes a determination unit 1, the determination unit is used to specify the first Document object as a comparison benchmark using the preset comparison method DiffBuilder.compare, specify the second Document object as an object to be compared using the preset designation method WithTest, and use the similarity check method CheckForSimilar to determine similar nodes, the similar nodes are nodes with completely or not completely the same structure and similar content, the first Document object is generated according to the first XML file, the second Document object is generated according to the second XML file, the first XML file and the second XML file are electronic manual files, the working principle of the determination unit 1 can refer to the aforementioned step 101, which will not be repeated here.
[0103] The XML file visual comparison device also includes a traversal unit 2, which is used to traverse the DOM trees of the first Document object and the second Document object, use the node ID as an anchor point to process all similar nodes, determine the matching nodes, use the difference listener DifferenceListener to record each initial difference information corresponding to each matching node, call the preset construction method DiffBuilder.build to build and return all Diff objects, each Diff object contains the initial difference information between the first Document object and the second Document object, and the initial difference information includes content difference, attribute difference and child node data difference. The working principle of the traversal unit 2 can refer to the aforementioned step 102 and will not be repeated here.
[0104] The XML file visual comparison device also includes a calling unit 3, which is used to call a preset difference acquisition method ApplyDifference for each Diff object to obtain each detailed difference information, wherein the detailed difference information includes attribute node differences and attribute element differences, and all detailed difference information is added to the attribute difference map of the XmlDiff object. The working principle of the calling unit 3 can refer to the aforementioned step 103 and will not be repeated here.
[0105] The XML file visualization comparison device also includes a display unit 4, which is used to analyze the file tags and file attributes parsed by the XSD rules using preset data standards, write an XSLT style sheet, load the style file according to the attribute difference mapping and the XSLT style sheet, create a converter, use the converter to convert the first XML file and the second XML file into a first HTML file and a second HTML file, and display the first HTML file and the second HTML file on a preset display interface. The working principle of the display unit 4 can refer to the aforementioned step 104 and will not be repeated here.
[0106] The electronic manual file comparison method disclosed in the present invention can efficiently and accurately identify the differences between two or more documents, including content additions and deletions, format changes, and error corrections, etc., which solves the time-consuming, labor-intensive, and error-prone problems of manual comparison for users, ensures the consistency of document content, and improves work efficiency and quality; it can focus more on the content differences themselves without having to meet excessively high professional and technical requirements. At the same time, since the present invention ensures the accuracy of the conversion process, there will be no problem that the final version of the PDF style does not meet expectations, which not only significantly reduces the user's comparison workload, but also greatly improves the comparison efficiency, bringing great convenience to users;
[0107] The present invention can automatically obtain the XML file to be compared, and convert it into a stream file form for parsing and comparison, thereby greatly improving the comparison efficiency and accuracy; using the CheckForSimilar method of DiffBuilder, it is possible to find nodes with similar contents even if the structures are not exactly the same for comparison; it is possible to ignore the comment parts in the XML file and the blank character differences between nodes or in the node content during the comparison process; it provides a wealth of comparison option configurations, such as the configuration of node filters and node matchers, which enables users to flexibly adjust the comparison strategy according to their own needs, so as to obtain a comparison result that is more in line with expectations.
[0108] Figure 3 Schematic diagram of the structure of the electronic device provided by the present invention. Figure 3As shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330 and a communication bus 340, wherein the processor 310, the communication interface 320 and the memory 330 communicate with each other through the communication bus 340. The processor 310 may call the logic instructions in the memory 330 to execute the XML file visual comparison method, the method comprising: using the preset comparison method DiffBuilder.compare to specify the first Document object as a comparison benchmark, using the preset designation method WithTest to specify the second Document object as an object to be compared, using the similarity check method CheckForSimilar to determine similar nodes, the similar nodes are nodes with completely or not completely the same structure and similar content, the first Document object is generated according to the first XML file, the second Document object is generated according to the second XML file, the first XML file and the second XML file are electronic manual files; traversing the DOM trees of the first Document object and the second Document object, using the node ID as an anchor to process all similar nodes, determining matching nodes, and using the difference listener DifferenceListener to record the corresponding nodes of each matching node For each initial difference information, call the preset construction method DiffBuilder.build to build and return all Diff objects. Each Diff object contains the initial difference information between the first Document object and the second Document object, and the initial difference information includes content difference, attribute difference and sub-node data difference; for each Diff object, call the preset difference acquisition method ApplyDifference to obtain each detailed difference information, and the detailed difference information includes attribute node difference and attribute element difference, and add all detailed difference information to the attribute difference mapping of the XmlDiff object; use the preset data standard to analyze the file tags and file attributes parsed by the XSD rule, write an XSLT style sheet, load the style file according to the attribute difference mapping and the XSLT style sheet, create a converter, use the converter to convert the first XML file and the second XML file into the first HTML file and the second HTML file, and display the first HTML file and the second HTML file in the preset display interface.
[0109] In addition, the logic instructions in the above-mentioned memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0110] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute a method for visually comparing XML files provided by the above methods, the method including: using a preset comparison method DiffBuilder.compare to specify a first Document object as a comparison benchmark, using a preset designation method WithTest to specify the second Document object as an object to be compared, using a similarity check method CheckForSimilar to determine similar nodes, wherein the similar nodes are nodes with completely or non-completely identical structures and similar contents, the first Document object is generated based on a first XML file, the second Document object is generated based on a second XML file, the first XML file and the second XML file are electronic manual files; traversing the DOM trees of the first Document object and the second Document object, using the node ID as an anchor to process all similar nodes, determining matching nodes, and using The difference listener DifferenceListener records each initial difference information corresponding to each matching node, calls the preset construction method DiffBuilder.build to build and return all Diff objects, each Diff object contains the initial difference information between the first Document object and the second Document object, and the initial difference information includes content difference, attribute difference and sub-node data difference; for each Diff object, call the preset difference acquisition method ApplyDifference to obtain each detailed difference information, the detailed difference information includes attribute node difference, attribute element difference, and all detailed difference information is added to the attribute difference mapping of the XmlDiff object; use the preset data standard to analyze the file tags and file attributes parsed by the XSD rule, write an XSLT style sheet, load the style file according to the attribute difference mapping and the XSLT style sheet, create a converter, use the converter to convert the first XML file and the second XML file into the first HTML file and the second HTML file, and display the first HTML file and the second HTML file in the preset display interface.
[0111] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the processor executes the XML file visualization comparison method provided by the above methods, the method comprising: using a preset comparison method DiffBuilder.compare to specify a first Document object as a comparison benchmark, using a preset designation method WithTest to specify the second Document object as an object to be compared, using a similarity check method CheckForSimilar to determine similar nodes, wherein the similar nodes are nodes with completely or not completely the same structure and similar content, the first Document object is generated based on a first XML file, the second Document object is generated based on a second XML file, and the first XML file and the second XML file are electronic manual files; traversing the DOM trees of the first Document object and the second Document object, using the node ID as an anchor to process all similar nodes, determining matching nodes, and using a difference listener DifferenceL istener records each initial difference information corresponding to each matching node, calls the preset construction method DiffBuilder.build to build and return all Diff objects, each Diff object contains the initial difference information between the first Document object and the second Document object, and the initial difference information includes content difference, attribute difference and sub-node data difference; for each Diff object, calls the preset difference acquisition method ApplyDifference to obtain each detailed difference information, and the detailed difference information includes attribute node difference and attribute element difference, and adds all detailed difference information to the attribute difference mapping of the XmlDiff object; uses the preset data standard to analyze the file tags and file attributes parsed by the XSD rule, writes an XSLT style sheet, loads the style file according to the attribute difference mapping and the XSLT style sheet, creates a converter, uses the converter to convert the first XML file and the second XML file into the first HTML file and the second HTML file, and displays the first HTML file and the second HTML file in the preset display interface.
[0112] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0113] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0114] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for visual comparison of XML files, characterized in that: include: The preset comparison method DiffBuilder.compare is used to specify the first Document object as a comparison benchmark, the preset designation method WithTest is used to specify the second Document object as an object to be compared, and the similarity check method CheckForSimilar is used to determine similar nodes, wherein the similar nodes are nodes with completely or not completely the same structure and similar content, the first Document object is generated according to a first XML file, the second Document object is generated according to a second XML file, and the first XML file and the second XML file are electronic manual files; Traverse the DOM trees of the first Document object and the second Document object, use the node ID as an anchor to process all similar nodes, determine the matching nodes, use the difference listener DifferenceListener to record each initial difference information corresponding to each matching node, call the preset construction method DiffBuilder.build to build and return all Diff objects, each Diff object contains the initial difference information between the first Document object and the second Document object, and the initial difference information includes content difference, attribute difference and child node data difference; For each Diff object, call the preset difference acquisition method ApplyDifference to obtain each detailed difference information, the detailed difference information includes attribute node differences and attribute element differences, and add all detailed difference information to the attribute difference map of the XmlDiff object; Analyze the file tags and file attributes parsed by the XSD rules using preset data standards, write an XSLT style sheet, load the style file according to the attribute difference mapping and the XSLT style sheet, create a converter, use the converter to convert the first XML file and the second XML file into the first HTML file and the second HTML file, and display the first HTML file and the second HTML file on a preset display interface.
2. The XML file visual comparison method according to claim 1, characterized in that: Before using the preset comparison method DiffBuilder.compare to specify the first Document object as a comparison reference, the method further includes: receiving a user input, wherein the user input is generated after the user determines the first XML file and the second XML file in the preset display interface; In response to the user input, the first XML file and the second XML file are converted into a first stream file and a second stream file, and the first stream file and the second stream file are parsed into a first Document object and a second Document object using a DocumentBuilder instance.
3. The XML file visual comparison method according to claim 1, characterized in that: After determining similar nodes using the similarity check method CheckForSimilar, the method further includes: Use the first preset ignoring method IgnoreComments to ignore the comments in the first Document object and the second Document object; Use the second preset ignore method NormalizeWhitespace to normalize whitespace characters by ignoring whitespace differences between nodes or in node content.
4. The XML file visual comparison method according to claim 1, characterized in that: Before traversing the DOM trees of the first Document object and the second Document object, the method further includes: A node filter is configured, and a preset exclusion method WithNodeFilter is used to exclude preset nodes from all similar nodes, wherein the preset nodes include processing instruction nodes and document type nodes.
5. The XML file visual comparison method according to claim 1, characterized in that: The use of the difference listener DifferenceListener to record the difference information includes: When the order of the matching nodes in the first Document object and the second Document object is different, the matching nodes are processed by using the preset matching method DefaultNodeMatcher and the preset comparison method ByAnchorElementSelector.
6. The XML file visual comparison method according to claim 1, characterized in that: The calling of the preset difference acquisition method ApplyDifference to obtain each detailed difference information includes: Call the preset selection method XPathUtil.selectNode, and use the preset expressions LeftDetail.getXPath and RightDetail.getXPath to obtain all first attribute nodes and all second attribute nodes from the Diff object, convert all first attribute nodes and all second attribute nodes to Attr type, and store them in LeftAttr and RightAttr variables respectively; Using the preset element acquisition methods LeftAttr.getOwnerElement and RightAttr.getOwnerElement, respectively obtain the XML elements owned by all first attribute nodes and all second attribute nodes, obtain all first XML elements and all second XML elements, and store all first XML elements and all second XML elements in LeftElem and RightElem variables respectively; Use the preset search method FindDifference to determine the difference object related to each attribute. If the difference object cannot be determined, create an XmlElementDiff object and set the object properties, which include left and right XPaths, anchor attribute, anchor value, element name, initially empty attribute difference mapping, and left and right elements. Add the XmlElementDiff object to the Differences collection.
7. The XML file visual comparison method according to claim 1, characterized in that: After writing the XSLT style sheet, add custom CSS styles to the file tags, the custom CSS styles including page size, header attributes, footer attributes, edit content, page type, font type, color, label, table border type, and table merge.
8. The XML file visual comparison method according to claim 1, characterized in that: The step of loading a style file according to the attribute difference mapping and the XSLT style sheet to create a converter includes: Set the style sheet path Path, and create an input stream InputStream through the preset creation method New ClassPathResource(path).getInputStream, the input stream points to the XSLT style sheet file in the specified path in the class path; The input stream is used to create a StreamSource object encapsulating an XSLT style sheet file, and the preset creation method TransformerFactory.newTemplates is called to create a Templates object according to the StreamSource object. The Templates object is used to be reused to perform multiple XSLT transformations.
9. An XML file visual comparison device, characterized in that: include: A determination unit, the determination unit is used to specify a first Document object as a comparison benchmark using a preset comparison method DiffBuilder.compare, specify a second Document object as a to-be-compared object using a preset designation method WithTest, and use a similarity check method CheckForSimilar to determine similar nodes, wherein the similar nodes are nodes with completely or not completely the same structure and similar content, the first Document object is generated based on a first XML file, the second Document object is generated based on a second XML file, and the first XML file and the second XML file are electronic manual files; A traversal unit, the traversal unit is used to traverse the DOM trees of the first Document object and the second Document object, use the node ID as an anchor to process all similar nodes, determine matching nodes, use the difference listener DifferenceListener to record each initial difference information corresponding to each matching node, call the preset construction method DiffBuilder.build to build and return all Diff objects, each Diff object contains the initial difference information between the first Document object and the second Document object, and the initial difference information includes content difference, attribute difference and child node data difference; A calling unit, the calling unit is used to call a preset difference acquisition method ApplyDifference for each Diff object to obtain each detailed difference information, the detailed difference information including attribute node difference and attribute element difference, and add all the detailed difference information to the attribute difference map of the XmlDiff object; A display unit is used to analyze file tags and file attributes parsed by XSD rules using preset data standards, write an XSLT style sheet, load a style file according to the attribute difference mapping and the XSLT style sheet, create a converter, use the converter to convert the first XML file and the second XML file into the first HTML file and the second HTML file, and display the first HTML file and the second HTML file on a preset display interface.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the XML file visual comparison method as described in any one of claims 1 to 8 is implemented.