Document processing method and device based on rich text data, computer equipment, medium and product

By parsing HTML content in rich text editors and mapping OOXML specifications, generating XML documents and inserting Word templates, the problem that rich text editors cannot export Word documents is solved, data security and functional flexibility are achieved, and multiple services are met Scenario requirements.

CN119250036APending Publication Date: 2025-01-03SHENZHEN COMTOP INFORMATION TECH
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411332543.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-24
Publication Date
2025-01-03

AI Technical Summary

Technical Problem

The existing rich text editor cannot directly export the content to Word document format, and the existing HTML to Word tool has data security risks and functional limitations. It cannot support flexibly inserting rich text editor content or web page content into Word templates. Keep or apply predefined styles of templates.

Method used

By parsing the HTML content in the rich text editor, constructing an HTML node tree, and mapping HTML nodes to the OOXML document structure and style structure according to the Office Open XML specification, generating an XML document, and inserting it into a Word template to specify it location, achieve the output of the target document.

Benefits of technology

It realizes the safe conversion of rich text editor content into Word documents, retains or applies predefined styles of Word templates, meets document needs in multiple business scenarios, and solves the problems of data security and functional flexibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119250036A_ABST
    Figure CN119250036A_ABST
Patent Text Reader

Abstract

The invention relates to a document processing method and device based on rich text data, computer equipment, a medium and a product. The method comprises the following steps: analyzing HTML (Hypertext Markup Language) contents in a rich text editor to obtain an HTML node tree; determining a document storage component and a style definition component of the template document according to the document format standard definition; traversing nodes of the HTML node tree, and mapping the nodes to a document storage component and a style definition component to obtain a document storage structure and a document style structure under the document format standard definition; and based on the document storage structure and the document style structure, generating an XML document under the document format standard definition, and processing the template document according to the XML document to obtain a target document. By the adoption of the method, data security can be guaranteed, the rich text editor content or the webpage content can be flexibly supported to be converted and inserted into the Word template, meanwhile, the template predefined style is reserved, and therefore the document requirement under the multi-service scene is met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of application development technology, and in particular to a document processing method, device, computer equipment, medium and product based on rich text data. Background Art

[0002] In the process of modern web application development, Rich Text Editors (RTEs) have become the standard tool for building dynamic content creation interfaces, especially in scenarios where users need to edit complex documents directly online.

[0003] However, rich text editors are usually unable to directly export content to Word document format, which requires users to rely on additional conversion tools or services. However, these tools often require users to upload HTML files to third-party platforms, which is not only cumbersome to process, but more importantly, for documents containing sensitive business data, this method poses serious risks of data security and privacy leakage. In addition, when copying content in a rich text editor or other web page content to a document editor such as Word, the original style is often lost, which cannot meet the scenarios with strict requirements on document format. Summary of the invention

[0004] Based on this, it is necessary to provide a document processing method, device, computer equipment, medium and product based on rich text data that can improve the accuracy of documents in response to the above technical problems.

[0005] In a first aspect, the present application provides a document processing method based on rich text data, comprising:

[0006] Parse the HTML content in the rich text editor to obtain the HTML node tree;

[0007] According to the document format standard definition, determine the document storage component and style definition component of the template document; the document storage component is used to store the document content, and the style definition component is used to store the document style;

[0008] Traversing the nodes of the HTML node tree, mapping the nodes to the document storage components, obtaining the document storage structure defined under the document format standard, and mapping the nodes to the style definition components, obtaining the document style structure defined under the document format standard;

[0009] Based on the document storage structure and the document style structure, an XML document defined under the document format standard is generated, and the template document is processed according to the XML document to obtain the target document.

[0010] In one embodiment, the step of parsing the HTML content in the rich text editor to obtain the HTML node tree includes:

[0011] Recognize the HTML content in the rich text editor to obtain HTML tags; HTML tags are used to represent HTML elements in the HTML content;

[0012] Construct an HTML node tree based on HTML tags; each node in the HTML node tree represents an HTML tag.

[0013] In one embodiment, the step of mapping the node to the document storage component to obtain the document storage structure defined under the document format standard includes:

[0014] According to a preset first mapping rule, converting the HTML element represented by the HTML tag corresponding to the node into an XML element defined in a document format standard;

[0015] All converted XML elements are serialized according to the structure of the HTML node tree to obtain a document storage structure defined by the document format standard.

[0016] In one embodiment, the step of mapping the node to the style definition component to obtain the document style structure defined under the document format standard includes:

[0017] For HTML elements with style attributes, according to the preset second mapping rule, the style attribute of the HTML element represented by the HTML tag corresponding to the node is written into the style definition component, and a corresponding style ID is created to obtain the document style structure defined under the document format standard.

[0018] In one embodiment, the method further comprises:

[0019] According to the style ID corresponding to the style attribute, a reference relationship between the XML element in the document storage structure and the style ID is established to represent the first XML style of the XML element through the style ID;

[0020] For an HTML element with a style tag, convert the style tag into a second XML style defined under a document format standard;

[0021] For an HTML element having both a style attribute and a style tag, the first XML style and the second XML style corresponding to the HTML element are merged to obtain a defined style corresponding to the HTML element, and the defined style is written to a corresponding position of the document storage structure.

[0022] In one embodiment, the step of processing the template document according to the XML document to obtain the target document includes:

[0023] Determine the area to be processed in the template document;

[0024] The region to be processed is replaced with the document content of the XML document to obtain the target document.

[0025] In a second aspect, the present application further provides a document processing device based on rich text data, comprising:

[0026] The content parsing module is used to parse the HTML content in the rich text editor to obtain an HTML node tree;

[0027] The structure determination module is used to determine the document storage component and style definition component of the template document according to the document format standard definition; the document storage component is used to store the document content, and the style definition component is used to store the document style;

[0028] A node mapping module, used to traverse the nodes of the HTML node tree, map the nodes to the document storage component, obtain the document storage structure under the document format standard definition, and map the nodes to the style definition component, obtain the document style structure under the document format standard definition;

[0029] The document processing module is used to generate an XML document defined under the document format standard based on the document storage structure and the document style structure, and to process the template document according to the XML document to obtain the target document.

[0030] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method steps of any one of the first aspects are implemented.

[0031] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which implements any one of the method steps in the first aspect when the computer program is executed by a processor.

[0032] In a fifth aspect, the present application further provides a computer program product, comprising a computer program, which implements any one of the method steps in the first aspect when executed by a processor.

[0033] The above-mentioned document processing method, device, computer equipment, medium and product based on rich text data, by converting the HTML content filled in the rich text editor into an HTML node tree, converting the HTML nodes into nodes of XML document content according to the mapping relationship between HTML node tags and XML nodes defined under the document format standard, parsing the style content in the node tag data, constructing an XML document style that complies with the document format standard definition, outputting the XML document according to the node content, inserting the XML document fragment into the tag placeholder position specified by the template document, and realizing the output of the final target document, can not only ensure data security, but also flexibly support the conversion and insertion of rich text editor content or web page content into Word templates, while retaining or applying the template predefined style, thereby meeting the document needs in multiple business scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0035] FIG1 is a schematic diagram of a process flow of a document processing method based on rich text data in one embodiment;

[0036] FIG2 is a schematic diagram of a mapping relationship between an HTML structure and a document.xml structure in one embodiment;

[0037] FIG3 is a schematic diagram of a mapping relationship between an HTML structure and a styles.xml structure in one embodiment;

[0038] FIG4 is a schematic diagram of the mapping relationship between HTML style tags and document.xml styles in one embodiment;

[0039] FIG5 is a schematic diagram of a mapping relationship between a merged HTML style tag and a document.xml style in one embodiment;

[0040] FIG6 is a schematic diagram of the complete process of generating OOXML elements from HTML tags in one embodiment;

[0041] FIG7 is a schematic diagram showing a comparison between a template document and a target document in one embodiment;

[0042] FIG8 is a schematic flow chart of a document processing method based on rich text data in another embodiment;

[0043] FIG9 is a structural block diagram of a document processing device based on rich text data in one embodiment;

[0044] FIG. 10 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0045] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0046] In modern Web application development, rich text editors have become an indispensable part. They have greatly improved the convenience and efficiency of users editing complex text content online, and realized the "what you see is what you get" editing experience. Common rich text editors such as CKEditor 5, UEditor, TinyMCE, Froala Editor, etc., not only support basic text formatting functions, but also can better handle complex content copied and pasted from document processing software such as Microsoft Word, including text styles, lists, tables, images and complex layouts, providing users with an editing experience close to the native Word application.

[0047] However, although these rich text editors perform well in content input and formatting, they face many limitations when it comes to content output, especially when it comes to conversion to Word document format. First, these editors do not support directly exporting edited content as Word documents, which limits their application in scenarios where Word format deliverables need to be generated.

[0048] To solve this problem, a variety of online HTML to Word conversion tools have emerged on the market (such as HTML to WordOnline, Zamzar, Convert Files, etc.), which generate Word documents for users to download after users upload HTML files and convert them on the server side. However, this method has significant data security risks, especially for documents containing sensitive business data, uploading them to third-party services for conversion may lead to data leakage, which does not meet the strict requirements of enterprises for data security.

[0049] In addition, existing HTML to Word tools have functional limitations. They can only convert the entire HTML file into an independent Word document, but cannot support inserting HTML content or fragments into a specific location in a predefined Word template, which limits the flexibility of document formatting. At the same time, these tools cannot automatically apply the predefined styles in the Word template (such as cover, header, footer, multi-level title, etc.), making it difficult for the generated Word document to meet the format requirements in specific business scenarios.

[0050] In summary, the current rich text editors in Web systems have significant technical bottlenecks in outputting content to Word documents, and the existing online HTML to Word tools have problems with data security and functional limitations. Therefore, it is particularly urgent and important to develop a solution that can not only ensure data security, but also flexibly support the conversion and insertion of rich text editor content or web page content into Word templates, while retaining or applying template predefined styles.

[0051] Based on this, the embodiment of the present application provides a document processing method based on rich text data, based on the HTML structure of the rich text editor to store content, combined with the Office Open XML (OOXML) technology at the bottom of the Word document, to achieve precise alignment of HTML tags with OOXML document content storage tags, as well as effective mapping of HTML styles with OOXML document styles. Furthermore, the present application also implements a dynamic content insertion mechanism based on the Word document template, allowing users to directly insert content or HTML file fragments in the rich text editor into the specified location of the Word template, while retaining the predefined styles in the template, such as cover, header and footer, multi-level title, etc., thereby perfectly meeting the business scenario requirements that have strict requirements on the Word document format or need to follow a specific template.

[0052] Before describing the embodiments of the present application, the concepts that may be involved in the embodiments of the present application are described below:

[0053] Rich Text Editor: Rich Text Editor (RTE) is a WYSIWYG text editor that can be embedded in a browser. It provides editing functions similar to Microsoft Word, such as font setting, color adjustment, image insertion, hyperlink addition, etc., making it convenient for users to edit and format articles or information.

[0054] HTML (Hyper Text Markup Language): A standard markup language used to create web pages. Through HTML, developers can tell browsers how to display web page content, including text, images, links, tables, lists, etc. HTML documents are composed of a series of HTML elements, which are defined by tags.

[0055] Document Object Model (DOM): Connects web pages with scripts or programming languages ​​by storing the structure of a document (such as the HTML that represents a web page) as objects in memory.

[0056] HTML DOM tree: A programming interface for HTML documents that represents the structure of a document and allows access and manipulation of these structures through programming languages ​​such as JavaScript. The DOM tree is a hierarchical data structure that represents the entire HTML document as a tree structure consisting of multiple nodes. In the HTML DOM tree, each element is considered a node.

[0057] Word document: An electronic document format created and edited using Microsoft Word software that supports rich text formatting, pictures, tables, hyperlinks and other elements.

[0058] Extensible Markup Language (XML): A language strictly serialized by the Document Object Model (DOM).

[0059] Office Open XML: XML-based office document format that supports documents such as files, tables, memos, and slides.

[0060] In an exemplary embodiment, as shown in FIG1 , a document processing method based on rich text data is provided, including the following steps 102 to 108. Among them:

[0061] S102: Parse the HTML content in the rich text editor to obtain an HTML node tree.

[0062] Alternatively, commonly used Web rich text editors mainly include CKEditor 5 / , UEditor, TinyMCE, Froala Editor, etc., which generally store content data in the form of HTML, providing users with an online "what you see is what you get" editing experience. Therefore, when processing the content of a Web rich text editor, it is necessary to parse the HTML fragment of the content data and construct an HTML node tree (i.e., HTML DOM tree). Among them, the HTML DOM tree is the programming interface of the HTML document, which represents the structure of the document and allows these structures to be accessed and operated through programming languages ​​such as JavaScript. The DOM tree is a hierarchical data structure that represents the entire HTML document as a tree structure composed of multiple nodes.

[0063] For example, you can use the open source Jsoup component to parse HTML. Jsoup is a Java HTML parser that can directly parse a Uniform Resource Locator (URL) address and HTML text content. It provides a very labor-saving API that can retrieve and manipulate data through DOM, CSS, and JQuery-like operation methods. Jsoup implements an HTML DOM tree that is consistent with the browser rendering effect, effectively ensuring the consistency of the parsed structure with the structure that the user sees through the browser.

[0064] S104: Determine a document storage component and a style definition component of the template document according to the document format standard definition; the document storage component is used to store document content, and the style definition component is used to store document style.

[0065] Optionally, the document format standard definition refers to the Office Open XML (OOXML for short) specification, which is an XML-based document file format used for documents of Microsoft Office applications (such as Word, Excel, and PowerPoint), and defines a set of detailed XML schemas for representing the content and structure of documents, including the structure, style, settings, representation of elements such as charts and images of the document itself. When converting HTML content to a Word document, in order to ensure that the converted document content has a consistent style with the Word document, by parsing the document structure under the OOXML specification, it is possible to determine how the content and style in the Word document are organized and managed through the OOXML specification, and edit, modify, and extend the document accordingly.

[0066] Exemplarily, the main structure of a Word document is shown in Table 1. As can be seen from Table 1, the content of the document is mainly stored in the / word / document.xml component (ie, the document storage component), and the style information of the document is mainly stored in the / word / styles.xml component (ie, the style definition component).

[0067] Table 1

[0068]

[0069] S106: traverse the nodes of the HTML node tree, map the nodes to the document storage component, obtain the document storage structure under the document format standard definition, and map the nodes to the style definition component, obtain the document style structure under the document format standard definition.

[0070] Optionally, in a rich text editor, the HTML content entered by the user usually contains various tags (such as , , , etc.), which are used to define the format and structure of the text. However, when these HTML contents are saved as Word documents in OOXML format, these HTML tags are not directly mapped to the corresponding XML tags in document.xml. Instead, OOXML uses its own tag system to represent the format and structure of the document. These tags may be similar to HTML tags in semantics, but there are differences in naming and structure. Similarly, there are tags with specific styles in HTML. When these tags are converted to OOXML format, in addition to being mapped to text content fragments in document.xml, they also need to be mapped to style definitions in styles.xml.

[0071] Exemplarily, by traversing the nodes of the HTML node tree, the HTML content in the rich text editor is converted into XML format to obtain document.xml (i.e., document storage structure) in OOXML format, and the style of the HTML content is mapped to the style in OOXML to obtain styles.xml (i.e., document style structure) in OOXML format, ensuring that the converted XML format is consistent with the effect of the HTML content.

[0072] S108: Generate an XML document defined under the document format standard based on the document storage structure and the document style structure, and process the template document according to the XML document to obtain a target document.

[0073] Optionally, the Word document stores the converted HTML content, including text, images, tables and other elements, through a document storage structure, so as to maintain the integrity of the content. At the same time, the Word document stores the converted HTML style through a document style structure, so as to ensure that the converted Word document is visually consistent with the original HTML page. The HTML content is converted into OOXML content by generating a corresponding OOXML node for each HTML node, and these sections are organized into document fragments.

[0074] Exemplarily, a template document usually contains a basic document structure and some placeholders. By traversing the content of the template document, the generated document fragments are inserted into the placeholder positions specified in the template document, replacing the original placeholder content, and finally outputting a complete OOXML document (ie, the target document).

[0075] In the above-mentioned document processing method based on rich text data, by converting the HTML content filled in the rich text editor into an HTML node tree, according to the mapping relationship between HTML node tags and XML nodes defined under the document format standard, the HTML nodes are converted into nodes of XML document content, the style content in the node tag data is parsed, and the XML document style that complies with the document format standard definition is constructed, the XML document is output according to the node content, and the XML document fragment is inserted into the tag placeholder position specified by the template document to achieve the output of the final target document. This can not only ensure data security, but also flexibly support the conversion and insertion of rich text editor content or web page content into Word templates, while retaining or applying the template predefined style, thereby meeting the document needs in multiple business scenarios.

[0076] In an exemplary embodiment, the step of parsing the HTML content in the rich text editor to obtain the HTML node tree includes: identifying the HTML content in the rich text editor to obtain HTML tags; HTML tags are used to represent HTML elements in the HTML content; an HTML node tree is constructed according to the HTML tags; each node in the HTML node tree represents an HTML tag.

[0077] Optionally, first identify the HTML content in the rich text editor, obtain the HTML content from the rich text editor, which usually includes multiple elements such as text, pictures and tables, and then parse these elements to identify the HTML tags of these elements, wherein the HTML tags are used to define the structure of the HTML document, for example Indicates a paragraph, Indicates pictures, etc.

[0078] Further, a Document Object Model (DOM) tree is constructed based on the parsed HTML tags, where the DOM tree is a tree structure in which each node represents an HTML element in the document, that is, an HTML tag. For example, in an HTML document, the root node is usually an element, which contains and two child nodes, the latter of which further contains all visible content on the page.

[0079] In this embodiment, by parsing the HTML content in the rich text editor into a HYML node tree, the HTML content can be structured and represented, clearly reflecting the element hierarchy and relationships of the HTML document, ensuring the integrity of the content when converted to OOXML, and further ensuring that the converted OOXML document is consistent in format with the original HTML content.

[0080] In an exemplary embodiment, the step of mapping nodes to document storage components to obtain a document storage structure defined under a document format standard includes: according to a preset first mapping rule, converting the HTML elements represented by the HTML tags corresponding to the nodes into XML elements defined under the document format standard; serializing all the converted XML elements according to the structure of the HTML node tree to obtain a document storage structure defined under the document format standard.

[0081] Alternatively, in the OOXML structure of a Word document, / word / document.xml is the main body of the document, which contains the main text content and most of the structural information of the document. This component is the XML representation of the content that users directly see when editing the document, including elements such as paragraphs, tables, lists, and pictures. In the process of mapping the HTML structure to document.xml, the principle mainly involves the conversion of elements between two different markup languages.

[0082] Optionally, first, for an element in an HTML document such as 、 、 <h1>etc.), formulate a set of mapping rules according to the target XML format (i.e. document.xml of OOXML), which define how to convert HTML elements into equivalent elements in XML. The element may be mapped to the document.xml<w:p> Elements. After that, according to the mapping rules, the HTML DOM structure is converted into the XML structure.

[0083] Exemplarily, as shown in Figure 2, Figure 2 is a schematic diagram of the mapping relationship between the HTML structure and the document.xml structure. It can be seen from Figure 2 that the HTML elements in the HTML node tree are converted into XML elements defined under the document format standard, and mapped one by one to the document.xml structure to obtain the document storage structure defined under the document format standard, wherein the element hierarchy and relationship of the document.xml structure and the HTML structure are always consistent.

[0084] In this embodiment, by mapping HTML nodes to OOXML document storage components, a document storage structure defined under the document format standard is obtained, which can generate XML documents that comply with the OOXML standard and efficiently convert HTML documents into OOXML format, thereby making full use of the advantages of OOXML to improve the quality and efficiency of document processing.

[0085] In an exemplary embodiment, the step of mapping a node to a style definition component to obtain a document style structure defined under a document format standard includes: for an HTML element having a style attribute, according to a preset second mapping rule, writing the style attribute of the HTML element represented by the HTML tag corresponding to the node into the style definition component, and creating a corresponding style ID to obtain a document style structure defined under the document format standard.

[0086] Optionally, there are some tags with specific styles in HTML, such as the "paragraph and style tags" and "isolation tags" selected in Figure 2. The style information of these tags is represented by the style attribute in the HTML structure, while in Word documents, the style and data content are well separated. Therefore, for these HTML elements with style attributes, when converting to OOXML, the styles in HTML need to be mapped to the OOXML style system, that is, the style attributes need to be written to styles.xml.

[0087] For example, < / h1> <h2>Take the secondary title represented by the tag as an example, as shown in Figure 3, which is a schematic diagram of the mapping relationship between the HTML structure and the styles.xml structure. As shown in Figure 3, the style information in HTML is parsed and mapped to styles.xml, which defines various styles that can be used in the document. Each style has a unique style ID. The styles in styles.xml define the format of the text (such as font, size, bold, etc.), as well as the layout of the paragraphs (such as spacing, indentation, etc.).

[0088] In this embodiment, by mapping HTML nodes to OOXML style definition components, a document style structure defined under the document format standard is obtained, and style information can be stored separately in the style definition component, thereby achieving separation of style and content, so that style modification can be performed independently of content, thereby improving the flexibility of the document.

[0089] In an exemplary embodiment, the method further includes: establishing a reference relationship between an XML element in a document storage structure and a style ID according to a style ID corresponding to a style attribute, so as to represent a first XML style of the XML element through the style ID; for an HTML element having a style tag, converting the style tag into a second XML style defined under a document format standard; for an HTML element having both a style attribute and a style tag, merging the first XML style and the second XML style corresponding to the HTML element to obtain a defined style corresponding to the HTML element, and writing the defined style to a corresponding position in the document storage structure.

[0090] Optionally, from the Word document structure, we can know that the numbering style of the ordered list is defined in the / word / numbering.xml component, including the format, level, and nested relationship of the numbering. Therefore, for the style definition in styles.xml, the list and list items in HTML can be directly mapped to the corresponding elements in document.xml by referencing the numbering style defined in numbering.xml in document.xml. As shown in the boxed content in Figure 3: w:styleId="3", this style ID is referenced in document.xml: <w:pstyle w:val="3">.

[0091] Furthermore, there are some tags with specific styles in HTML, such as ~ The sixth level heading tag, , , , For various font tags, etc., for such style tags, without considering the style attribute, you can directly define a specific style in the document.xml component.

[0092] Exemplarily, taking text styles as an example, the font, color, font size, bold, underline and other styles of the text in HTML can be defined as styles in Word. The mapping relationship between HTML style tags and document.xml styles is shown in FIG. 4 .

[0093] Furthermore, an HTML element may have both a style attribute and a style tag. For example, To specify the text as bold, the style attribute of the tag is also configured. At this time, it is necessary to merge the result of the style attribute mapping (i.e. the first XML style) and the style converted from the style tag (i.e. the second XML style) to finally form the style required by the Word document.

[0094] For example, taking text as an example, in a piece of text there are both style attributes and , This style tag, then the final mapping result is shown in Figure 5.

[0095] Furthermore, in combination with Figures 2 to 5, it can be seen that according to the above processing logic, the parsing and mapping of HTML tags, style attributes and style tags can be realized. After HTML is parsed into a DOM tree, the DOM tree nodes are traversed in a loop to construct document.xml and styles.xml fragments in OOXML to realize the conversion of HTML fragment content into Word content. After the conversion is completed, the repeated styles in the generated styles.xml need to be merged. Among them, the schematic diagram of the complete process of generating OOXML elements from HTML tags is shown in Figure 6.

[0096] In this embodiment, by merging repeated styles in styles.xml generated by HTML elements that have both style attributes and style tags, display problems caused by style conflicts or overlaps can be avoided, thereby ensuring content integrity when converting to OOXML, and further ensuring that the converted OOXML document is consistent in format with the original HTML content.

[0097] In an exemplary embodiment, the step of processing the template document according to the XML document to obtain the target document includes: determining the area to be processed in the template document; replacing the area to be processed with the document content of the XML document to obtain the target document.

[0098] Alternatively, in actual business scenarios, the content filled in through the rich text editor is often only a part of the actual business needs, and a large amount of content is filled in the Word document template. For example, the "Outline Design Specification" often includes fixed content such as project background, reference specifications, reading instructions, etc., and only the relevant content of the functional design in the "Outline Design Specification" needs to be dynamically filled in by the system, so it is necessary to implement dynamic insertion of Word content in a fixed template.

[0099] Exemplarily, taking the "Outline Design Specification" template as an example, as shown in Figure 7, Figure 7 is a schematic diagram comparing the template document (the document on the left in Figure 7) and the target document (the document on the right in Figure 7). It can be seen from Figure 7 that the area selected in the template document is the area to be processed, which is represented by a placeholder in the template document. By replacing the placeholder of the area to be processed with the document content of the XML document (that is, the selected part of the target document), a target document that meets business needs is finally generated.

[0100] In this embodiment, by replacing the placeholder of the area to be processed with the document content of the XML document, it is possible to not only ensure data security, but also flexibly support the conversion and insertion of rich text editor content or web page content into a Word template, while retaining or applying the template predefined style, thereby meeting the document requirements in multiple business scenarios.

[0101] In an exemplary embodiment, as shown in FIG8 , a document processing method based on rich text data is provided, the method comprising the following steps:

[0102] The HTML content in the rich text editor is identified to obtain HTML tags; the HTML tags are used to represent HTML elements in the HTML content; an HTML node tree is constructed according to the HTML tags; each node in the HTML node tree represents an HTML tag.

[0103] According to the document format standard definition, the document storage component and style definition component of the template document are determined; the document storage component is used to store the document content, and the style definition component is used to store the document style.

[0104] Traverse the nodes of the HTML node tree, and according to a preset first mapping rule, convert the HTML elements represented by the HTML tags corresponding to the nodes into XML elements defined under the document format standard; serialize all the converted XML elements according to the structure of the HTML node tree to obtain a document storage structure defined under the document format standard.

[0105] For HTML elements with style attributes, according to the preset second mapping rule, the style attribute of the HTML element represented by the HTML tag corresponding to the node is written into the style definition component, and a corresponding style ID is created to obtain the document style structure defined under the document format standard.

[0106] According to the style ID corresponding to the style attribute, a reference relationship between the XML element in the document storage structure and the style ID is established to represent the first XML style of the XML element through the style ID; for HTML elements with style tags, the style tags are converted into a second XML style defined under the document format standard; for HTML elements with both style attributes and style tags, the first XML style and the second XML style corresponding to the HTML element are merged to obtain the defined style corresponding to the HTML element, and the defined style is written to the corresponding position of the document storage structure.

[0107] Based on the document storage structure and document style structure, an XML document defined under the document format standard is generated.

[0108] Determine the area to be processed in the template document; replace the area to be processed with the document content of the XML document to obtain the target document.

[0109] In this embodiment, the HTML content filled in the rich text editor is converted into an HTML node tree, and according to the mapping relationship between HTML node tags and XML nodes defined under the document format standard, the HTML nodes are converted into nodes of XML document content, the style content in the node tag data is parsed, and the XML document style that complies with the document format standard definition is constructed, and the XML document is output according to the node content, and the XML document fragment is inserted into the tag placeholder position specified by the template document to achieve the output of the final target document. This can not only ensure data security, but also flexibly support the conversion and insertion of rich text editor content or web page content into a Word template, while retaining or applying the template predefined style, thereby meeting the document requirements in multiple business scenarios.

[0110] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0111] Based on the same inventive concept, the embodiment of the present application also provides a document processing device based on rich text data for implementing the document processing method based on rich text data involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in the one or more document processing device embodiments based on rich text data provided below can refer to the limitations of the document processing method based on rich text data above, and will not be repeated here.

[0112] In an exemplary embodiment, as shown in FIG9 , a document processing device based on rich text data is provided, comprising: a content parsing module 10, a structure determination module 20, a node mapping module 30 and a document processing module 40, wherein:

[0113] The content parsing module 10 is used to parse the HTML content in the rich text editor to obtain an HTML node tree.

[0114] The structure determination module 20 is used to determine the document storage component and style definition component of the template document according to the document format standard definition; the document storage component is used to store the document content, and the style definition component is used to store the document style.

[0115] The node mapping module 30 is used to traverse the nodes of the HTML node tree, map the nodes to the document storage component, obtain the document storage structure under the document format standard definition, and map the nodes to the style definition component to obtain the document style structure under the document format standard definition.

[0116] The document processing module 40 is used to generate an XML document defined under the document format standard based on the document storage structure and the document style structure, and to process the template document according to the XML document to obtain a target document.

[0117] In an exemplary embodiment, the content parsing module 10 is also used to identify HTML content in the rich text editor to obtain HTML tags; HTML tags are used to represent HTML elements in HTML content; an HTML node tree is constructed based on the HTML tags; each node in the HTML node tree represents an HTML tag.

[0118] In an exemplary embodiment, the node mapping module 30 is also used to convert the HTML elements represented by the HTML tags corresponding to the nodes into XML elements defined under the document format standard according to a preset first mapping rule; all the converted XML elements are serialized according to the structure of the HTML node tree to obtain a document storage structure defined under the document format standard.

[0119] In an exemplary embodiment, the node mapping module 30 is also used to write the style attribute of the HTML element represented by the HTML tag corresponding to the node into the style definition component for HTML elements with style attributes according to a preset second mapping rule, and create a corresponding style ID to obtain a document style structure defined under the document format standard.

[0120] In an exemplary embodiment, the node mapping module 30 is also used to establish a reference relationship between the XML element in the document storage structure and the style ID according to the style ID corresponding to the style attribute, so as to represent the first XML style of the XML element through the style ID; for HTML elements with style tags, the style tags are converted into a second XML style defined under the document format standard; for HTML elements with both style attributes and style tags, the first XML style and the second XML style corresponding to the HTML element are merged to obtain the defined style corresponding to the HTML element, and the defined style is written to the corresponding position of the document storage structure.

[0121] In an exemplary embodiment, the document processing module 40 is further used to determine a region to be processed in the template document; and replace the region to be processed with the document content of the XML document to obtain a target document.

[0122] Each module in the above-mentioned document processing device based on rich text data can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module above.

[0123] In an exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be shown in FIG10. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected via a system bus, and the communication interface, the display unit, and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner may be implemented through WIFI, a mobile cellular network, near field communication (NFC) or other technologies. When the computer program is executed by the processor, a document processing method based on rich text data is implemented. The display unit of the computer device is used to form a visually visible picture, which may be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.

[0124] Those skilled in the art will understand that the structure shown in FIG. 10 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.

[0125] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the following steps when executing the computer program: parsing HTML content in a rich text editor to obtain an HTML node tree; determining a document storage component and a style definition component of a template document according to a document format standard definition; the document storage component is used to store document content, and the style definition component is used to store document style; traversing the nodes of the HTML node tree, mapping the nodes to the document storage component to obtain a document storage structure under the document format standard definition, and mapping the nodes to the style definition component to obtain a document style structure under the document format standard definition; generating an XML document under the document format standard definition based on the document storage structure and the document style structure, and processing the template document according to the XML document to obtain a target document.

[0126] In one embodiment, the processor executes a computer program that involves parsing HTML content in a rich text editor to obtain an HTML node tree, including: identifying the HTML content in the rich text editor to obtain HTML tags; HTML tags are used to represent HTML elements in the HTML content; an HTML node tree is constructed according to the HTML tags; each node in the HTML node tree represents an HTML tag.

[0127] In one embodiment, when a processor executes a computer program, the process of mapping nodes to document storage components to obtain a document storage structure defined under a document format standard includes: converting HTML elements represented by HTML tags corresponding to nodes into XML elements defined under a document format standard according to a preset first mapping rule; and serializing all converted XML elements according to the structure of an HTML node tree to obtain a document storage structure defined under a document format standard.

[0128] In one embodiment, when a processor executes a computer program, the process of mapping a node to a style definition component to obtain a document style structure defined under a document format standard includes: for an HTML element having a style attribute, according to a preset second mapping rule, writing the style attribute of the HTML element represented by the HTML tag corresponding to the node into the style definition component, and creating a corresponding style ID to obtain a document style structure defined under the document format standard.

[0129] In one embodiment, when the processor executes the computer program, the following steps are also implemented: according to the style ID corresponding to the style attribute, a reference relationship between the XML element in the document storage structure and the style ID is established to represent the first XML style of the XML element through the style ID; for HTML elements with style tags, the style tags are converted into a second XML style defined under the document format standard; for HTML elements with both style attributes and style tags, the first XML style and the second XML style corresponding to the HTML element are merged to obtain the defined style corresponding to the HTML element, and the defined style is written to the corresponding position of the document storage structure.

[0130] In one embodiment, the processor executes a computer program involving processing a template document according to an XML document to obtain a target document, including: determining a region to be processed in the template document; and replacing the region to be processed with document content of the XML document to obtain the target document.

[0131] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented: parsing HTML content in a rich text editor to obtain an HTML node tree; determining a document storage component and a style definition component of a template document according to a document format standard definition; the document storage component is used to store document content, and the style definition component is used to store document style; traversing the nodes of the HTML node tree, mapping the nodes to the document storage component to obtain a document storage structure under the document format standard definition, and mapping the nodes to the style definition component to obtain a document style structure under the document format standard definition; generating an XML document under the document format standard definition based on the document storage structure and the document style structure, and processing the template document according to the XML document to obtain a target document.

[0132] In one embodiment, when a computer program is executed by a processor, the computer program parses HTML content in a rich text editor to obtain an HTML node tree, including: identifying the HTML content in the rich text editor to obtain HTML tags; HTML tags are used to represent HTML elements in the HTML content; an HTML node tree is constructed according to the HTML tags; each node in the HTML node tree represents an HTML tag.

[0133] In one embodiment, when a computer program is executed by a processor, the steps involved in mapping nodes to document storage components to obtain a document storage structure defined under a document format standard include: converting HTML elements represented by HTML tags corresponding to nodes into XML elements defined under a document format standard according to a preset first mapping rule; and serializing all converted XML elements according to the structure of an HTML node tree to obtain a document storage structure defined under a document format standard.

[0134] In one embodiment, when a computer program is executed by a processor, the steps involved in mapping a node to a style definition component to obtain a document style structure defined under a document format standard include: for an HTML element having a style attribute, according to a preset second mapping rule, writing the style attribute of the HTML element represented by the HTML tag corresponding to the node into the style definition component, and creating a corresponding style ID to obtain a document style structure defined under the document format standard.

[0135] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented: according to the style ID corresponding to the style attribute, a reference relationship between the XML element in the document storage structure and the style ID is established to represent the first XML style of the XML element through the style ID; for HTML elements with style tags, the style tags are converted into a second XML style defined under the document format standard; for HTML elements with both style attributes and style tags, the first XML style and the second XML style corresponding to the HTML element are merged to obtain the defined style corresponding to the HTML element, and the defined style is written to the corresponding position of the document storage structure.

[0136] In one embodiment, when a computer program is executed by a processor, the processing of a template document according to an XML document to obtain a target document includes: determining a region to be processed in the template document; and replacing the region to be processed with the document content of the XML document to obtain the target document.

[0137] In one embodiment, a computer program product is provided, including a computer program, which implements the following steps when executed by a processor: parsing HTML content in a rich text editor to obtain an HTML node tree; determining a document storage component and a style definition component of a template document according to a document format standard definition; the document storage component is used to store document content, and the style definition component is used to store document style; traversing the nodes of the HTML node tree, mapping the nodes to the document storage component to obtain a document storage structure under the document format standard definition, and mapping the nodes to the style definition component to obtain a document style structure under the document format standard definition; generating an XML document under the document format standard definition based on the document storage structure and the document style structure, and processing the template document according to the XML document to obtain a target document.

[0138] In one embodiment, when a computer program is executed by a processor, the computer program parses HTML content in a rich text editor to obtain an HTML node tree, including: identifying the HTML content in the rich text editor to obtain HTML tags; HTML tags are used to represent HTML elements in the HTML content; an HTML node tree is constructed according to the HTML tags; each node in the HTML node tree represents an HTML tag.

[0139] In one embodiment, when a computer program is executed by a processor, the steps involved in mapping nodes to document storage components to obtain a document storage structure defined under a document format standard include: converting HTML elements represented by HTML tags corresponding to nodes into XML elements defined under a document format standard according to a preset first mapping rule; and serializing all converted XML elements according to the structure of an HTML node tree to obtain a document storage structure defined under a document format standard.

[0140] In one embodiment, when a computer program is executed by a processor, the steps involved in mapping a node to a style definition component to obtain a document style structure defined under a document format standard include: for an HTML element having a style attribute, according to a preset second mapping rule, writing the style attribute of the HTML element represented by the HTML tag corresponding to the node into the style definition component, and creating a corresponding style ID to obtain a document style structure defined under the document format standard.

[0141] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented: according to the style ID corresponding to the style attribute, a reference relationship between the XML element in the document storage structure and the style ID is established to represent the first XML style of the XML element through the style ID; for HTML elements with style tags, the style tags are converted into a second XML style defined under the document format standard; for HTML elements with both style attributes and style tags, the first XML style and the second XML style corresponding to the HTML element are merged to obtain the defined style corresponding to the HTML element, and the defined style is written to the corresponding position of the document storage structure.

[0142] In one embodiment, when a computer program is executed by a processor, the processing of a template document according to an XML document to obtain a target document includes: determining a region to be processed in the template document; and replacing the region to be processed with the document content of the XML document to obtain the target document.

[0143] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0144] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0145] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.< / w:pstyle> < / h2>

Claims

1. A document processing method based on rich text data, characterized in that: The method comprises: Parse the HTML content in the rich text editor to obtain the HTML node tree; Determine a document storage component and a style definition component of a template document according to a document format standard definition; the document storage component is used to store document content, and the style definition component is used to store document style; Traversing the nodes of the HTML node tree, mapping the nodes to the document storage component to obtain a document storage structure defined under the document format standard, and mapping the nodes to the style definition component to obtain a document style structure defined under the document format standard; Based on the document storage structure and the document style structure, an XML document defined under the document format standard is generated, and the template document is processed according to the XML document to obtain a target document.

2. The method according to claim 1, characterized in that The HTML content in the rich text editor is parsed to obtain an HTML node tree, including: Recognize the HTML content in the rich text editor to obtain HTML tags; the HTML tags are used to represent HTML elements in the HTML content; An HTML node tree is constructed according to the HTML tag; each node in the HTML node tree represents an HTML tag.

3. The method according to claim 2, characterized in that The step of mapping the node to the document storage component to obtain a document storage structure defined under the document format standard includes: According to a preset first mapping rule, converting the HTML element represented by the HTML tag corresponding to the node into an XML element defined in the document format standard; All converted XML elements are serialized and represented according to the structure of the HTML node tree to obtain a document storage structure defined under the document format standard.

4. The method according to claim 3, characterized in that The step of mapping the node to the style definition component to obtain a document style structure defined under the document format standard includes: For HTML elements with style attributes, according to the preset second mapping rule, the style attribute of the HTML element represented by the HTML tag corresponding to the node is written into the style definition component, and a corresponding style ID is created to obtain the document style structure defined under the document format standard.

5. The method according to claim 4, characterized in that The method further comprises: According to the style ID corresponding to the style attribute, a reference relationship is established between the XML element in the document storage structure and the style ID, so as to represent the first XML style of the XML element through the style ID; For an HTML element having a style tag, converting the style tag into a second XML style defined under the document format standard; For an HTML element having both a style attribute and a style tag, the first XML style and the second XML style corresponding to the HTML element are merged to obtain a defined style corresponding to the HTML element, and the defined style is written to a corresponding position of the document storage structure.

6. The method according to claim 4, characterized in that The step of processing the template document according to the XML document to obtain a target document includes: Determine the area to be processed in the template document; The region to be processed is replaced with the document content of the XML document to obtain a target document.

7. A document processing device based on rich text data, characterized in that: The device comprises: The content parsing module is used to parse the HTML content in the rich text editor to obtain an HTML node tree; A structure determination module, used to determine a document storage component and a style definition component of a template document according to a document format standard definition; the document storage component is used to store document content, and the style definition component is used to store document style; A node mapping module, used for traversing the nodes of the HTML node tree, mapping the nodes to the document storage component, obtaining a document storage structure defined under the document format standard, and mapping the nodes to the style definition component, obtaining a document style structure defined under the document format standard; The document processing module is used to generate an XML document defined under the document format standard based on the document storage structure and the document style structure, and to process the template document according to the XML document to obtain a target document.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • Document content analysis method and device based on structural analysis and program product

    CN120805892A

  • Composite document surgical editing method based on markup language skeleton reservation

    CN122287568A