Word document editable region positioning method and device based on XML (Extensible Markup Language)
By parsing Word documents to generate a character map dictionary and combining it with a dynamic verification mechanism, the problem of insufficient recognition range and accuracy of editable areas in Word documents is solved, achieving efficient and accurate plain text area positioning, which is suitable for contract review systems and office software platforms.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-13
- Publication Date
- 2026-04-10
AI Technical Summary
Existing technologies for recognizing editable areas in Word documents suffer from limitations in recognition range due to the native API or insufficient XML parsing accuracy, making them ineffective in recognizing plain text areas and inefficient.
By decompressing Word documents to generate XML files, recognizing permission tag nodes and structural tag nodes, constructing a character map dictionary, and combining it with a dynamic verification mechanism, accurate identification and efficient positioning of editable areas can be achieved.
It significantly improves the accuracy and efficiency of editable area recognition, increasing the positioning accuracy to 98% when processing complex documents and reducing the processing time to less than 1 minute, making it suitable for various Word document scenarios.
Smart Images

Figure CN121835609A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer document information processing, and particularly relates to a Word document editable area positioning method and device based on XML. BACKGROUND
[0002] With the development of office automation and document intelligent processing technology, the editable area recognition and permission control of Word documents become key links in enterprise document management, contract systems and bid preparation systems. The existing technology mainly adopts two schemes to realize the recognition and positioning of the editable area of the docx document.
[0003] (1) Native API scheme
[0004] The scheme relies on the native Word object model (such as the ContentControl interface) to identify the control class editable area in the document. This method can directly access the structured controls (such as drop-down boxes, rich text boxes, etc.) through the API, and has certain convenience in visual operation and control management. However, this scheme has significant limitations: its recognition ability is limited to control objects, and it cannot process editable areas generated by <w:permstart>With <w:permend>The label marks a plain text editable area. In practical applications, more than 70% of the editable areas in enterprise contracts, bidding documents and other documents are in the form of plain text, such as the name of Party A, the amount of filling column, etc., which leads to the fact that the method cannot cover most of the editing scenarios and becomes a blind area of automatic processing.
[0005] (2) XML parsing scheme
[0006] Another method is to directly decompress the docx file, parse the underlying document.xml file, and identify the permission tag <w:permstart>With <w:permend>to locate editable regions. This method breaks the limitation of application layer API and can directly manipulate the underlying structure of the document to achieve more flexible identification of permission regions. However, since a Word document usually contains various non-text tags such as tables, line breaks, pictures, etc., in order to accurately calculate the start and end positions of the editable region, the length of the placeholder of each type of tag in the character stream must be considered. Since different tag types (such as <w:br / > 、 <w:tbl>The character conversion rules are not unified, and the existing XML parsing scheme is prone to deviation in character position calculation, with a positioning error rate of 30%-40%, which seriously affects the accuracy and reliability of editable area identification.
[0007] In addition, the dynamic traversal verification method needs to try character by character throughout the document, and it takes more than 10 minutes to process a 100-page document.
[0008] In summary, the existing technology in the identification of editable areas of docx documents is either subject to the functional boundaries of the native interface or has a large error in XML parsing accuracy, and still cannot balance the identification range and positioning accuracy, so an improved method is needed that can cover both pure text areas and ensure high-precision positioning.
[0009] This section is intended to provide background or context for embodiments of the invention recited in the claims. The description herein does not admit to be prior art because it is included in this section. SUMMARY
[0010] To solve the problems in the prior art, the embodiments of the present application provide a Word document editable area positioning method and device based on XML, which can solve the problem of how to break through the limitations of the native API in complex Word document structure and realize accurate identification and efficient positioning of non-control class pure text editable areas.
[0011] In one aspect of the present application, a Word document editable area positioning method based on XML is provided, which comprises:
[0012] Decompressing the obtained Word document to obtain a corresponding XML file;
[0013] Traversing the XML file to identify and locate the permission tag node and the structural tag node to obtain a tag node list;
[0014] Generating a character map dictionary according to the tag node list and a pre-constructed document tag placeholder rule library;
[0015] Based on the character map dictionary, performing region jumping dynamic verification to obtain editable area position information that passes the verification.
[0016] Further, the generating of the character map dictionary according to the tag node list and the pre-constructed document tag placeholder rule library comprises:
[0017] Determining the character length of each tag area according to the tag node list and the pre-constructed document tag placeholder rule library;
[0018] Converting the character length into character index coordinates;
[0019] generate the character map dictionary based on the character index coordinates.
[0020] Further, the determining of the character length of each label region according to the label node list and the pre-constructed document label placeholder rule library comprises:
[0021] if the label type of a first label region in the label node list is a text label, determining the character length of the first label region as the actual character length in the first label region;
[0022] if the label type of a second label region in the label node list is a line break label, determining the character length of the second label region as 1 character;
[0023] if the label type of a third label region in the label node list is a table cell label, determining the character length of the third label region as the accumulation of the text length in the cell;
[0024] if the label type of a fourth label region in the label node list is a picture or object label, determining the character length of the fourth label region as 0 characters.
[0025] Further, the region jumping dynamic verification based on the character map dictionary comprises:
[0026] initializing a document position pointer;
[0027] when the document position pointer is located in an editable region in the character map dictionary, calling an API to verify the first character of the editable region, if the verification is passed, marking the editable region and moving the document position pointer to the end of the editable region;
[0028] when the document position pointer is located in an interval region in the character map dictionary, directly moving the document position pointer to the end of the interval region;
[0029] when the document position pointer is located in an un-precomputed region in the character map dictionary, calling an API to perform character-by-character verification on the un-precomputed region.
[0030] Further, the calling of the API to verify the target character interval comprises:
[0031] calling a Range interface to perform an operation of setting text or detecting writing permission on the target character interval, to determine whether the target character interval has an editable attribute;
[0032] when the operation is successfully executed, generating editable region marking information.
[0033] Further, the character map dictionary is a key-value pair structure, the key is a region identifier, and the value is a three-tuple including a region type, a start index, and an end index; the region type includes an editable region and an interval region.
[0034] In another aspect of the present application, an XML-based Word document editable region positioning device is provided, which comprises:
[0035] An XML file acquisition unit is configured to decompress an acquired Word document to obtain a corresponding XML file;
[0036] A tag node list generation unit is configured to traverse the XML file, identify and locate permission tag nodes and structural tag nodes, and obtain a tag node list;
[0037] A character map dictionary generation unit is configured to generate a character map dictionary based on the tag node list and a pre-constructed document tag placeholder rule library;
[0038] An editable region determination unit is configured to perform region jump dynamic verification based on the character map dictionary to obtain editable region position information that passes the verification.
[0039] Further, the character map dictionary generation unit comprises:
[0040] A character length determination module is configured to determine the character length of each tag region based on the tag node list and the pre-constructed document tag placeholder rule library;
[0041] A character index coordinate generation module is configured to convert the character length into a character index coordinate;
[0042] A character map dictionary generation module is configured to generate the character map dictionary based on the character index coordinate.
[0043] Further, the character length determination module comprises:
[0044] A first character length determination submodule is configured to, if the tag type of a first tag region in the tag node list is a text tag, determine the character length of the first tag region as the actual character length in the first tag region;
[0045] A second character length determination submodule is configured to, if the tag type of a second tag region in the tag node list is a line break tag, determine the character length of the second tag region as 1 character;
[0046] A third character length determination submodule is configured to, if the tag type of a third tag region in the tag node list is a table cell tag, determine the character length of the third tag region as the accumulation of the text length in the cell.
[0047] A fourth character length determination sub-module is configured to determine that the character length of the fourth label region is 0 characters if the label type of the fourth label region in the label node list is a picture or an object label.
[0048] Further, the editable region determination unit comprises:
[0049] A pointer initialization module is configured to initialize a document position pointer;
[0050] An editable region verification module is configured to, when the document position pointer is located in an editable region in the character map dictionary, call an API to verify the first character of the editable region, and if the verification is passed, mark the editable region and move the document position pointer to the end of the editable region.
[0051] An interval region verification module is configured to, when the document position pointer is located in an interval region in the character map dictionary, directly move the document position pointer to the end of the interval region.
[0052] An un-precomputed region verification module is configured to, when the document position pointer is located in an un-precomputed region in the character map dictionary, call an API to perform character-by-character verification on the un-precomputed region.
[0053] Further, the editable region determination unit further comprises:
[0054] A verification module is configured to call a Range interface to perform an operation of setting text or detecting writing permission on a target character interval, so as to determine whether the target character interval has an editable attribute.
[0055] A marking module is configured to, when the operation is performed successfully, generate editable region marking information.
[0056] Further, the character map dictionary is in a key-value pair structure, the key is a region identifier, and the value is a three-tuple comprising a region type, a start index and an end index; the region type comprises an editable region and an interval region.
[0057] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a computer device is also provided, which comprises a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the above-mentioned XML-based Word document editable region positioning method when executing the computer program.
[0058] In order to achieve the above object, according to another aspect of the present application, there is further provided a computer readable storage medium having stored thereon computer programs / instructions which, when executed by a processor, implement the steps of the above XML-based Word document editable area positioning method.
[0059] In order to achieve the above object, according to another aspect of the present application, there is further provided a computer program product comprising computer programs / instructions which, when executed by a processor, implement the steps of the above XML-based Word document editable area positioning method.
[0060] The present application has the following remarkable beneficial effects compared with the prior art by implementing the above technical solutions of XML structure analysis, character mapping pre-computation and dynamic verification combination:
[0061] 1. Breakthrough improvement in editable area identification efficiency
[0062] The present application introduces the "XML pre-computation generated character map" mechanism before dynamic verification, and combines the "area jump executor" to execute the verification process, greatly reducing the repeated calls to the Word API. By pre-dividing the editable area and the interval area, the non-editable area is directly skipped in the verification process, and only the first character of the editable area is verified for writability. The test results show that the average time for processing 100 pages of complex documents is shortened from more than 10 minutes in the prior art to less than 1 minute, with an overall efficiency improvement of more than 90%, fundamentally breaking through the performance bottleneck caused by the O(n) complexity of the traditional dynamic traversal method.
[0063] 2. Significant improvement in positioning accuracy under complex documents
[0064] By constructing the "document tag placeholder rule library", the present application realizes character conversion and mapping of multiple types of XML tags such as text, table, line break, etc. in the pre-computation stage, so that the generated character map is highly consistent with the underlying character structure of Word. Compared with the prior art which cannot uniformly handle different structural tag lengths, the positioning accuracy of the present scheme is improved to more than 98% in documents containing complex elements (such as tables, line breaks, pictures), effectively eliminating the deviation caused by non-uniform tag placeholders, and ensuring the accuracy and stability of the area positioning results.
[0065] 3. The range of recognizable permission area types is expanded, and the universality of the scheme is enhanced
[0066] The present application directly analyzes the internal XML structure of the docx file, and no longer relies on the control collection in the Word object model (Object Model), so that all <w:permstart> / <w:permend>The label marks a pure text editable area. The scheme realizes unified identification of control class and non-control class areas, fills the functional gap of the prior art in pure text permission identification, has stronger universality and adaptability, and is suitable for various Word document scenes.
[0067] 4. The optimal balance between processing efficiency and system resource occupation is realized
[0068] The application significantly reduces the API call frequency in the jump verification process, thereby reducing the interaction pressure and memory occupation rate of the Word COM component. When processing a super-large volume of documents, the system runs smoothly without thread blocking or application unresponsive phenomenon, ensuring the stability and commercial availability of the scheme. Therefore, the application can be widely integrated in contract review systems, document automation tools and office software platforms in practical applications, and provides efficient and reliable technical support for rapid permission identification and editable area positioning of mass documents. BRIEF DESCRIPTION OF DRAWINGS
[0069] In order to more clearly illustrate the technical solutions in the embodiments of the application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the application, and for those skilled in the art, other drawings can also be obtained without creative labor. In the drawings:
[0070] Figure 1 is the first flowchart of the XML-based Word document editable area positioning method of the embodiment of the application;
[0071] Figure 2 is the second flowchart of the XML-based Word document editable area positioning method of the embodiment of the application;
[0072] Figure 3 is the third flowchart of the XML-based Word document editable area positioning method of the embodiment of the application;
[0073] Figure 4 is the fourth flowchart of the XML-based Word document editable area positioning method of the embodiment of the application;
[0074] Figure 5 is the fifth flowchart of the XML-based Word document editable area positioning method of the embodiment of the application;
[0075] Figure 6 is the first structural block diagram of the XML-based Word document editable area positioning device of the embodiment of the application;
[0076] Figure 7 is a second structural block diagram of an XML-based Word document editable area positioning device according to an embodiment of the present application;
[0077] Figure 8 is a third structural block diagram of an XML-based Word document editable area positioning device according to an embodiment of the present application;
[0078] Figure 9 is a fourth structural block diagram of an XML-based Word document editable area positioning device according to an embodiment of the present application;
[0079] Figure 10 is a fifth structural block diagram of an XML-based Word document editable area positioning device according to an embodiment of the present application;
[0080] Figure 11 is a structural diagram of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION
[0081] In order to make the personnel in the art better understand the present application scheme, the technical scheme in the embodiments of the present application will be described clearly and completely below in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor should belong to the protection scope of the present application.
[0082] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can adopt a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can adopt a computer program product in the form of being implemented on one or more computer usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer usable program codes.
[0083] It should be noted that the terms "include" and "have" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover the non-exclusive inclusion, for example, a process, method, system, product or device containing a series of steps or units does not have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0084] It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict. The present application will be described in detail below with reference to the drawings and in combination with the embodiments.
[0085] The method realizes high-precision positioning of editable regions under a complex document structure by decompressing and analyzing a Word document (.docx format), node identification, character mapping and dynamic verification, thereby overcoming the problems of recognition blind spots and low efficiency caused by relying on native API or pure XML analysis in the prior art.
[0086] The following describes the specific implementation process of the XML-based Word document editable region positioning method provided by the embodiments of the application, taking a server as an execution subject.
[0087] Figure 1 is the first flowchart of the XML-based Word document editable region positioning method of the embodiments of the application, as shown in Figure 1 The XML-based Word document editable region positioning method provided by the embodiments of the application includes the following steps.
[0088] S101: Decompressing a obtained Word document to obtain a corresponding XML file;
[0089] S102: Traversing the XML file, identifying and positioning permission tag nodes and structural tag nodes to obtain a tag node list;
[0090] S103: Generating a character map dictionary according to the tag node list and a pre-constructed document tag placeholder rule library;
[0091] S104: Based on the character map dictionary, performing region jump dynamic verification to obtain editable region position information that passes the verification.
[0092] As can be seen from the flowchart Figure 1 , the application provides an XML-based Word document editable region positioning method, which includes the following steps: decompressing a obtained Word document to obtain a corresponding XML file; traversing the XML file, identifying and positioning permission tag nodes and structural tag nodes to obtain a tag node list; generating a character map dictionary according to the tag node list and a pre-constructed document tag placeholder rule library; and based on the character map dictionary, performing region jump dynamic verification to obtain editable region position information that passes the verification. The method realizes fast and accurate positioning of editable regions in complex documents, and significantly improves the accuracy and processing efficiency of editable region identification.
[0093] The following describes each step in detail.
[0094] S101: Decompressing a obtained Word document to obtain a corresponding XML file;
[0095] Specifically, first, the server decompresses the obtained Word document (.docx format). Since the.docx file is essentially a compressed package containing multiple XML files, after decompression, a document structure directory can be obtained, wherein the "document.xml" file contains all the contents of the document body and permission tag information. In this step, the server reads and loads the document.xml file to provide a data source for subsequent tag identification and structure analysis.
[0096] S102: Traverse the XML file, identify and locate the permission tag node and the structural tag node, and obtain a tag node list;
[0097] Specifically, the server traverses the XML file through the built-in XML parsing engine to identify the permission tag node (for example <w:permstart> 、 <w:permend>) and structural tag nodes (e.g., text tags <w:t>, table label <w:tbl>, line break tags <w:br / > and form a list of tag nodes.
[0098] Each node records its type, hierarchical position and index order in the XML document. The output of this step is a list of tag node objects, which describe the logical structure and semantic properties of all content units in the document.
[0099] S103: generating a character map dictionary according to the list of tag nodes and a pre-constructed document tag placeholder rule library;
[0100] Specifically, after obtaining the list of tag nodes, the server calculates the character length of each tag node according to the pre-constructed document tag placeholder rule library.
[0101] Through the above calculation, the server can map the logical hierarchy of the XML structure into a linear character sequence. Subsequently, the server generates character index coordinates according to the character length of each tag and constructs a character map dictionary (char_map). This dictionary completely describes the distribution of editable and interval areas in the document at the character level, providing a positioning basis for subsequent dynamic verification.
[0102] In an embodiment, when encountering <w:permstart>The tag indicates the beginning of an editable region. When encountered <w:permend>The tag end indicates the end of the editable area and the start of the interval area.
[0103] In one embodiment, the document tag placeholder rule library defines the character conversion mode corresponding to different types of tags, as shown in Table 1:
[0104] Table 1
[0105]
[0106] That is, the text tag is counted by the actual number of characters; the line break tag is converted to 1 character; the character length of the table cell tag is the cumulative length of the text in each cell; the picture or object tag is converted to 0 characters.
[0107] In one embodiment, on the basis of Table 1, the table-related tags also need to calculate the placeholder, and the specific rules are shown in Table 2:
[0108] Table 2
[0109]
[0110] In one embodiment, the table tag is identified <w:tbl>After, all the cell tags in it are tagged <w:tc>accumulation of text in the middle, in addition to tab labels <w:tab>, cell tag <w:tc>and table row labels <w:tl>Also count 1 character.
[0111] Figure 2 is a second flowchart of the XML-based Word document editable area positioning method of the embodiment of the application, as shown in Figure 2 In an embodiment of the application, S103 comprises:
[0112] S201: determining the character length of each label area according to the label node list and the pre-constructed document label placeholder rule library;
[0113] Specifically, after completing the node traversal and identification of the XML file, the server obtains a node list containing multiple label nodes. Each node contains its type information, hierarchical relationship, and node order number in the document structure, and other basic attributes. The node list constitutes the input data set for subsequent character mapping generation.
[0114] The server parses each label node in the node list one by one according to the pre-established document label placeholder rule library. The rule library stores the label type and its corresponding character placeholder rule in the form of key-value pair, which is used to guide the mapping relationship between the logical structure and the character sequence.
[0115] When performing the calculation, the server determines the character length information of each label node according to the arrangement order of the node in the XML structure, and accumulates to form a linear character coordinate sequence of the document.
[0116] In this way, the hierarchical XML structure of the document is converted into a continuous character index space, so that each permission label and its interval position has clear start and end coordinates in the character dimension.
[0117] Figure 3 is a third flowchart of the XML-based Word document editable area positioning method of the embodiment of the application, as shown in Figure 3 In an embodiment of the application, S201 comprises:
[0118] S301: if the label type of the first label area in the label node list is a text label, determining the character length of the first label area as the actual character length in the first label area;
[0119] Specifically, to solve the problem of inconsistent character counting caused by multiple label types in the XML structure of the Word document, the application realizes accurate character length calculation of text, line break, table, picture and other structure nodes through the combination of label type identification and differentiated conversion rules, thereby constructing a character stream model consistent with the rendering logic of the Word bottom layer.
[0120] The server first judges the label type of each node when traversing the label node list, and calls the corresponding conversion rule function (placeholder rule) according to the type to obtain the character length value corresponding to the node.
[0121] When it is detected that the node type is a text label (such as <w:t>), the server extracts the actual text content inside the tag and takes the number of characters as the character length value. For example, for the tag <w:t>Party A< / w:t> , the server calculates its length as 2 characters. This approach ensures that the character count of the text type node is fully consistent with the actual content of the document, providing an accurate basis for subsequent character index mapping.
[0122] S302: If the tag type of the second tag region in the tag node list is a line break tag, determine the character length of the second tag region as 1 character;
[0123] Specifically, when detecting that the node type is a line break tag (such as <w:br / > ), the server regards the node as a logical separator occupying a fixed character width. To maintain the correspondence with the character position in the Word editor, the server uniformly converts the line break to 1 character length. This processing approach ensures that in complex layout scenarios such as paragraph line breaks and table line breaks, the character index will not be misaligned.
[0124] S303: If the tag type of the third tag region in the tag node list is a table cell tag, determine the character length of the third tag region as the cumulative length of the text within the cell;
[0125] Specifically, when detecting that the node type is a table cell tag (such as <w:tc>or <w:tbl>When the node type is a text node, the server calculates the character length of the text node by counting the number of characters in the text content of the text node. When the node type is a table cell (i.e., an internal node), the server traverses all the text nodes within the cell and accumulates the sum of the lengths of the internal text content as the total character length of the cell. For a table region containing multiple cells, the server accumulates the total number of characters of each cell in turn to obtain the character length of the entire table region.
[0126] By this hierarchical accumulation strategy, the server is able to correctly simulate the linear character unfolding effect of the table structure in the Word document, thereby making the positioning of the editable region more accurate in the table environment.
[0127] S304: If the tag type of the fourth tag region in the tag node list is a picture or an object tag, it is determined that the character length of the fourth tag region is 0 characters.
[0128] Specifically, when it is detected that the node type is a picture or an embedded object tag (such as <w:drawing> 、 <w:object>When the character length of a node is 0, the server determines that the node does not constitute text content and does not participate in character stream calculation, and thus sets the character length of the node to 0. This processing manner can effectively avoid interference of non-text elements in character index calculation, and maintain continuity and stability of editable area positioning.
[0129] After the above calculation is performed, the server writes the character length value corresponding to each label node into a temporary mapping table, and uses the value in subsequent steps to generate character index coordinates and a character map dictionary.
[0130] Through the above differentiated conversion rules, the application can accurately reflect the character distribution characteristics of the Word underlying layer while maintaining the consistency of the document structure, so that the character position calculation error in a complex document environment is controlled within a negligible range.
[0131] S202: converting the character length into character index coordinates;
[0132] Specifically, the server converts the character length information obtained through the above calculation into corresponding character index coordinates. For each label node, the server determines the start position index and the end position index, and binds the index interval to the label type to which the node belongs. This process forms a regionalized character interval description, which reflects the layout relationship of the XML document at the character level.
[0133] S203: generating the character map dictionary based on the character index coordinates.
[0134] Specifically, the server generates a character map dictionary (Character Map Dictionary) based on the index information of all nodes. The dictionary adopts a key-value pair structure, in which the key (Key) is a region identifier (for example, region_1, gap_1, etc.), and the value (Value) is a corresponding region attribute set, including region type (editable or gap), start index, and end index.
[0135] The generated character map dictionary completely describes the spatial distribution of editable regions and non-editable regions in the document in the character dimension, providing accurate input data support for the "region jumping logic" in the subsequent dynamic verification stage.
[0136] Through the above steps, the server realizes the mapping process from the document structure layer to the character coordinate layer, ensuring that each label node has a traceable physical position in the character sequence. Compared with the prior art, the method in the embodiment not only improves the accuracy of character index calculation, but also greatly simplifies the subsequent verification logic through the structured mapping table, laying a data foundation for efficiently identifying editable regions in Word documents.
[0137] S104: Based on the character map dictionary, region jump dynamic verification is performed to obtain editable region position information passed by verification.
[0138] Specifically, after the character map generation is completed, the server enters a dynamic verification phase. First, the document position pointer current_pos is initialized to 0, and region jump logic is performed according to the character map dictionary during traversal. Through this jump verification mechanism, the server avoids API calls for each character one by one, greatly improving the overall processing efficiency, while ensuring the accuracy of the positioning result.
[0139] After the verification of all regions is completed, the server outputs the verified region index range in the form of a data structure. This result can be used to: provide editable region coordinate information to the upper layer application interface to realize automatic marking; generate an identification file or directly highlight the editable region in the Word document.
[0140] The final output of the editable region position information can be called by a document automation system, a contract review system, etc., to realize automatic recognition and control of the editable region.
[0141] Figure 4 is the fourth flowchart of the XML-based Word document editable region positioning method of the embodiment of the application, as shown in Figure 4 S104 includes:
[0142] S401: The document position pointer is initialized;
[0143] Specifically, the server uses the aforementioned generated character map dictionary (Character Map Dictionary) as input data, and through pointer control and condition judgment mechanism, realizes the rapid identification and verification of the editable region in the Word document, thereby significantly improving the processing efficiency while ensuring the identification accuracy.
[0144] The server first initializes the document position pointer current_pos to 0, which is used to represent the linear position index of the current character in the document. This pointer serves as a traversal control variable throughout the verification process and is dynamically pushed forward according to the verification result. In the initialization stage, the server also reads the overall structure of the character map dictionary, extracts the start and end indexes of all editable regions and interval regions, and provides a basic reference for subsequent judgment.
[0145] The server first queries the character map dictionary according to the value of current_pos in each verification cycle to determine whether the current position falls within a certain region interval. If the current_pos is between the start and end indexes of a certain region, the server determines whether the current region is an "editable region", an "interval region" or an "un-precomputed region" according to the "type" field of the region. This determination is achieved through index lookup of the dictionary structure, with extremely low time complexity, providing real-time decision basis for subsequent jump and verification operations.
[0146] S402: When the document position pointer is in an editable region in the character map dictionary, call the API to verify the first character of the editable region. If the verification is passed, mark the editable region and move the document position pointer to the end of the editable region.
[0147] Specifically, when the region type determination result is an editable region, the server calls the API interface to perform a write verification operation on the first character of the region to determine whether the region has an editable attribute.
[0148] Verification is usually completed by calling the Range interface in the Word Object Model, such as by Range.SetText() or a permission test function to attempt to write a test character at the target position.
[0149] If the verification is successful, the server considers the entire region to be editable and records the identification information and index range of the region internally. After completing the verification, the server immediately updates the current_pos to the end index of the region plus 1, implementing region-level jumping, thereby avoiding repeated verification of each character in the region. This "jump verification" mechanism greatly reduces the number of API calls, making the processing efficiency several to tens of times higher than the traditional character-by-character traversal method.
[0150] S403: When the document position pointer is in an interval region in the character map dictionary, directly move the document position pointer to the end of the interval region.
[0151] Specifically, when the current_pos is in an interval region in the character map dictionary, the server does not need to perform any verification operation because such regions are identified as non-editable or non-permission areas in the document structure. The server directly moves the current_pos to the end index of the interval region plus 1 position and continues to execute the next round of judgment. This strategy effectively avoids unnecessary traversal and API calls in non-essential regions, further improving overall running efficiency.
[0152] S404: When the document position pointer is in an unprecomputed region in the character map dictionary, invoke the API to perform character-by-character validation on the unprecomputed region.
[0153] Specifically, if current_pos does not belong to any region in the character map dictionary, i.e., belongs to an unprecomputed region (e.g., a node that is not mapped due to special nesting or parsing exceptions), the server performs character-by-character validation in compatibility mode.
[0154] In this mode, the server invokes the API for write or permission detection on the current position single character, and decides whether to mark the character as editable according to the return result. Although this mode is less efficient, it ensures the integrity and robustness of document processing, avoiding missing edge regions or abnormal labels causing positioning loss.
[0155] After the character index of the entire document is traversed, the server aggregates all validated editable region index ranges into a result set to form the final editable region position information. This result can be used as input for subsequent marking, exporting, or permission control modules to achieve automated recognition and visual output of the editable region of the document.
[0156] In an embodiment, the implementation logic of dynamic jump validation is as follows:
[0157] {
[0158] current_pos = 0 # Document position pointer initialization
[0159] while current_pos < total_doc_length:
[0160] if region := find_region(char_map, current_pos): # Check if the current position is in a precomputed region
[0161] if region.type == "editable":
[0162] range = doc.Range(current_pos, current_pos+1) # Only select the first character
[0163] if try_modify(range): # API call validation
[0164] mark_editable_region(region.start, region.end) # Mark the entire region
[0165] current_pos = region.end + 1 # Jump to the end of the region
[0166] elif region.type == "gap":
[0167] current_pos = region.end + 1 # Skip the interval region directly
[0168] else:
[0169] # Uncalculated areas (compatibility mode)
[0170] range = doc.Range(current_pos, current_pos+1)
[0171] if try_modify(range):
[0172] mark_editable_region(current_pos, current_pos)
[0173] current_pos += 1 # Move character by character
[0174] }
[0175] Through the above steps, this invention implements a dynamic verification mechanism based on region-level logic. Compared with the character-by-character traversal method in the prior art, this embodiment can significantly reduce redundant verification operations and exhibit higher operating efficiency and server stability when processing large-scale complex Word documents. At the same time, this skip-based verification mode still maintains the ability to handle special regions, ensuring the comprehensiveness and accuracy of editable region recognition.
[0176] Figure 5 This is the fifth flowchart of the XML-based Word document editable area positioning method according to an embodiment of the present invention, as shown below. Figure 5 As shown, in one embodiment of the present invention, calling the API to verify the target character range includes:
[0177] S501: Call the Range interface to perform operations such as setting text or checking write permissions on the target character range, in order to determine whether the target character range has editable attributes;
[0178] Specifically, when the dynamic verification engine of the server detects that the current document position pointer is in a certain editable region or an undetermined region, the server calls the Range interface provided by the Word application, constructs a Range object representing the target character range, such as Range (current_pos, current_pos+1).
[0179] Subsequently, the server performs a "set text" or "detect write permission" operation through the API:
[0180] The set text operation (SetText): The server attempts to write a test character or identifier to the target character interval to verify whether the interval allows content modification;
[0181] Write permission detection operation: The server calls the permission judgment function (such as CanEdit, Editable, or the exception capture mechanism after attempting to write) of the Word API to determine whether the Range object has editable permissions.
[0182] Through any of the above methods, the server can determine the writability of the character interval according to the return result or exception feedback. If the operation is successful and no permission error is triggered, it indicates that the region is in an editable state in the document permission control.
[0183] S502: When the operation is successfully executed, generate editable region marker information.
[0184] Specifically, when the verification result indicates that the target character interval can be edited, the server immediately generates corresponding editable region marker information. The marker information can take two forms:
[0185] Data layer identification: In the internal data structure of the server, the start and end indices of the region and the verification result are recorded as a region identification data, such as "region_1": {"type": "editable", "start": 0, "end":105};
[0186] Document layer identification: The server can call the Word API to add visual identification to the corresponding region, such as setting the background color, inserting a comment, or adding a custom label, to facilitate subsequent display or export.
[0187] The marker information can be output to the upper interface or persistent storage in subsequent steps to generate a complete set of editable region position information.
[0188] After the single region verification is completed, the server feeds back the verification status to the dynamic verification engine to update the moving logic of the current position pointer current_pos. If the verification is successful, the region jump to the end of the region is performed; if the verification fails, the verification cycle of the next character or region is continued.
[0189] The logical cycle of "verification-feedback-jump" ensures that the entire document is verified while maintaining processing efficiency and result consistency.
[0190] Through the above steps, the present application establishes a direct mapping relationship from the character interval to the permission result at the API call level, realizing the automatic verification of editable region identification. Compared with the prior art, the present embodiment avoids the performance bottleneck caused by character-by-character API calls, and realizes regional verification through Range object level operation, greatly improving the verification accuracy and execution speed.
[0191] In an embodiment of the present application, the character map dictionary is a key-value pair structure, the key is a region identifier, and the value is a triple including a region type, a start index and an end index; the region type includes an editable region and a gap region.
[0192] Specifically, the character map dictionary (Character Map Dictionary) is a key data structure established by the present application between the Word document structure information and the character level verification logic. The dictionary is used to record the mapping relationship of each label node in the character dimension in the document, and stores the type attribute and index range of each region in the form of a unified key-value pair, providing accurate and retrievable data support for subsequent dynamic verification.
[0193] The character map dictionary is generated by the aforementioned label parsing and character length calculation, adopts a key-value pair (Key-Value) structure, and its design logic is as follows:
[0194] The key (Key) of the character map dictionary is a region identifier, which is used to uniquely mark each continuous character interval in the document. The region identifier can be automatically generated according to the order of region appearance, such as "region_1", "gap_1" and "region_2", etc., corresponding to editable regions and gap regions respectively.
[0195] The value (Value) part is a region attribute set, usually represented in the form of a triple, including:
[0196] Region type (type): used to distinguish the nature of the region, which can be "editable" (editable region) or "gap" (gap region);
[0197] Start index (start): refers to the starting position of the region in the document character sequence;
[0198] end: indicates the end position of the region in the document character sequence.
[0199] In an embodiment, the character map dictionary structure is as follows:
[0200] char_map = {
[0201] "region_1": {"type": "editable", "start": 0, "end": 105}, # editable region 1
[0202] "gap_1": {"type": "gap", "start": 106, "end": 245}, # gap region 1
[0203] "region_2": {"type": "editable", "start": 246, "end": 328} # editable region 2
[0204] }
[0205] In an embodiment, the above method is implemented by an XML parsing engine and a dynamic verification engine in the server, and the specific functions are shown in Table 3:
[0206] Table 3
[0207]
[0208] The application provides a Word document editable region positioning method based on XML. The method decompresses a obtained Word document to obtain a corresponding XML file. The XML file is traversed to identify and position permission tag nodes and structural tag nodes to obtain a tag node list. A character map dictionary is generated according to the tag node list and a pre-constructed document tag placeholder rule library. Region jump dynamic verification is performed based on the character map dictionary to obtain editable region position information that passes the verification, thereby realizing rapid and accurate positioning of editable regions in a complex document and significantly improving the accuracy and processing efficiency of editable region identification.
[0209] It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a group of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0210] Based on the same inventive concept, the embodiment of the present application further provides an XML-based Word document editable area positioning device, which can be used to realize the XML-based Word document editable area positioning method described in the above embodiment, as described in the following embodiment. Since the principle of problem solving of the XML-based Word document editable area positioning device is similar to that of the XML-based Word document editable area positioning method, the embodiments of the XML-based Word document editable area positioning device can refer to the embodiments of the XML-based Word document editable area positioning method, and the repeated parts will not be described herein. The term "unit" or "module" used below can be a combination of software and / or hardware that realizes a predetermined function. Although the device described in the following embodiment is preferably realized in software, the realization of hardware or a combination of software and hardware is also possible and is conceived.
[0211] Figure 6 is a first structural block diagram of the XML-based Word document editable area positioning device of the embodiment of the present application, as shown in the figure, in an embodiment of the present application, the XML-based Word document editable area positioning device of the present application comprises: Figure 6
[0212] the XML file acquisition unit 601 is configured to decompress the acquired Word document to obtain a corresponding XML file;
[0213] the tag node list generation unit 602 is configured to traverse the XML file, identify and locate the permission tag node and the structural tag node, and obtain a tag node list;
[0214] the character map dictionary generation unit 603 is configured to generate a character map dictionary according to the tag node list and a pre-constructed document tag placeholder rule library;
[0215] the editable area determination unit 604 is configured to perform area jumping dynamic verification based on the character map dictionary to obtain editable area position information that passes the verification.
[0216] Figure 7 is a second structural block diagram of the XML-based Word document editable area positioning device of the embodiment of the present application, based on the embodiment, further, as shown in the figure, Figure 6 in an embodiment of the present application, the character map dictionary generation unit 603 comprises: Figure 7 the character length determination module 701 is configured to determine the character length of each tag area according to the tag node list and a pre-constructed document tag placeholder rule library;
[0217]
[0218] The character index coordinate generation module 702 is configured to convert the character length into a character index coordinate.
[0219] The character map dictionary generation module 703 is configured to generate the character map dictionary based on the character index coordinate.
[0220] Figure 8 is a third structural block diagram of an XML-based Word document editable region positioning device according to an embodiment of the present application, which is based on Figure 7 on the basis of the embodiment, further, as Figure 8 shown, in an embodiment of the present application, the character length determination module 701 comprises:
[0221] The first character length determination sub-module 801 is configured to, if the tag type of a first tag region in the tag node list is a text tag, determine the character length of the first tag region as the actual character length in the first tag region.
[0222] The second character length determination sub-module 802 is configured to, if the tag type of a second tag region in the tag node list is a line break tag, determine the character length of the second tag region as 1 character.
[0223] The third character length determination sub-module 803 is configured to, if the tag type of a third tag region in the tag node list is a table cell tag, determine the character length of the third tag region as the accumulation of the text length in the cell.
[0224] The fourth character length determination sub-module 804 is configured to, if the tag type of a fourth tag region in the tag node list is a picture or object tag, determine the character length of the fourth tag region as 0 characters.
[0225] Figure 9 is a fourth structural block diagram of an XML-based Word document editable region positioning device according to an embodiment of the present application, which is based on Figure 6 the embodiment, further, as Figure 9 shown, in an embodiment of the present application, the editable region determination unit 604 comprises:
[0226] The pointer initialization module 901 is configured to initialize a document position pointer.
[0227] The editable region verification module 902 is configured to, when the document position pointer is located in an editable region in the character map dictionary, call an API to verify the first character of the editable region, if the verification is passed, mark the editable region and move the document position pointer to the end of the editable region.
[0228] The interval area verification module 903 is configured to directly move the document position pointer to the end of the interval area in the character map dictionary when the document position pointer is located in the interval area in the character map dictionary.
[0229] The non-precomputed area verification module 904 is configured to call an API to perform character-by-character verification on the non-precomputed area in the character map dictionary when the document position pointer is located in the non-precomputed area in the character map dictionary.
[0230] Figure 10 FIG. 5 is a fifth structural block diagram of an XML-based Word document editable area positioning apparatus according to an embodiment of the present application, and Figure 9 Based on the embodiment, further, Figure 10 As shown in FIG. 6, in one embodiment of the present application, the editable area determination unit 604 further includes:
[0231] The verification module 1001 is configured to call a Range interface to perform a set text or write permission detection operation on a target character interval, to determine whether the target character interval has an editable attribute.
[0232] The marking module 1002 is configured to generate editable area marking information when the operation is successfully performed.
[0233] In one embodiment of the present application, the character map dictionary is in a key-value pair structure, the key is an area identifier, and the value is a triple including an area type, a start index, and an end index; the area type includes an editable area and an interval area.
[0234] The present application provides an XML-based Word document editable area positioning method and apparatus, which obtains an XML file by decompressing a Word document; iterates through the XML file, identifies and locates a permission tag node and a structural tag node, to obtain a tag node list; generates a character map dictionary according to the tag node list and a pre-constructed document tag placeholder rule library; and performs area jump dynamic verification based on the character map dictionary, to obtain editable area position information that passes verification, thereby realizing fast and accurate positioning of editable areas in a complex document, and significantly improving the accuracy and processing efficiency of editable area identification.
[0235] Figure 11 FIG. 1 is a structural diagram of a computer device according to an embodiment of the present application, and Figure 11 As shown, the computer device can include a processor 1101, a communications interface 1102, a memory 1103, and a communications bus 1104, wherein the processor 1101, the communications interface 1102, and the memory 1103 complete mutual communication through the communications bus 1104. The processor 1101 can invoke the logical instructions in the memory 1103 to perform the following method: decompressing an obtained Word document to obtain a corresponding XML file; traversing the XML file, identifying and positioning a permission tag node and a structural tag node to obtain a tag node list; generating a character map dictionary according to the tag node list and a pre-constructed document tag placeholder rule library; and performing region skipping dynamic verification based on the character map dictionary to obtain editable region position information that passes verification.
[0236] In addition, the logical instructions in the memory 1103 described above can be implemented in the form of a software functional unit and sold or used as an independent product, and can be stored in a computer-readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, includes several instructions to make a computer device (which can be a personal computer, a top drive control center server, or a network device) execute all or part of the steps of the methods described in the various embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.
[0237] The embodiment discloses a computer program product, which comprises a computer program stored on a computer readable storage medium, and the computer program comprises program instructions. When the program instructions are executed by a computer, the computer can execute the method provided by the above-mentioned method embodiments, for example, including: decompressing an obtained Word document to obtain a corresponding XML file; traversing the XML file, identifying and positioning a permission tag node and a structural tag node to obtain a tag node list; generating a character map dictionary according to the tag node list and a pre-constructed document tag placeholder rule library; and performing region skipping dynamic verification based on the character map dictionary to obtain editable region position information that passes verification.
[0238] The embodiment provides a computer readable storage medium, which stores a computer program, and the computer program causes the computer to execute the method provided in each method embodiment, for example, including: decompressing an acquired Word document to obtain a corresponding XML file; traversing the XML file, identifying and positioning a permission tag node and a structural tag node to obtain a tag node list; generating a character map dictionary according to the tag node list and a pre-constructed document tag placeholder rule library; and performing region jump dynamic verification based on the character map dictionary to obtain editable region position information that passes the verification.
[0239] Those skilled in the art should understand that embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. In addition, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage, etc.) containing computer-usable program code.
[0240] The present application is described with reference to flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and combinations of flows and / or blocks in the flowcharts and / or block diagrams can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing apparatus to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing apparatus generate a means for implementing the functions specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 an apparatus that implements the functions specified in the flowcharts and / or block diagrams.
[0241] These computer program instructions can also be stored in a computer-readable memory that can direct the computer or other programmable data processing apparatus to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including instruction apparatus, which implements the functions specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 an apparatus that implements the functions specified in the flowcharts and / or block diagrams.
[0242] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus, so that a series of operation steps are performed on the computer or other programmable data processing apparatus to produce a computer-implemented process, so that the instructions executed on the computer or other programmable data processing apparatus provide a means for implementing the functions specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 the steps of the function specified in the one or more blocks.
[0243] In the description of the application, reference has been made to the use of terms such as "one embodiment", "an embodiment", "some embodiments", "example", "exemplary", "specific example" or "some examples" means that a particular feature, structure, material or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the application. The illustrative appearances of the above-mentioned terms in various places in the specification are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0244] The specific embodiments described above are intended to be illustrative of the application, and the true scope of the application is indicated by the appended claims.< / w:object> < / w:drawing> < / w:tbl> < / w:tc> < / w:t> < / w:tl> < / w:tc> < / w:tab> < / w:tc> < / w:tbl> < / w:permend> < / w:permstart> < / w:tbl> < / w:t> < / w:permend> < / w:permstart> < / w:permend> < / w:permstart> < / w:tbl> < / w:permend> < / w:permstart> < / w:permend> < / w:permstart>
Claims
1. A method for locating editable areas in a Word document based on XML, characterized in that, include: The obtained Word document is decompressed to obtain the corresponding XML file; Traverse the XML file, identify and locate permission tag nodes and structural tag nodes, and obtain a list of tag nodes; A character map dictionary is generated based on the list of tag nodes and the pre-built document tag placeholder rule library; Based on the character map dictionary, dynamic verification of area jumps is performed to obtain the location information of the editable area that has passed the verification.
2. The method for locating editable regions in a Word document based on XML according to claim 1, characterized in that, The step of generating a character map dictionary based on the list of tag nodes and a pre-built document tag placeholder rule library includes: The character length of each tag region is determined based on the list of tag nodes and the pre-built document tag placeholder rule library; Convert the character length into character index coordinates; The character map dictionary is generated based on the character index coordinates.
3. The method for locating editable regions in a Word document based on XML according to claim 2, characterized in that, The step of determining the character length of each tag region based on the tag node list and a pre-built document tag placeholder rule library includes: If the tag type of the first tag region in the tag node list is a text tag, the character length of the first tag region is determined to be the actual character length of the first tag region. If the tag type of the second tag region in the tag node list is a newline tag, then the character length of the second tag region is determined to be 1 character. If the tag type of the third tag area in the tag node list is a table cell tag, the character length of the third tag area is determined to be the sum of the text lengths within the cell; If the tag type of the fourth tag region in the tag node list is an image or object tag, then the character length of the fourth tag region is determined to be 0 characters.
4. The method for locating editable regions in a Word document based on XML according to claim 1, characterized in that, The dynamic verification of region jumps based on the character map dictionary includes: Initialize the document position pointer; When the document position pointer is located in an editable area of the character map dictionary, the API is called to verify the first character of the editable area. If the verification passes, the editable area is marked and the document position pointer is moved to the end of the editable area. When the document position pointer is located in the interval region of the character map dictionary, the document position pointer is directly moved to the end of the interval region; When the document location pointer is located in an uncalculated region in the character map dictionary, the API is called to perform character-by-character verification of the uncalculated region.
5. The method for locating editable regions in a Word document based on XML according to claim 4, characterized in that, Calling the API to validate the target character range includes: Call the Range interface to perform operations such as setting text or checking write permissions on the target character range, in order to determine whether the target character range has editable attributes; When the operation is successfully executed, editable region marker information is generated.
6. The method for locating editable regions in a Word document based on XML according to claim 1, characterized in that, The character map dictionary is a key-value pair structure, where the key is a region identifier and the value is a triple including region type, start index, and end index; the region type includes editable regions and interval regions.
7. A Word document editable area positioning device based on XML, characterized in that, include: The XML file acquisition unit is used to decompress the acquired Word document to obtain the corresponding XML file; The tag node list generation unit is used to traverse the XML file, identify and locate permission tag nodes and structural tag nodes, and obtain a tag node list; The character map dictionary generation unit is used to generate a character map dictionary based on the list of tag nodes and a pre-built document tag placeholder rule library; The editable region determination unit is used to perform dynamic verification of region jumps based on the character map dictionary to obtain the location information of the editable region that has passed the verification.
8. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program / instructions stored thereon, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 6.
10. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 6.