A method, device, electronic device and storage medium for page rendering

By judging and deleting the element nodes specified in the HTML code generation process, the problem of high maintenance of multiple code branches of software projects is solved, and the requirements of automatically adapting to different operating environments are realized, reducing maintenance difficulty and error rate.

CN115034182BActive Publication Date: 2024-11-01BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110246501.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-05
Publication Date
2024-11-01
Estimated Expiration
2041-03-05

AI Technical Summary

Technical Problem

When a software project is used by multiple customers, multiple code branches are maintained to meet the needs of different operating environments, resulting in high error rate of manual deletion and high maintenance difficulty.

Method used

During the HTML code generation process, we judge whether the attribute information of the element node contains the specified identifier. If it is included, delete the node. The generated DOM tree is used to render the page to meet the needs of different operating environments and avoid manual deletion and multiple Code branch maintenance.

Benefits of technology

It reduces the difficulty of maintaining software project code, reduces manual errors, and automatically deletes unnecessary element nodes according to the operating environment to meet the needs of each customer.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115034182B_ABST
    Figure CN115034182B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a method, device, electronic device and storage medium for page rendering, which relates to the field of computer technology. The method includes: loading the hypertext markup language HTML code of the software project, and in the process of generating the document object model DOM tree through the HTML code, each time an element node is generated, it is determined whether the attribute information of the element node includes the specified identifier corresponding to the current operating environment; if the attribute information of the element node includes the specified identifier, the element node is deleted, and then the page is rendered based on the generated DOM tree. The difficulty of maintenance can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for page rendering. Background Art

[0002] After a software project is standardized, it will be applied to multiple environments. For example, the same software project can be delivered to various customers. In order to meet the needs of each customer, the code of the software project needs to be deleted according to the operating environment of different customers. The current method is to maintain multiple code branches, each code branch corresponds to a customer's operating environment. Before delivering the software project, the code in each code branch can be deleted by switching branches to meet the needs of each user.

[0003] However, when there are more customers, the number of code branches that need to be maintained also increases. The error rate of manually deleting each code branch is high, and the maintenance difficulty is high. Summary of the invention

[0004] The purpose of the embodiments of the present invention is to provide a method, device, electronic device and storage medium for page rendering to reduce the difficulty of maintaining the code of a software project. The specific technical solution is as follows:

[0005] In a first aspect, an embodiment of the present application provides a method for page rendering, comprising:

[0006] Load the Hypertext Markup Language HTML code of the software project;

[0007] In the process of generating a document object model DOM tree through the HTML code, each time an element node is generated, determining whether the attribute information of the element node includes a designated identifier corresponding to the current operating environment;

[0008] If the attribute information of the element node includes the specified identifier, the element node is deleted;

[0009] Render the page based on the generated DOM tree.

[0010] In a possible implementation manner, before determining whether the attribute information of the element node includes a specified identifier, the method further includes:

[0011] In the process of generating the DOM tree through the HTML code, each time a DOM node is generated, determining whether the DOM node is an element node;

[0012] If the DOM node is an element node, executing the step of determining whether the attribute information of the element node includes a specified identifier;

[0013] If the DOM node is not an element node, the DOM node is retained.

[0014] In a possible implementation manner, after determining whether the attribute information of the element node includes a specified identifier, the method further includes:

[0015] If the attribute information of the element node does not include the specified identifier, the element node is retained.

[0016] In a possible implementation manner, deleting the element node includes:

[0017] If the element node includes child nodes, the element node and the child nodes included in the element node are deleted.

[0018] In a possible implementation, the HTML code includes designated identifiers corresponding to a plurality of operating environments. For each operating environment, the designated identifier corresponding to the operating environment is used to indicate that in the operating environment, an element node containing the designated identifier needs to be deleted after being generated.

[0019] In a second aspect, an embodiment of the present application provides a device for page rendering, including:

[0020] A loading module is used to load the Hypertext Markup Language HTML code of the software project;

[0021] A judgment module, used for judging whether the attribute information of each element node generated during the process of generating a document object model DOM tree by the HTML code includes a designated identifier corresponding to the current operating environment;

[0022] A deleting module, configured to delete the element node if the attribute information of the element node includes the designated identifier;

[0023] The rendering module is used to render the page based on the generated DOM tree.

[0024] In a possible implementation, the device further includes: a first reservation module;

[0025] The judgment module is further used to judge whether a DOM node is an element node each time a DOM node is generated during the process of generating the DOM tree through the HTML code; if the DOM node is an element node, then executing the step of judging whether the attribute information of the element node includes a specified identifier;

[0026] The first retaining module is used to retain the DOM node if the DOM node is not an element node.

[0027] In a possible implementation manner, the device further includes:

[0028] The second retaining module is used to retain the element node if the attribute information of the element node does not include the designated identifier.

[0029] In a possible implementation, the deleting module is specifically configured to delete the element node and the child nodes included in the element node if the element node includes child nodes.

[0030] In a possible implementation, the HTML code includes designated identifiers corresponding to a plurality of operating environments. For each operating environment, the designated identifier corresponding to the operating environment is used to indicate that in the operating environment, an element node containing the designated identifier needs to be deleted after being generated.

[0031] In a third aspect, an embodiment of the present invention further provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0032] Memory, used to store computer programs;

[0033] The processor is used to implement any of the above-mentioned page rendering method steps when executing the program stored in the memory.

[0034] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the page rendering method described in the first aspect is implemented.

[0035] In a fifth aspect, an embodiment of the present application further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the page rendering method described in the first aspect above.

[0036] By adopting the above technical solution, the HTML code of the software project can be loaded. In the process of generating a DOM tree based on the HTML code, each time an element node is generated, it is determined whether the attribute information of the element node includes the specified identifier corresponding to the current operating environment. If it does, the element node is deleted, and the page can be rendered according to the generated DOM tree. Because the embodiment of the present application can delete the element node according to the specified identifier, the rendered page meets the requirements of the current operating environment, and there is no need to manually delete the code, and there is no need to maintain multiple code branches of the software project, which reduces the difficulty of maintenance.

[0037] Of course, it is not necessary to achieve all of the advantages described above at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other embodiments can be obtained based on these drawings without paying creative work.

[0039] Figure 1 A flowchart of a page rendering method provided in an embodiment of the present application;

[0040] Figure 2 A schematic diagram of the structure of a page rendering device provided in an embodiment of the present application;

[0041] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0042] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0043] In the process of software project development, if the software project needs to be applied to multiple customers, it is necessary to maintain multiple code branches in the relevant technology to meet the needs of different customers. However, the use of this method will result in a high error rate in code deletion and high maintenance costs. In order to solve this problem, in an embodiment of the present application, a specified identifier can be added to the element nodes that the customer does not need for each customer, so that when the code of the project is run in the operating environment of the customer, the element node carrying the specified identifier is deleted. For developers, it is only necessary to add a specified identifier to the element node, without manually performing code deletion operations, and there is no need to maintain multiple code branches, which reduces the difficulty of maintenance.

[0044] The following is a detailed description of the page rendering method provided in the embodiment of the present application.

[0045] like Figure 1 As shown, the embodiment of the present application provides a method for page rendering, including:

[0046] S101. Loading Hypertext Markup Language (HTML) code of a software project.

[0047] The software project is a software project that has been delivered to the customer by the software developer, and the HTML code of the software project can be loaded when the software is run.

[0048] S102: In the process of generating a Document Object Model (DOM) tree through HTML code, each time an element node is generated, it is determined whether the attribute information of the element node includes a designated identifier corresponding to the current operating environment.

[0049] The designated identifier may be in the form of a character string. For example, the designated identifier may be "isec".

[0050] S103: If the attribute information of the element node includes a designated identifier, the element node is deleted.

[0051] If the attribute information of the element node includes the specified identifier, it means that the element node is not needed by the current client, so the element node is deleted from the DOM tree.

[0052] The element node may also include child nodes in the DOM tree. If the element node includes child nodes, the element node and the child nodes included in the element node are deleted from the DOM tree.

[0053] On the contrary, if the attribute information of the element node does not include the specified identifier, the element node is retained.

[0054] S104: Rendering a page based on the generated DOM tree.

[0055] After the HTML code is parsed, a DOM tree may be generated, and a subsequent page rendering process may be performed based on the DOM tree, thereby displaying the rendered page.

[0056] By adopting the above technical solution, the HTML code of the software project can be loaded. In the process of generating a DOM tree based on the HTML code, each time an element node is generated, it is determined whether the attribute information of the element node includes the specified identifier corresponding to the current operating environment. If it does, the element node is deleted, and the page can be rendered according to the generated DOM tree. Because the embodiment of the present application can delete the element node according to the specified identifier, the rendered page meets the requirements of the current operating environment, and there is no need to manually delete the code, and there is no need to maintain multiple code branches of the software project, which reduces the difficulty of maintenance.

[0057] In another embodiment of the present application, since the DOM nodes included in the DOM tree are not limited to element nodes, after the DOM node is generated, it is necessary to determine the type of the DOM node. Therefore, before determining whether the attribute information of the element node includes the specified identifier, the method further includes:

[0058] In the process of generating a DOM tree through HTML code, each time a DOM node is generated, it is determined whether the DOM node is an element node;

[0059] If the DOM node is an element node, executing the step of determining whether the attribute information of the element node includes a specified identifier;

[0060] If the DOM node is not an element node, the DOM node is retained.

[0061] For example, for a software project, if the software project includes 100 functions, of which client A does not need 10 functions, then the designated identifier corresponding to client A's operating environment is added to the codes corresponding to the 10 functions, such as "abc". Then, when the HTML code corresponding to the software project is run in client A's operating environment, the element node including the designated identifier "abc" can be deleted, so that the 10 functions will not be displayed to client A, thus satisfying client A's needs.

[0062] In an embodiment of the present application, the HTML code includes designated identifiers corresponding to multiple operating environments. For each operating environment, the designated identifier corresponding to the operating environment is used to indicate that in the operating environment, the element node containing the designated identifier needs to be deleted after being generated.

[0063] For another example, for the above software project, if client B does not need 5 of the functions, then the designated identifier corresponding to client B's operating environment is added to the code corresponding to the 5 functions, such as the designated identifier "def". When the HTML code corresponding to the software project is run in client B's operating environment, the element node including the designated identifier "def" can be deleted, so that the 5 functions will not be displayed to client B, thus satisfying client B's needs.

[0064] It can be seen that because the HTML code includes designated identifiers corresponding to multiple operating environments, when the HTML code is run in different operating environments, the element nodes including the designated identifiers corresponding to the operating environment will be automatically deleted, so that the HTML code can meet the needs of various customers. For developers, only one set of HTML code needs to be maintained, and there is no need to maintain code branches or manually delete code, which avoids errors caused by manual code deletion and reduces the difficulty of maintenance.

[0065] Based on the same technical concept, the embodiment of the present application also provides a device for page rendering, such as Figure 2 As shown, the device comprises:

[0066] A loading module 201 is used to load the hypertext markup language HTML code of the software project;

[0067] The judging module 202 is used to judge whether the attribute information of each element node includes the designated identifier corresponding to the current operating environment during the process of generating the document object model DOM tree through HTML code;

[0068] A deletion module 203, configured to delete an element node if the attribute information of the element node includes a specified identifier;

[0069] The rendering module 204 is used to render the page based on the generated DOM tree.

[0070] Optionally, the device further comprises: a first retention module;

[0071] The judgment module 202 is also used to judge whether a DOM node is an element node each time a DOM node is generated during the process of generating a DOM tree through HTML code; if the DOM node is an element node, then the step of judging whether the attribute information of the element node includes a specified identifier is executed;

[0072] The first retaining module is used to retain the DOM node if the DOM node is not an element node.

[0073] Optionally, the device further comprises:

[0074] The second retaining module is used to retain the element node if the attribute information of the element node does not include the specified identifier.

[0075] Optionally, the deleting module 203 is specifically configured to delete the element node and the child nodes included in the element node if the element node includes child nodes.

[0076] The HTML code includes designated identifiers corresponding to a plurality of operating environments. For each operating environment, the designated identifier corresponding to the operating environment is used to indicate that in the operating environment, an element node including the designated identifier needs to be deleted after being generated.

[0077] By adopting the above technical solution, the HTML code of the software project can be loaded. In the process of generating a DOM tree based on the HTML code, each time an element node is generated, it is determined whether the attribute information of the element node includes the specified identifier corresponding to the current operating environment. If it does, the element node is deleted, and the page can be rendered according to the generated DOM tree. Because the embodiment of the present application can delete the element node according to the specified identifier, the rendered page meets the requirements of the current operating environment, and there is no need to manually delete the code, and there is no need to maintain multiple code branches of the software project, which reduces the difficulty of maintenance.

[0078] The embodiment of the present invention further provides an electronic device, such as Figure 3As shown, it includes a processor 301, a communication interface 302, a memory 303 and a communication bus 304, wherein the processor 301, the communication interface 302, and the memory 303 communicate with each other through the communication bus 304.

[0079] Memory 303, used for storing computer programs;

[0080] The processor 301 is used to execute the program stored in the memory 303 to implement the following steps:

[0081] Load the HTML code of the software project;

[0082] In the process of generating the DOM tree through HTML code, each time an element node is generated, it is determined whether the attribute information of the element node includes the specified identifier corresponding to the current operating environment;

[0083] If the attribute information of the element node includes the specified identifier, the element node is deleted;

[0084] Render the page based on the generated DOM tree.

[0085] The processor 301 is also used to implement other method steps in the above method embodiment, and reference may be made to the relevant description in the method embodiment.

[0086] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0087] The communication interface is used for communication between the above electronic device and other devices.

[0088] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0089] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0090] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned page rendering methods are implemented.

[0091] In another embodiment of the present invention, a computer program product including instructions is provided, which, when executed on a computer, enables the computer to execute any of the page rendering methods in the above embodiments.

[0092] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0093] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0094] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, electronic device and medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.

[0095] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A method for page rendering, characterized in that: include: Loading a hypertext markup language HTML code of the software project; the HTML code includes designated identifiers corresponding to a plurality of operating environments, and for each operating environment, the designated identifier corresponding to the operating environment is used to indicate that in the operating environment, an element node containing the designated identifier needs to be deleted after being generated; In the process of generating a document object model DOM tree through the HTML code, each time an element node is generated, determining whether the attribute information of the element node includes a designated identifier corresponding to the current operating environment; If the attribute information of the element node includes the specified identifier, the element node is deleted; Render the page based on the generated DOM tree; Before determining whether the attribute information of the element node includes a specified identifier, the method further includes: In the process of generating the DOM tree through the HTML code, each time a DOM node is generated, determining whether the DOM node is an element node; If the DOM node is an element node, executing the step of determining whether the attribute information of the element node includes a specified identifier; If the DOM node is not an element node, the DOM node is retained.

2. The method according to claim 1, characterized in that After determining whether the attribute information of the element node includes a specified identifier, the method further includes: If the attribute information of the element node does not include the specified identifier, the element node is retained.

3. The method according to claim 1, characterized in that Deleting the element node includes: If the element node includes child nodes, the element node and the child nodes included in the element node are deleted.

4. A device for page rendering, characterized in that: include: A loading module, used to load the hypertext markup language HTML code of the software project; the HTML code includes designated identifiers corresponding to a plurality of operating environments, and for each operating environment, the designated identifier corresponding to the operating environment is used to indicate that in the operating environment, an element node containing the designated identifier needs to be deleted after being generated; A judgment module, used for judging whether the attribute information of each element node generated during the process of generating a document object model DOM tree by the HTML code includes a designated identifier corresponding to the current operating environment; A deleting module, configured to delete the element node if the attribute information of the element node includes the designated identifier; The rendering module is used to render the page based on the generated DOM tree; The device also includes: a first retention module; The judgment module is further used to judge whether a DOM node is an element node each time a DOM node is generated during the process of generating the DOM tree through the HTML code; if the DOM node is an element node, then executing the step of judging whether the attribute information of the element node includes a specified identifier; The first retaining module is used to retain the DOM node if the DOM node is not an element node.

5. The device according to claim 4, characterized in that The device also includes: The second retaining module is used to retain the element node if the attribute information of the element node does not include the designated identifier.

6. The device according to claim 4, characterized in that The deleting module is specifically used to delete the element node and the child nodes included in the element node if the element node includes child nodes.

7. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 3 when executing a program stored in a memory.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 3 are implemented.