Content analysis and positioning method and system based on DOM (Document Object Model) structure

By constructing a DOM tree and text index, and using an improved dynamic programming algorithm and multi-dimensional positioning strategy, the problem of accurate content positioning and marking in complex structures of HTML documents was solved. This enabled accurate positioning and multi-dimensional marking of erroneous content, improving positioning accuracy and visualization effects.

CN121787400APending Publication Date: 2026-04-03XIAN BODA SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-26
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

Existing technologies struggle to accurately locate and mark content in HTML documents, especially when dealing with nested structures, conflicts between various tags, and the lack of multi-dimensional positioning capabilities in complex HTML document structures.

Method used

By constructing a DOM tree and text index, using an improved dynamic programming algorithm to calculate the longest common subsequence, identifying different characters and establishing a special tag range mapping table, and combining multi-dimensional positioning strategies and priority rules to handle tag conflicts, accurate tags are generated.

Benefits of technology

It achieves accurate identification and marking of erroneous content while maintaining the HTML document structure, resolves the marking conflict problem, improves the accuracy of location and the clarity of visualization, and expands the detection capabilities for hyperlinks and element attributes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121787400A_ABST
    Figure CN121787400A_ABST
Patent Text Reader

Abstract

The invention discloses a content parsing and positioning method and system based on a DOM structure. The method comprises the steps that an HTML document is parsed, a DOM tree and a text index are constructed, a correct text and a wrong text are input, and a difference character index list is returned based on longest common subsequence recognition; traversing the DOM tree to identify the special labels and establish a special label range mapping table, and correspondingly selecting a positioning strategy to obtain a positioning result; associating the DOM node identifier based on the difference character index list to perform difference analysis to obtain a difference result of the wrong text and the correct text; traversing all nodes in the DOM tree to analyze attribute values of the nodes, and judging and generating a mark according to a difference result and a positioning result; conflicts among the multiple marks are processed according to a preset priority rule, and the positions of the marks are adjusted through a position updating algorithm; and applying the updated and adjusted mark to the original document to generate final output. According to the method, accurate content positioning and marking in the HTML document can be realized, and the original DOM structure is not influenced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a method and system for content parsing and positioning based on DOM structure, belonging to the technical field of computer applications. Background Technology

[0002] With the development of the internet, the quality inspection of web page content has become increasingly important. Especially in areas such as content moderation, text proofreading, and web security testing, precise content location and marking within HTML documents are crucial. Existing technologies primarily focus on plain text processing or simple HTML parsing, making it difficult to handle complex HTML document structures and diverse positioning requirements. In practical applications, HTML documents have the following characteristics: they contain nested DOM trees, text content is scattered across various tags, resulting in a complex structure, and text, links, styles, and scripts are mixed together. Content may be dynamically generated or modified via JavaScript, exhibiting dynamism, and there are diverse error types such as spelling errors, syntax errors, and inappropriate links. These characteristics make precise content location and marking within HTML documents extremely challenging.

[0003] Currently, existing technologies for precise content location and tagging of HTML documents suffer from the following drawbacks: Traditional text processing methods cannot handle the structural information of HTML documents, leading to inaccurate location. Using regular expressions to process HTML documents has well-known limitations, making it difficult to handle nested structures. Pure DOM manipulation methods are inefficient when processing large volumes of documents. Furthermore, existing technologies struggle to handle conflicts between various tags, such as overlapping style tags and error tags. Additionally, existing technologies typically only allow location based on a single dimension (e.g., text content), lacking multi-dimensional location capabilities. Moreover, they cannot adjust location and tagging strategies based on context (e.g., whether within a specific tag). This invention aims to address these shortcomings.

[0004] Therefore, there is an urgent need for a content parsing and positioning method and system based on the DOM structure, which can accurately locate and mark the document content while maintaining the original HTML document structure, so as to address the problems raised in the background. Summary of the Invention

[0005] The summary section of this application is intended to provide a brief overview of the concepts, which will be described in detail in the detailed description section below. This summary section is not intended to identify key or essential features of the claimed technical solutions, nor is it intended to limit the scope of the claimed technical solutions.

[0006] To address the problems and shortcomings of existing technologies, this invention aims to provide a content parsing and positioning method and system based on DOM structure. This method and system can accurately locate and mark erroneous words while maintaining the original HTML document structure, accurately identify and label correct content in nested HTML document structures, and perform structural parsing and target content verification on hyperlinks in HTML documents. It can locate content based on both text features and HTML document structure, thus resolving potential conflicts arising from multiple tags in complex HTML document structures. This addresses the problems mentioned in the background section.

[0007] To achieve the above objectives, the present invention provides the following technical solution: This invention discloses a content parsing and location method based on DOM structure, comprising the following steps: Step 1: Extract the HTML document to build the DOM tree and text index, and obtain the correct and incorrect text as input; Step 2: Based on the correct and incorrect texts, identify and return a list of differing character indices using the longest common subsequence. Step 3: Traverse the DOM tree to identify special tags, establish a special tag range mapping table, and select the corresponding positioning strategy to obtain the positioning result; Step 4: Based on the DOM node identifier associated with the list of differing character indices, perform difference analysis to obtain the difference results between the erroneous text and the correct text; Step 5: Traverse all nodes in the DOM tree, analyze the attribute values ​​of each node, and determine and generate tags based on the difference results and location results; Step 6: Process conflicts between multiple markers according to preset priority rules, and adjust the position of the markers using a position update algorithm; Step 7: Apply the updated and adjusted markup to the original document to generate the final output.

[0008] Preferably, step 2 further includes the following steps: Step 2.1: Associate the correct and incorrect text with the unique identifier of their respective DOM nodes; Step 2.2: Calculate the longest common subsequence (LCS) using an improved dynamic programming algorithm to adapt to the nested structure of the HTML document; Step 2.3: Identify the differential characters in the erroneous text based on the longest common subsequence (LCS); Step 2.4: Generate a list of indexes of the differing characters in the error text, and return the list of differing character indexes for subsequent marking.

[0009] Preferably, step 3 further includes the following steps: Step 3.1: Traverse the DOM tree to identify and record the node path range and tag attribute information of special tags, and establish a special tag range mapping table; Step 3.2: Determine the content to be located based on the context of the text content and the special tag range mapping table, and trigger the corresponding text location strategy when it meets the relevance determination rules; Step 3.3: After executing the text positioning strategy to obtain the positioning results, retain the valid results through double filtering and finally output the positioning result list.

[0010] Preferably, step 4 further includes the following steps: Step 4.1: Extract the text content of the nodes in the DOM tree, split it into a "character-node weight" binary array, and identify the type of the characters in each binary array; Step 4.2: Bind the “character-node weight” binary array to the DOM node identifier, and use the LCS algorithm with weight factor optimization to match and obtain the difference characters; Step 4.3: Perform special processing on the different types of the characters, and recombine the processed characters into complete text.

[0011] Preferably, step 5 further includes the following steps: Step 5.1: Use depth-first and breadth-first traversal algorithms to traverse all nodes of the DOM tree and analyze the attribute list of each node one by one; Step 5.2: Extract the attribute value of each node, remove special characters from the attribute value and convert it into a key-value pair; Step 5.3: Determine whether the attribute value meets the marking conditions, and inject custom DOM attributes into the elements containing attributes that meet the conditions; Step 5.4: Generate visual annotations for the custom DOM attributes using an absolute positioning annotation layer; Step 5.5: Repeat steps 5.1 to 5.4 to ensure that all nodes in the DOM tree that meet the criteria are checked and processed.

[0012] Preferably, in step 2.2, an improved dynamic programming algorithm is used to calculate the longest common subsequence (LCS). First, a two-dimensional dynamic programming (DP) table is constructed. The character sequences of the error text and the correct text are traversed to fill the two-dimensional DP table. When the i-th character of the error text is the same as the j-th character of the correct text and the DOM node identifiers of the two texts satisfy the relationship of "parent-child node" or "adjacent node at the same level", the text is filled. Then, starting from the lower right cell of the two-dimensional DP table, the text is backtracked upwards and then to the left to complete the extraction of the longest common subsequence length.

[0013] Preferably, in steps 3.2 and 3.3, the text positioning strategy is selected and executed in conjunction with the special label range mapping table, specifically as follows: For ordinary text content, text sequence combined with node fingerprinting is used for localization. The process involves matching the text to be located with the text content in the text index table, and combining the difference results to determine the specific node position of the text in the DOM tree. For attribute content, attribute value hashing combined with tag functionality is used for location. The process involves traversing the nodes of the target tag type in the DOM tree, extracting attribute values ​​and matching them with the attribute content to be located to determine the node position of the target attribute. For special tag content, text within dynamic script nodes is not positioned, while static script nodes only have their src attribute checked. Content within iframe tags triggers cross-domain detection, allowing penetration positioning; otherwise, it is marked as cross-domain and cannot be positioned.

[0014] Preferably, in step 4.3, special processing is performed for each type of difference, including spelling errors, extra characters, and missing characters, specifically: For ordinary characters, if they are different characters, apply a red wavy underline style directly; if they are not different characters, keep the original style. For space characters, if they are different characters, add a yellow background color mark and a transparent label; if they are not different characters, keep the original style. Tab characters: If they are different characters, they are replaced with blue special symbols and marked with a blue border; if they are not different characters, they are marked with gray and retain their original function.

[0015] Preferably, in step 6, conflicts between multiple tags are processed according to a preset priority rule, and the tag positions are adjusted by a position update algorithm. The priority levels are, from high to low, hyperlink risk tags, text error tags, special character tags, and style tags. During position update, the original position of high-priority tags is retained, and the position of low-priority tags is adjusted. If there is still a conflict after offset, it is adjusted until there is no overlap. Finally, a conflict processing log is generated.

[0016] This invention also discloses a content parsing and positioning system based on DOM structure, comprising: The document parsing module is used to extract HTML documents to build a DOM tree and text index, obtain correct and incorrect text as input, and identify and return a list of different character indexes based on the longest common subsequence of the correct and incorrect text. The multi-dimensional positioning module is used to traverse the DOM tree to identify special tags and establish a special tag range mapping table. Based on multi-dimensional positioning of text, structure and attributes, it dynamically selects the text positioning strategy in combination with the special tag range mapping table and obtains the positioning result by selecting the corresponding text positioning strategy. The difference analysis module is used to associate the difference character index list with DOM node identifiers to perform difference analysis and identify the difference results between the erroneous text and the correct text. The tag generation module is used to traverse all nodes in the DOM tree, analyze the attribute values ​​of each node, and determine and generate tags based on the difference results and positioning results; The conflict handling module is used to handle conflicts between multiple tags according to preset priority rules and adjust the tag positions through a position update algorithm. The content restructuring module is used to apply the updated and adjusted markup to the original document to generate the final output.

[0017] Compared with the prior art, the beneficial effects of the present invention are as follows: This invention provides a content parsing and positioning method and system based on DOM structure. It constructs a DP table associated with DOM node identifiers through an improved dynamic programming algorithm, optimizes backtracking rules, and achieves accurate difference analysis between erroneous and correct content within the HTML nested structure. This solves the problem that traditional LCS algorithms cannot handle cross-DOM node text sequences, providing a precise foundation for subsequent markup of differential characters. By identifying special tags in the HTML document and establishing a range mapping table, it dynamically selects text positioning or attribute positioning strategies based on the DOM node environment of the content (whether it is within a special tag, node hierarchy), avoiding the mispositioning of invalid content within special tags by traditional single-dimensional positioning and improving positioning accuracy. It defines clear tag priority rules and conflict judgment criteria, combined with a position update algorithm, to resolve contradictions when multiple tags overlap in node paths or conflict in visual styles, ensuring tag consistency and visual clarity, overcoming the deficiency of existing technologies in tag conflict handling without clear rules. For special characters such as spaces and tabs that are easily overlooked in HTML documents, it designs differentiated visual marking schemes (such as background color, special symbol replacement) to ensure that errors or anomalies of special characters can be accurately identified, filling the gap in existing technologies for special character marking. By extracting element attributes through depth-first traversal of the DOM tree, and establishing categorized attribute marking rules, risk detection and marking of attributes of elements such as hyperlinks and images are achieved. This expands the dimensions of positioning and marking, and solves the limitation of traditional technologies that only focus on text content and ignore element attributes. Attached Figure Description

[0018] The accompanying drawings, which form part of this application, are used to provide a further understanding of the application and to make other features, objects, and advantages of the application more apparent. The illustrative embodiments and descriptions of this application are used to explain the application and do not constitute an undue limitation of the application. In the drawings: Figure 1This is a flowchart illustrating the steps of the DOM-based content parsing and positioning method in an embodiment of the present invention. Figure 2 This is a flowchart of the HTML document parsing based on the longest common subsequence difference within the DOM structure-based content parsing and positioning method in this embodiment of the invention; Figure 3 This is a flowchart illustrating the filtering and positioning results using a special tag range mapping table within the DOM structure content parsing and positioning method in this embodiment of the invention. Figure 4 This is a flowchart illustrating the analysis of differences between error and correct content within the DOM-based content parsing and location method in this embodiment of the invention. Figure 5 This is a flowchart illustrating the method for parsing and locating content based on DOM structure in this embodiment of the invention, which uses the location results and difference analysis markers. Figure 6 This is a flowchart of adjusting the marker position within the DOM structure content parsing and positioning method in an embodiment of the present invention. Detailed Implementation

[0019] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.

[0020] It should also be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings. Unless otherwise specified, the embodiments and features described in this disclosure can be combined with each other. This invention aims to provide a precise annotation and validation method for HTML documents, enabling accurate positioning and marking of document content while maintaining the original HTML document structure. It also supports multi-dimensional positioning strategies, including positioning based on text content, DOM tree, and attributes, resolving marking conflicts to ensure consistency and visualization effects. Furthermore, it enhances context awareness, adjusting positioning and marking strategies according to the content's environment.

[0021] Example 1

[0022] This invention discloses a content parsing and positioning method based on DOM structure. The following will describe this disclosure in detail with reference to the accompanying drawings and embodiments. Figure 1 As shown, it includes the following steps: Step 1: Extract the HTML document to build the DOM tree and text index, and obtain the correct and incorrect text as input; Step 2: Based on the correct and incorrect text, identify and return a list of indexes of differing characters using the longest common subsequence. Step 3: Traverse the DOM tree to identify special tags, build a special tag range mapping table, and select the corresponding positioning strategy to obtain the positioning result; Step 4: Based on the list of differing character indexes and associated DOM node identifiers, perform difference analysis to obtain the difference results between the erroneous text and the correct text; Step 5: Traverse all nodes in the DOM tree, analyze the attribute values ​​of each node, and determine and generate tags based on the difference results and location results; Step 6: Handle conflicts between multiple markers according to preset priority rules, and adjust the marker positions using a position update algorithm; Step 7: Apply the updated and adjusted markup to the original document to generate the final output.

[0023] Specifically, step 1 involves extracting the HTML document to construct a DOM tree and text index, obtaining correct and incorrect text as input. HTML tags are ignored during extraction, and only text characters are retained. The HTML document is parsed to construct a DOM tree and a text index is built based on DOM nodes. The text index contains the text content, the identifier of the DOM node, and the node hierarchy, in the format of "root node > parent node [n] > child node [m]", such as body > div [2] > p [1].

[0024] like Figure 2 As shown, for step 2, a list of differing character indices is returned based on the longest common subsequence of the correct and incorrect text. This further includes the following steps: Step 2.1: Associate the correct and incorrect text with the unique identifier of their respective DOM nodes; Step 2.2: Calculate the longest common subsequence (LCS) using an improved dynamic programming algorithm to adapt to the nested structure of the HTML document; Step 2.3: Identify the differential characters in the erroneous text based on the longest common subsequence (LCS); Step 2.4: Generate a list of indexes of the differing characters in the error text, and return the list of differing character indexes for subsequent tagging.

[0025] Specifically, the system receives correct and incorrect text as input and associates each text character with a unique identifier of its DOM node (e.g., body>div[2]>p[1]). The storage structure adopts a key-value pair structure (e.g., {char:"a",nodeId:"body>div[2]>p[1]"}). The improved dynamic programming algorithm is used to calculate the longest common subsequence to adapt to the nested structure of the HTML document and construct a two-dimensional DP table. Among them, the row represents the character sequence of the incorrect text (labeled characters and the identifier of the DOM node), the column represents the character sequence of the correct text (labeled characters and the identifier of the DOM node), and the cell value represents the length of the longest common subsequence (LCS) before the corresponding character in the current row and column. When filling the table, when the i-th character of the incorrect text is the same as the j-th character of the correct text, and the identifiers of the DOM nodes of the two satisfy the relationship of "parent-child node" or "adjacent node at the same level", DP[i][j] = DP[i-1][j-1] + 1; otherwise, DP[i][j] = max(DP[i-1][j], DP[i][j-1]). When backtracking the table, start backtracking from the bottom right cell of the DP table. When DP[i][j] = DP[i-1][j-1] + 1, it means that the current character is part of the longest common subsequence (LCS), and record the character and its corresponding DOM node identifier. When DP[i][j] = DP[i-1][j], backtrack upwards. When DP[i][j] = DP[i][j-1], backtrack to the left. Continue backtracking until the top left cell of the table is reached, completing the extraction of the longest common subsequence (LCS).

[0026] Based on the longest common subsequence (LCS) result, the difference characters in the error text are identified. The correct text is compared character by character with the extracted longest common subsequence (LCS), and the correlation of the corresponding DOM node identifiers is checked. If the tag is not in the longest common subsequence (LCS) and the DOM node identifier cannot match the correct content character, it is determined to be a difference character. For example, if the error text "test" is located in body>span[1], while the correct text "test" is located in body>div[3], it is determined to be a difference. A list of indexes of the difference characters in the original error text is generated. This list of indexes contains the position number of the difference character in the error text, the DOM node identifier, and the character content. Finally, the list of difference character indexes is returned for subsequent tagging.

[0027] like Figure 3 As shown, for step 3, which involves traversing the DOM tree to identify special tags, establishing a special tag range mapping table, and selecting a corresponding positioning strategy to obtain the positioning result, the following steps are also included: Step 3.1: Traverse the DOM tree to identify and record the node path range and tag attribute information of special tags, and establish a special tag range mapping table; Step 3.2: Determine the content to be located based on the context of the text content and the special tag range mapping table, and trigger the corresponding text location strategy when it meets the relevance determination rules; Step 3.3: After obtaining the location results by executing the text location strategy, retain the valid results through double filtering and finally output the location result list.

[0028] Furthermore, the DOM tree is traversed to identify special tags (such as style, script, a, etc.), recording the node path range and tag attribute information of these special tags (such as the href attribute of the a tag), and establishing a special tag range mapping table. Based on the context of the text content, a text positioning strategy is selected in conjunction with the special tag range mapping table. When the content to be located meets the relevance judgment rules, the corresponding strategy is triggered. Specifically, for ordinary text that is hierarchically related and whose nodes are static, a combination of text sequence and node fingerprint is used for positioning, i.e., node fingerprint = node path + tag name + hash value of the number of child nodes, to avoid mispositioning of different nodes of the same text. For attribute content that is either dynamic or static, a combination of attribute value hashing and tag function is used for positioning, such as calculating the MD5 hash of the href attribute of the a tag to match risky link libraries, while also verifying whether the `target` attribute is `_blank`. For special tag content, text within dynamic script nodes is not positioned, while only the src attribute of static script nodes is checked. Content within iframe tags triggers cross-domain detection; if allowed, it is positioned through the domain; otherwise, it is marked as cross-domain and cannot be positioned. In addition, the rules for determining relevance are that the difference in level between the node containing the content to be located and its parent node is ≤2 and the node must be a non-container tag (e.g., a p node cannot cross a section container).

[0029] The selected text location strategy is then executed to obtain the location results. Specifically, for ordinary text location strategies, the text to be located is matched with the text content in the text index table, and the LCS difference analysis results are used to determine the specific node position of the text in the DOM tree. For attribute location strategies, nodes of the target tag type are traversed in the DOM tree, attribute values ​​are extracted (removing special symbols such as quotation marks and escape characters, and converting them to standard character sequences), and matched with the content of the attribute to be located to determine the node position of the target attribute. For content within special tags (such as CSS code within the style tag, JavaScript code within the script tag), exclusion or special processing is performed according to the application scenario requirements. For example, text content within the script tag is not subject to text error location, only the node position is recorded; text content within the a tag is subject to both text location and attribute location. After executing the location strategy, a double filtering is used to retain valid results. Specifically, the first layer filters nodes in dynamic nodes whose generation timestamp is less than or equal to the document loading completion timestamp to exclude invalid nodes that have not been fully rendered. The second layer filters location results across container tags; for example, if a node outside a section container matches text inside the container, it is considered invalid. The final output is a list of location results, including the node path, dynamic state, relevance score, and location strategy type. Location results that do not meet the criteria (such as text location results within style tags or attribute location results with empty attribute values) are filtered out, generating the final location result list, which includes the target content, the DOM node identifier, and the location strategy type.

[0030] like Figure 4 As shown, for step 4, differential analysis is performed based on the DOM node identifiers associated with the differential character index list to identify the differences between erroneous and correct text. Specifically, this includes the following steps: Step 4.1: Extract the text content of the nodes in the DOM tree, split it into a "character-node weight" binary array, and identify the type of the characters in each binary array; Step 4.2: Bind the "character-node weight" binary array to the DOM node identifier, and use the LCS algorithm with weight factor optimization to match the different characters; Step 4.3: Perform special processing on the different character types and recombine the processed characters into complete text.

[0031] Furthermore, the target text, extracted from the DOM tree nodes, is split into multiple "character-node weight" binary arrays, each with the structure [character, node weight]. The type of each character in these arrays is identified, including ordinary characters (such as letters, numbers, and Chinese characters), space characters (spaces, newlines), and tabs. A weight-factor optimized LCS algorithm is used to match differing characters. Specifically, the "character-node weight" binary array from step 4.1 is first bound to DOM node identifiers (such as slide indexes and shape IDs) to form a "character-node weight-DOM identifier" ternary array. Based on this ternary array, the source text sequence S and the correct text sequence T are obtained. A dynamic programming table dp[i][j] is created. If the characters in S[i] and T[j] are the same, the weight of that character is added; otherwise, the larger value between dp[i−1][j] and dp[i][j−1] is taken. The system extracts common characters (i.e., weighted LCS) by backtracking from the end of the table and prioritizing their respective weights. It then compares the source text sequence S and the correct text sequence T with the weighted LCS to identify redundant characters in the source text, missing characters in the correct text, and replacement characters. These are then linked to corresponding nodes using DOM markers. Finally, high-weighted difference characters are selected based on node weight thresholds for subsequent processing.

[0032] Special handling is applied to different types of differences, specifically as follows: For ordinary characters: If they are different characters, apply a red wavy underline style. The CSS style is defined as `text-decoration: wavy underline red`; if they are not different characters, keep the original style.

[0033] Space characters: If it is a differentiating character (such as an extra space), add a yellow background color marker. The CSS style is defined as (.space-error { background-color: #ffff00; position: relative;}), and a transparent "・" marker is added via pseudo-elements (.space-error::after { content: "・"; color: transparent; position: absolute; top: 0;left: 0;}) to ensure visibility; if it is a non-differentiating character, keep the original style.

[0034] Tab character: If it is a different character, replace the original tab character with a blue "⇥" special symbol and add a blue border. The CSS style is defined as .tab-error { border: 1px solid blue; padding: 0 2px; content: "⇥"; color: blue;}; If it is a non-different character, retain the original function and add a gray "⇥" tooltip. The CSS style is defined as .tab-normal { color: #999; content: "⇥";}.

[0035] Finally, the processed characters are reassembled into complete text, and corresponding HTMLspan tags are added to each processed character to wrap style information, generating a marked HTML string to ensure that the original DOM tree structure is not destroyed.

[0036] like Figure 5 As shown, step 5 involves traversing all nodes in the DOM tree, analyzing the attribute values ​​of each node, and generating tags based on the difference and location results. Specifically, this includes the following steps: Step 5.1: Use depth-first and breadth-first traversal algorithms to traverse all nodes of the DOM tree and analyze the attribute list of each node one by one; Step 5.2: Extract the attribute values ​​of each node, remove special characters from the attribute values, and convert them into key-value pairs; Step 5.3: Determine whether the attribute value meets the marking conditions, and inject the custom DOM attribute into the element containing the attribute that meets the conditions; Step 5.4: Generate visual annotations for custom DOM properties using an absolute positioning annotation layer; Step 5.5: Repeat steps 5.1 to 5.4 to ensure that all nodes in the DOM tree that meet the criteria are checked and processed.

[0037] Furthermore, a depth-first and breadth-first traversal algorithm is used to traverse all nodes of the DOM tree and analyze the attribute list of each node one by one. First, a breadth-first traversal is performed on container tags (div, section, etc.) to mark whether container nodes contain differences. Then, a depth-first traversal is performed on the child nodes within the container to accurately locate the leaf nodes where the difference characters are located. During the traversal, nodes corresponding to invalid differences need to be skipped, such as dynamic script nodes marked as IGNORE_. Then, the attribute values ​​of each node are extracted, and escape characters and empty characters in the attribute values ​​are removed and converted into "attribute name-normalized value" key-value pairs (e.g., the href attribute of an a tag is represented as {href: "https: / / xxx.com"}). The matching degree between the attribute value and the structured difference results is then calculated. When the matching degree is ≥0.7, it is determined that the attribute needs to be marked. The matching degree is obtained by the ratio of string edit distance / length. Next, it is determined whether the attribute value meets the marking conditions. Custom DOM attributes are injected into the elements containing attributes that meet the conditions. Specifically, the `data-diff-*` series of custom attributes are injected into the nodes containing the difference characters. Inject custom attributes (`data-risk-*`) into risk attribute nodes (such as malicious `href`). These custom attributes support subsequent JS parsing and export of difference reports. They generate overlay-style visual annotations from the custom DOM attributes, achieving visualization of custom attributes through absolute positioning annotation layers without modifying the original DOM structure and styles. This also supports data extraction and report generation. Repeat steps 5.1 to 5.4 above for all child nodes of the current node to ensure that all nodes in the DOM tree that meet the conditions are checked and processed.

[0038] like Figure 6 As shown, step 6 handles conflicts between various tags according to preset priority rules, adjusting tag positions using a position update algorithm. Specifically, it iterates through all generated tags, comparing the DOM node paths and position ranges of the tags to identify overlapping or intersecting tags (such as text error tags and hyperlink risk tags existing simultaneously within the same node). Tag priorities are determined according to preset rules: hyperlink risk tags > text error tags > special character tags > style tags. The tag position adjustment and update method is as follows: retain the original position of high-priority tags; adjust the position of low-priority tags (e.g., shift downwards by 5px or to the right by 10px); if conflicts persist after shifting, further adjustments are made until there is no overlap; then, a conflict handling log is generated (conflicting tag type, original position, adjusted position). Finally, it checks whether the adjusted tags affect the original DOM structure or other functions, ensuring clear tag visualization and no interference with user operations. Finally, the updated and adjusted tags are applied to the original document to generate the final output.

[0039] This embodiment may also include a DOM-based content parsing and positioning system, comprising a document parsing module, a multi-dimensional positioning module, a difference analysis module, a tag generation module, a conflict handling module, and a content reconstruction module. The document parsing module extracts HTML documents to construct a DOM tree and text index, obtaining correct and incorrect text as input, and returns a list of differing character indices based on the longest common subsequence (LCS) of the correct and incorrect text. The multi-dimensional positioning module uses text, structure, and attributes for multi-dimensional positioning, traversing the DOM tree to identify special tags, establishing a special tag range mapping table, selecting a positioning strategy accordingly, and dynamically selecting the positioning strategy based on the special tag range mapping table. The difference analysis module uses an improved LCS algorithm to perform difference analysis by associating DOM node identifiers, identifying the difference between incorrect and correct text. The tag generation module generates appropriate tags based on the positioning and difference results, defining CSS styles for different types of tags. The conflict handling module handles conflicts between various tags according to preset priority rules, adjusting tag positions through a position update algorithm. The content reconstruction module applies the tags to the original document to generate the final output, ensuring that the original DOM tree structure is not destroyed.

[0040] Example 2

[0041] Based on Example 1, the specific process for text error detection and marking is as follows: The input is an HTML document entered by the user in a rich text editor, containing 3 spelling errors (such as "technology" being misspelled as "technical description" and "analysis" being misspelled as "extraction"), and the DOM structure contains 5 levels of nesting (body>div>section>article>p). The processing is as follows: the HTML document is parsed to construct a DOM tree and generate a text index table, recording the node identifier of each character (such as the node identifier of "description" in "technical description" being body>div[1]>section[1]>article[1]>p[2]). The correct text ("technical analysis framework") and the incorrect text ("technical description extraction framework") are received, and the LCS is calculated as "technical framework" using the improved LCS algorithm. After verifying the associated DOM node identifiers, "description" and "extraction" are identified as different characters. According to the index of the different characters, "description" and "extraction" are marked with red wavy lines. After detecting no conflict, the marked position is directly retained. The mark is applied to the original HTML document to generate an HTML string with error marks. The HTML document with error marks is output, and the error content is marked with red wavy lines. Users can visually see the error content and make corrections based on the system's suggestions. Clicking on the error word will scroll directly to the error location and add a background color.

[0042] Example 3

[0043] Based on Example 1 regarding hyperlink detection and tagging, the specific process is as follows: In a web security detection system, it is necessary to detect hyperlinks in an HTML document and tag potential security risks. The input is the HTML document to be detected, which contains multiple hyperlinks. The processing involves the system parsing the HTML document and extracting all hyperlinks. Attribute-based location technology is used to detect the href attribute of the hyperlinks. Detected risky links are tagged. The output is an HTML document with risk tags, where risky links are marked with a specific style. This allows users to visually see potential risky links and take appropriate measures.

[0044] Example 4

[0045] Based on Example 1, which focuses on content detection within complex DOM structures, the specific process involves a content moderation system that needs to detect and mark sensitive content within a complex DOM structure. The input is an HTML document to be reviewed, containing a complex DOM structure and sensitive content. The processing involves the system parsing the HTML document, constructing a DOM tree and a text index. Combining the API detection results (returning "Example of Violating Content" as sensitive content), a text location strategy is selected, and the node position of the sensitive text is determined after matching the text index table. A marking plan is generated to ensure that the original HTML structure is not affected. The exception handling module detects that the node containing the sensitive text also contains extra spaces (false whitespace). Based on priority rules, the sensitive content marker is retained, while the extra spaces (low priority) are removed. Finally, the output is an HTML document with the sensitive content markers, allowing reviewers to visually see the sensitive content and take appropriate action.

[0046] To implement the above embodiments, this application also discloses an electronic device. The electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) or a program loaded from a storage device into a random access memory (RAM). The RAM also stores various programs and data required for the operation of the electronic device. The processing unit, ROM, and RAM are interconnected via a bus. An input / output (I / O) interface is also connected to the bus. Typically, the following devices can be connected to the I / O interface: input devices including, for example, a touchscreen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices including, for example, magnetic tape, hard disk, etc.; and communication devices. The communication device allows the electronic device to communicate wirelessly or wiredly with other devices to exchange data.

[0047] In particular, according to some embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, some embodiments of this disclosure include a computer program product comprising a computer program carried on a computer storage medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device, or installed from a ROM. When the computer program is executed by a processing device, it performs the functions defined above in the methods of some embodiments of this disclosure.

[0048] It should be noted that, in some embodiments of this disclosure, the computer storage medium described above can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can 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 a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.

[0049] In some embodiments of this disclosure, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device. In some embodiments of this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can also be any computer storage medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer storage medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0050] The aforementioned computer storage medium may be included within the aforementioned electronic device, or it may exist independently without being assembled into the electronic device. The aforementioned computer storage medium carries one or more programs that, when executed by the electronic device, enable the electronic device to implement a DOM-based content parsing and positioning method.

[0051] Computer program code for performing operations of some embodiments of this disclosure can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0052] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings.

[0053] All technologies not described in detail in this invention are existing technologies. The above descriptions are merely some preferred embodiments of this disclosure and explanations of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in the embodiments of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalent features without departing from the above-described inventive concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features with similar functions disclosed in the embodiments of this disclosure.

Claims

1. A content parsing and positioning method based on DOM structure, characterized in that, Includes the following steps: Step 1: Extract the HTML document to build the DOM tree and text index, and obtain the correct and incorrect text as input; Step 2: Based on the correct and incorrect texts, identify and return a list of differing character indices using the longest common subsequence. Step 3: Traverse the DOM tree to identify special tags, establish a special tag range mapping table, and select the corresponding positioning strategy to obtain the positioning result; Step 4: Based on the DOM node identifier associated with the list of differing character indices, perform difference analysis to obtain the difference results between the erroneous text and the correct text; Step 5: Traverse all nodes in the DOM tree, analyze the attribute values ​​of each node, and determine and generate tags based on the difference results and location results; Step 6: Process conflicts between multiple markers according to preset priority rules, and adjust the position of the markers using a position update algorithm; Step 7: Apply the updated and adjusted markup to the original document to generate the final output.

2. The content parsing and positioning method based on DOM structure according to claim 1, characterized in that, Step 2 also includes the following steps: Step 2.1: Associate the correct and incorrect text with the unique identifier of their respective DOM nodes; Step 2.2: Calculate the longest common subsequence (LCS) using an improved dynamic programming algorithm to adapt to the nested structure of the HTML document; Step 2.3: Identify the differential characters in the erroneous text based on the longest common subsequence (LCS); Step 2.4: Generate a list of indexes of the differing characters in the error text, and return the list of differing character indexes for subsequent marking.

3. The content parsing and positioning method based on DOM structure according to claim 2, characterized in that, Step 3 also includes the following steps: Step 3.1: Traverse the DOM tree to identify and record the node path range and tag attribute information of special tags, and establish a special tag range mapping table; Step 3.2: Determine the content to be located based on the context of the text content and the special tag range mapping table, and trigger the corresponding text location strategy when it meets the relevance determination rules; Step 3.3: After executing the text positioning strategy to obtain the positioning results, retain the valid results through double filtering and finally output the positioning result list.

4. The content parsing and positioning method based on DOM structure according to claim 3, characterized in that, Step 4 also includes the following steps: Step 4.1: Extract the text content of the nodes in the DOM tree and split it into a "character-node weight" binary array, and identify the type of the characters in each binary array; Step 4.2: Bind the "character-node weight" binary array to the DOM node identifier, and use the LCS algorithm with weight factor optimization to match and obtain the difference characters; Step 4.3: Perform special processing on the different types of the characters, and recombine the processed characters into complete text.

5. The content parsing and positioning method based on DOM structure according to claim 4, characterized in that, Step 5 also includes the following steps: Step 5.1: Use depth-first and breadth-first traversal algorithms to traverse all nodes of the DOM tree and analyze the attribute list of each node one by one; Step 5.2: Extract the attribute value of each node, remove special characters from the attribute value and convert it into a key-value pair; Step 5.3: Determine whether the attribute value meets the marking conditions, and inject a custom DOM attribute into the element containing the attribute that meets the conditions; Step 5.4: Generate visual annotations for the custom DOM attributes using an absolute positioning annotation layer; Step 5.5: Repeat steps 5.1 to 5.4 to ensure that all nodes in the DOM tree that meet the criteria are checked and processed.

6. The content parsing and positioning method based on DOM structure according to claim 5, characterized in that: In step 2.2, the improved dynamic programming algorithm is used to calculate the longest common subsequence (LCS). First, a two-dimensional dynamic programming (DP) table is constructed. The character sequences of the error text and the correct text are traversed to fill the two-dimensional DP table. When the i-th character of the error text is the same as the j-th character of the correct text and the DOM node identifiers of the two satisfy the "parent-child node" or "sibling node" relationship, the table is filled. Then, starting from the bottom right cell of the two-dimensional DP table, the table is backtracked upwards and then to the left to complete the extraction of the longest common subsequence length.

7. The content parsing and positioning method based on DOM structure according to claim 5, characterized in that: In steps 3.2 and 3.3, the text positioning strategy is selected and executed in conjunction with the special label range mapping table. Specifically, For ordinary text content, text sequence combined with node fingerprinting is used for localization. The process involves matching the text to be located with the text content in the text index table, and combining the difference results to determine the specific node position of the text in the DOM tree. For attribute content, attribute value hashing combined with tag functionality is used for location. The process involves traversing the nodes of the target tag type in the DOM tree, extracting attribute values ​​and matching them with the attribute content to be located to determine the node position of the target attribute. For special tag content, text within dynamic script nodes is not positioned, while static script nodes only have their src attribute checked. Content within iframe tags triggers cross-domain detection, allowing penetration positioning; otherwise, it is marked as cross-domain and cannot be positioned.

8. The content parsing and positioning method based on DOM structure according to claim 5, characterized in that, In step 4.3, special processing is performed for each type of difference, including spelling errors, extra characters, and missing characters, specifically: For ordinary characters, if they are different characters, apply a red wavy underline style directly; if they are not different characters, keep the original style. For space characters, if they are different characters, add a yellow background color mark and a transparent label; if they are not different characters, keep the original style. Tab characters: If they are different characters, they are replaced with blue special symbols and marked with a blue border; if they are not different characters, they are marked with gray and retain their original function.

9. The content parsing and positioning method based on DOM structure according to claim 5, characterized in that: In step 6, conflicts between various tags are handled according to preset priority rules, and the tag positions are adjusted by a position update algorithm. The priority levels from high to low are hyperlink risk tags, text error tags, special character tags, and style tags. When updating the position, the original position of the high-priority marker is retained, the position of the low-priority marker is adjusted, and if there is still a conflict after the offset, it is adjusted until there is no overlap. Finally, a conflict handling log is generated.

10. A content parsing and positioning system based on DOM structure, characterized in that, include: The document parsing module is used to extract HTML documents to build a DOM tree and text index, obtain correct and incorrect text as input, and identify and return a list of different character indexes based on the longest common subsequence of the correct and incorrect text. The multi-dimensional positioning module is used to traverse the DOM tree to identify special tags and establish a special tag range mapping table. Based on multi-dimensional positioning of text, structure and attributes, it dynamically selects the text positioning strategy in combination with the special tag range mapping table and obtains the positioning result by selecting the corresponding text positioning strategy. The difference analysis module is used to associate the difference character index list with DOM node identifiers to perform difference analysis and identify the difference results between the erroneous text and the correct text. The tag generation module is used to traverse all nodes in the DOM tree, analyze the attribute values ​​of each node, and determine and generate tags based on the difference results and positioning results; The conflict handling module is used to handle conflicts between multiple tags according to preset priority rules and adjust the tag positions through a position update algorithm. The content restructuring module is used to apply the updated and adjusted markup to the original document to generate the final output.