CN109522018B - Page processing method and device and storage medium - Google Patents

Page processing method and device and storage medium Download PDF

Info

Publication number
CN109522018B
CN109522018B CN201811351835.6A CN201811351835A CN109522018B CN 109522018 B CN109522018 B CN 109522018B CN 201811351835 A CN201811351835 A CN 201811351835A CN 109522018 B CN109522018 B CN 109522018B
Authority
CN
China
Prior art keywords
node
markup language
module
page
template
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811351835.6A
Other languages
Chinese (zh)
Other versions
CN109522018A (en
Inventor
刘致军
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201811351835.6A priority Critical patent/CN109522018B/en
Publication of CN109522018A publication Critical patent/CN109522018A/en
Application granted granted Critical
Publication of CN109522018B publication Critical patent/CN109522018B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/38Creation or generation of source code for implementing user interfaces
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/14Tree-structured documents
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/151Transformation
    • G06F40/154Tree transformation for tree-structured or markup documents, e.g. XSLT, XSL-FO or stylesheets

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Human Computer Interaction (AREA)
  • Document Processing Apparatus (AREA)
  • Stored Programmes (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses a page processing method, a page processing device and a storage medium. The method comprises the following steps: generating a template character string according to the view of the page to be generated; analyzing the template character string to generate a template tree; acquiring the attribute of at least one node in the template tree, and constructing a data structure associated with a data model of a page to be generated according to the attribute of the at least one node; and converting the data structure into a tree structure, generating a first markup language document according to the data model and the tree structure, and generating a page according to the first markup language document. By using the technical scheme, the time efficiency of page development and maintenance and the resource utilization rate of the page processing device can be improved.

Description

Page processing method and device and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a page processing method, an apparatus, and a storage medium.
Background
With the rapid development of internet services, the current web pages are more and more complex, the functions are more and more powerful, and the data volume is gradually increased. Under the circumstance, when web front-end development is carried out, the mode of directly operating the Document Object Model (DOM) is lower and lower, the logic of JavaScript is more and more complex, and the maintenance cost of the website is high.
At present, in order to reduce direct operations on a DOM, a JavaScript logic is used to form a virtual tree in the existing solution, the virtual tree with changed interface data is compared to obtain a difference, and then the interface is adjusted according to the difference. However, since the virtual tree is formed by using JavaScript logic, it takes a long time to develop and maintain the web page. In addition, the time overhead of virtual tree comparison is also large, and even if a comparison mode of loop recursion is used, the processing efficiency is far worse than that of manual modification of the DOM. In view of this, how to improve the time efficiency of page development and maintenance in front-end development is a problem to be solved.
Disclosure of Invention
In view of this, embodiments of the present invention provide a page processing method, a page processing apparatus, and a storage medium, which can improve time efficiency of page development and maintenance and resource utilization rate of the page processing apparatus.
The technical scheme of the invention is realized as follows:
the embodiment of the invention provides a page processing method, which comprises the following steps:
generating a template character string according to the view of the page to be generated;
analyzing the template character string to generate a template tree;
acquiring the attribute of at least one node in the template tree, and constructing a data structure associated with a data model of a page to be generated according to the attribute of the at least one node; and a process for the preparation of a coating,
and converting the data structure into a tree structure, generating a first markup language document according to the data model and the tree structure, and generating the page according to the first markup language document.
An embodiment of the present invention further provides a page processing apparatus, including:
the template module is used for generating a template character string according to the view of the page to be generated;
the analysis module is used for analyzing the template character string generated by the templating module to generate a template tree;
the acquisition module is used for acquiring the attribute of at least one node in the template tree generated by the analysis module;
the building module is used for building a data structure associated with the data model of the page to be generated according to the attribute of the at least one node obtained by the obtaining module;
the transformation module is used for transforming the data structure obtained by the construction module into a tree structure; and a process for the preparation of a coating,
and the generating module is used for generating a first markup language document according to the data model and the tree structure obtained by the converting module, and generating the page according to the first markup language document.
Embodiments of the present invention further provide a computer-readable storage medium storing computer-readable instructions, which can cause at least one processor to execute the method described above.
Compared with the prior art, the method provided by the invention does not depend on fixed grammar and self-defined labels, reduces the learning cost of developers, has flexible grammar and is simpler and more convenient to realize; when the first markup language document is generated, the data structure is converted into a tree structure, so that the page updating speed is improved, and the execution time of codes is reduced; the data structure associated with the data model of the page to be generated is built through the template tree, and the data model is directly connected with the DOM, so that the processing time of the complex page can be greatly shortened, the page development and maintenance efficiency is improved, and the resource utilization rate of the page processing device is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts. Wherein the content of the first and second substances,
fig. 1 is a schematic structural diagram of a web front-end development system according to an embodiment of the present invention;
FIG. 2 is an exemplary flowchart of a page processing method according to an embodiment of the invention;
FIG. 3 is an exemplary flowchart for obtaining attributes of at least one node in a template tree, according to an embodiment of the present invention;
FIG. 4 is an exemplary flow diagram for generating a first markup language document based on a data model and a tree structure, according to one embodiment of the present invention;
FIG. 5 is an exemplary flowchart of a page processing method according to another embodiment of the present invention;
FIG. 6 is an exemplary flow diagram for updating a markup language document according to an embodiment of the present invention;
FIG. 7 is an exemplary flowchart of a page processing method according to yet another embodiment of the present invention;
FIG. 8 is a block diagram of a page processing apparatus according to an embodiment of the present invention;
FIG. 9 is a schematic structural diagram of a page processing apparatus according to another embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The page processing method protected by the embodiment of the invention can be applied to web front-end development, realizes bidirectional data binding of data directly connected with the DOM, and can also be applied to front-end development of an android operating system and an IOS operating system.
Fig. 1 is a schematic structural diagram of a web front-end development system according to an embodiment of the present invention. As shown in fig. 1, the web front-end development system 100 includes a terminal device 101 and a user 102. A browser 103 runs on the terminal device 101, and the browser 103 includes the page processing apparatus 1031 and the user interface 1032 protected by the embodiment of the present application.
According to the embodiment of the present invention, the processing of the front-end page of the web site by the developer using the page processing device 1031 specifically includes: generating a template character string according to the view of the page to be generated; analyzing the template character string to generate a template tree; acquiring the attribute of at least one node in the template tree, and constructing a data structure associated with the data model of the page to be generated according to the attribute of the at least one node; and converting the data structure into a tree structure, and generating a first markup language document according to the data model and the tree structure. The initial page can be obtained by adding the first markup language document to the page to be generated, and then the initial page is displayed on the user interface. Thus, the user can see the page when opening the browser.
According to the embodiment of the present invention, when the data model changes, the update of the page can be quickly realized according to the page processing device 1031. For example, the page processing device 1031 obtains an event triggered by a user through the user interface 1032, and at this time, the data model as the data to be rendered changes, and through the above-mentioned associated data structure, may update the first markup language document to obtain a second markup language document, and then render the second markup language document into an updated page, and display the updated page on the user interface.
The terminal device 101 refers to a terminal device having a data calculation processing function, and includes but is not limited to a smart phone (equipped with a communication module), a palm computer, a tablet computer, and the like. These communication terminals are all installed with an operating system, including but not limited to: the Android operating system, the Symbian operating system, the Windows mobile operating system, and the apple iPhone OS operating system, among others.
FIG. 2 is an exemplary flowchart of a page processing method according to an embodiment of the present invention. The method is applied to the browser. As shown in fig. 2, the method may include the steps of:
step 201, generating a template character string according to a view of a page to be generated.
Step 202, analyzing the template character string to generate a template tree.
Step 203, obtaining the attribute of at least one node in the template tree, and constructing a data structure associated with the data model of the page to be generated according to the attribute of the at least one node.
Step 204, converting the data structure into a tree structure, generating a first markup language document according to the data model and the tree structure, and generating a page according to the first markup language document.
Each step is described in detail below.
In step 201, a template character string is generated according to a view of a page to be generated. For example, the page to be generated is a user login page. This step may implement "templating", i.e. obtaining a string containing variables and logic. Specifically, the template string includes a script language statement and a markup language statement.
In the embodiment of the invention, a JavaScript language is used as a script language for page development, and the markup language is a hypertext markup language (HTML). Then, the generated template string is a mixed code including a JavaScript statement and an HTML statement. Because any JavaScript statement can be written in the template character string, the limitation that only fixed tags and grammar can be used in the prior art can be solved, and the efficiency of page development is improved.
Considering that it is difficult to distinguish JavaScript statements in a template string from output variables using an existing regular expression, in an embodiment of the present invention, when generating a template string according to a view of a page to be generated, the method specifically includes: setting a first identifier for marking a scripting language statement; the second identifier is set for marking the output variable when using the markup language statement.
In a specific application, the first identifier is <% >, and a JavaScript statement is written by adopting the syntax of <% >, for example, a <% if (name) {% > < span > name cannot be null < span > <% >. The second identifier is { }, and is used for identifying an output variable, such as < span > { { name } } span >, which indicates that a name is output in the span. By means of the distinguishing, the JavaScript statements in the virtual tree have corresponding DOM, and the output variables can be analyzed into attribute changes of the virtual tree.
For example, in the following HTML code, a tag div is defined, where the output variables class _ name and name are represented using { } } and JavaScript statements are represented using <% >.
Figure BDA0001865067710000051
In step 202, the template string is parsed to generate a template tree. Since the template character string in step 201 includes the script language statement and the markup language statement, the parsed template tree includes the script language statement and the DOM tree.
For example, the template string (referred to as tplHtml) is parsed using the getDomTree function as follows, resulting in a template tree (referred to as "root.
Figure BDA0001865067710000052
Thus, the code in the tag div is parsed into 3 nodes, and the obtained template tree is as follows:
▼Nodelist(3)[text,p.{{class_name}},text]
Figure BDA0001865067710000053
0:text
Figure BDA0001865067710000054
1:p.{{class_name}}
Figure BDA0001865067710000055
2:text
length:3
wherein, text nodes indicated by text are described by JavaScript codes. When the template character string including the JavaScript statement is parsed, a native Application Program Interface (API) in the JavaScript can be used, complex syntax analysis is not required, and the attribute of the DOM, that is, the value of the node, can be directly obtained.
In step 203, the attribute of at least one node in the template tree is obtained, and a data structure associated with the data model of the page to be generated is constructed according to the attribute of the at least one node.
FIG. 3 is an exemplary flowchart for obtaining attributes of at least one node in a template tree according to an embodiment of the present invention. As shown in fig. 3, the method comprises the following steps:
step 2031, traverse the template tree to obtain at least one node.
In a specific application, the template tree may be recursively traversed by using a depth-first method to obtain each node in the template tree. For example, child nodes of the tree are fetched with dom.
Step 2032, classifying the traversed at least one node, and determining whether each node is a text node.
In this step, the type of each node is determined, and whether the node is a text node is judged according to the type. If yes, go to step 2033, otherwise go to step 2034. In a specific application, the node type can be returned by using the nodeType to judge. When the type of a returned node is 3, determining that the node is a text node; otherwise, it is a non-text node.
Step 2033, when a node is determined to be a text node, analyzing the sentence of the text node according to the syntax of the scripting language, and obtaining at least one attribute name of the text node and an expression corresponding to the attribute name.
In this step, for a text node, the label and attribute of the text node are obtained. And carrying out JavaScript syntax analysis on the attributes, judging whether the analyzed result is a JavaScript expression, and if so, determining which attributes are contained and what type of expression each attribute belongs to.
The expression corresponds to at least one script instruction when parsed. When the expression is analyzed, a script template of each script instruction is preset; and aiming at each script instruction, matching the sentences of the text nodes according to the script template of the script instruction to obtain an expression corresponding to the script instruction.
Specifically, when analyzing the JavaScript code of the text node, a corresponding use method, that is, a script template, needs to be set for each script instruction. Table 1 is an example of a script instruction, including the names, meanings, and corresponding script templates of a plurality of script instructions. Wherein the three instructions v _ if, v _ elif, v _ else are analyzed with regular matching and finally end with { end. v _ if is associated with v _ elif, when "} else {" is found in the JavaScript statement, it indicates that the previous if is paired with the current else, so that the condition of the DOM behind the else is resolved to the inverse of the previous if value, i.e., negated.
Figure BDA0001865067710000071
Table 1 script instruction example
For the instruction of each, since each represents one or more nodes, the method is similar to v _ if during analysis, but the two structures of each and for are analyzed respectively. In this regard, the script templates are set as follows:
Figure BDA0001865067710000072
furthermore, the bind instruction is written in the attr field when there is a property at the beginning of the bind in the property (e.g., a mouse event such as a bindtap click, bindinput form entry, bindnoseup, etc.) because it is to be added to the property.
Step 2034, when a node is determined to be a non-text node, the label and attribute of the non-text node are read from the template tree.
For example, if the type of the node returned using nodeType is not 3, then the node is determined to be a non-text node. The non-text node is analyzed by HTML syntax, and the tag (tagName) and the attribute (attributes) of the non-text node can be obtained.
In this way, in step 203, a data structure associated with the data model of the page to be generated is built according to the properties of at least one node, which data structure connects the data model and the DOM directly, hence also referred to as a direct data structure.
In an embodiment of the present invention, a specific method for constructing the data structure includes: constructing an element for each text node in a data structure; in this element, a field associated with the data model is constructed using the attribute name of the text node as a key (key), and using the expression corresponding to the attribute name and the script instruction corresponding to the expression as values (value). The relationship between the script instruction and the expression is also a combination of key values, that is, the script instruction is used as a key and the expression is used as a value.
That is, the attribute of the text node is written into the associated field in a manner of a double-layer key (key). When data in the data model changes, the data can be associated to the corresponding node through the attribute, so that the direct connection between the data and the DOM is realized, and therefore, the fields can also be called direct connection relation fields.
For example, the established data structure is a data array domArr, wherein in a text node labeled "p", the constructed direct connection relation field is a relation field, and includes 2 attributes: one is that key is the attribute name ", and value includes: a script instruction v _ if, an expression "$ { name }"; script instruction innerText, expression "name: $ name } "; secondly, the key is an attribute name "class _ name", and the value includes: script instructions attr, the expression "{ ' class ' $ { class _ name } ' }.
Figure BDA0001865067710000081
For another example, when the script instruction is "eat", the constructed relation field is as follows, where key is the attribute name "data", and value includes: script instruction each, expression "arr: 'data', index: 'index', item: 'value'.
Figure BDA0001865067710000091
In step 204, the data structure is converted to a tree structure, a first markup language document is generated from the data model and the tree structure, and a page is generated from the first markup language document.
In this step, the data structure is converted into a tree structure when the first markup language document is generated. And rendering the generated first markup language document to generate a required page.
Specifically, when an HTML document is generated, the data structure is converted to a DOM. For example, the transformation method is to virtualize a root node of a root, and transform the input data structure data into a tree structure root by using a getTree function, as shown in the following code.
Figure BDA0001865067710000092
Figure BDA0001865067710000101
Thus, the generated tree structure is as follows, and it can be seen that the direct connection relationship field relationship is included in the tree structure.
Figure BDA0001865067710000102
FIG. 4 is an exemplary flow diagram for generating a first markup language document based on a data model and a tree structure, according to one embodiment of the invention. As shown in fig. 4, a recursive method is used, which includes the following steps:
step 401, generating elements in the HTML document according to the tag of the node in the tree structure.
For example, in the following code example regarding a render function, an element, i.e., a statement var el ═ document.
Step 402, add the updated domId to the attribute.
Step 403, add static attributes.
By static attribute is meant a fixed value set for a node in the tree structure. These fixed values are the basic contents of the node attributes, and dynamic attributes are added by dynamically setting variables on this basis. In the following code, the setAttribute function is used to set the static properties of a node.
Step 404, process the relation of direct connection field relation.
The direct connection relation field comprises an attribute name, a script instruction and an expression. And running each script instruction to obtain a running result. Specifically, v _ if, v _ elif and v _ else, if false, returning directly; InnerHTML, using a template string $ { }; for each, elements may be added in a loop based on the length of the array, where domid is set to "$ { domid } _$ { index }", to identify the elements. Therefore, when the page is updated, the element to be updated in the DOM can be found as long as the index of the changed element in the array is known.
At step 405, the sub-elements are recursively processed.
When the element generated in step 401 is a parent element including a plurality of child elements, recursive processing may be performed on each child element using a forEach instruction, as shown in the following code.
Figure BDA0001865067710000111
Figure BDA0001865067710000121
The final generated HTML document refers to the returned doc. And rendering the doc to obtain an initial page, and displaying the initial page on a user interface of the browser.
In the above embodiment, the template character string is generated according to the view of the page to be generated, the template character string is analyzed, the template tree is generated, the attribute of at least one node in the template tree is obtained, the data structure associated with the data model of the page to be generated is constructed according to the attribute of the at least one node, the data structure is converted into the tree structure, and the first markup language document is generated according to the data model and the tree structure, so that the following technical effects can be obtained:
1) because any JavaScript statement is written in the template character string, the method does not depend on fixed grammar and self-defined labels and does not need to manually synthesize a virtual tree, thereby reducing the learning cost of developers, having flexible grammar and being simpler and more convenient to realize.
2) When the first markup language document is generated, the data structure is converted into a tree structure, and the advantage is that when the DOM is updated, the one-dimensional array structure is easy to operate and search; when the HTML document is generated, the tree structure is easier to generate, so that the page updating speed is improved, and the execution time of codes is reduced.
3) The data structure associated with the data model of the page to be generated is built through the template tree, and the data model is directly connected with the DOM, so that the binding can greatly shorten the processing time of the complex page, improve the processing efficiency and simultaneously improve the resource utilization rate of the page processing device.
Fig. 5 is an exemplary flowchart of a page processing method according to another embodiment of the present invention. As shown in fig. 5, based on the step shown in fig. 2, after the page generated in step 204 is the initial page, the method further includes the following steps:
step 501, monitoring whether the data model changes.
And monitoring whether the data in the data model is used for rendering the page, and if the data is changed, updating the DOM to further update the displayed initial page.
In an embodiment of the invention, the defineProperty function may be used to listen for changes in properties in the data model. Specifically, set methods in attributes are listened to. set acts as a rewriter of attributes, and this set method is automatically invoked once an attribute is reassigned.
In another embodiment of the invention, the setData function can be used, the DOM is updated when the attribute is set, and the manual calling is used, so that the execution of the updated page can be effectively reduced.
Step 502, when monitoring that the data model changes, updating the first markup language document according to the data model and the attributes of the nodes in the data structure to obtain a second markup language document, and generating an updated page according to the second markup language document.
And rendering the obtained second markup language document to obtain an updated page.
FIG. 6 is an exemplary flow diagram for updating a markup language document, according to an embodiment of the present invention. As shown in fig. 6, the method comprises the following steps:
step 601, determining the changed data fields in the data model.
For example, in the following code, a key refers to a data field in which a change occurs.
At step 602, a node associated with the attribute of the data field is identified in the data structure.
For example, the attribute of the data field is "name", the data structure is an array domArr (as shown in the following code) including a direct connection field relationship, and the associated node is a node labeled "p".
At step 603, an element in the first markup language document corresponding to the associated node is determined.
For example, by setting the tag to "p", an element corresponding to the tag "p" in the HTML document doc can be determined as an element to be updated.
And step 604, assigning the element again according to the changed data field value to obtain a second markup language document.
For example, the value of the data field is represented by value, and the value of the element is re-assigned through the getValue function, so that the element is updated, and a new HTML document is obtained.
Figure BDA0001865067710000141
Through the embodiment, when the data model changes, the HTML element to be updated can be determined through the constructed data structure associated with the data model of the page to be generated, and therefore the page can be updated quickly.
Fig. 7 is an exemplary flowchart of a page processing method according to still another embodiment of the present invention. As shown in fig. 7, on the basis of fig. 2, the method further includes the following steps:
step 701, acquiring an event triggered in a view of a page to be generated.
Such events (events) are, for example, click events, input events, and the like.
Step 702, updating the first markup language document according to the attributes and events of the nodes in the data structure to obtain a second markup language document, and generating an updated page according to the second markup language document.
Determining a node associated with the event in the data structure according to a binding instruction preset in the attribute of the node; determining an element in the first markup language document corresponding to the associated node; and calling an event processing function corresponding to the event to process the event to obtain a second markup language document. And rendering the obtained second markup language document to obtain an updated page.
For example, the binding instruction is the bind instruction given in table 1 above, and the bind instruction is written in the attribute attr field of the node in the data structure. Then the bind instruction is found in the data structure, thereby determining the node where the bind instruction is located.
According to the method and the device for updating the HTML, the interface is changed due to the generation of the event, when the event is triggered, the triggered event is led into the HTML through the constructed direct connection data structure, and therefore updating based on the event is achieved.
Fig. 8 is a schematic structural diagram of a page processing apparatus 800 according to an embodiment of the present invention, which is applied to a browser. The page processing apparatus 800 includes:
the templating module 810 is configured to generate a template character string according to a view of a page to be generated;
the parsing module 820 is configured to parse the template character string generated by the templating module 810 to generate a template tree;
an obtaining module 830, configured to obtain an attribute of at least one node in the template tree generated by the parsing module 820;
a constructing module 840, configured to construct a data structure associated with the data model of the page to be generated according to the attribute of the at least one node obtained by the obtaining module 830;
a conversion module 850, configured to convert the data structure obtained by the construction module 840 into a tree structure; and a process for the preparation of a coating,
and a generating module 860 for generating the first markup language document according to the data model and the tree structure obtained by the converting module 850, and generating a page according to the first markup language document.
In an embodiment of the present invention, the template string includes a script language statement and a markup language statement, and the templating module 810 is configured to set a first identifier for marking the script language statement; the second identifier is set for marking the output variable when using the markup language statement.
In an embodiment of the present invention, the obtaining module 830 is configured to traverse the template tree to obtain at least one node; judging whether the at least one node is a text node; when a node is confirmed as a text node, analyzing the sentence of the text node according to the grammar of the script language, and obtaining at least one attribute name of the text node and an expression corresponding to the attribute name.
In an embodiment of the present invention, the page processing apparatus 800 further includes:
a monitoring module 870 for monitoring whether the data model changes;
an updating module 880, configured to update the first markup language document obtained by the generating module 860 according to the data model and the attribute of the node in the data structure obtained by the constructing module 840 when the monitoring module 870 monitors that the data model changes, so as to obtain a second markup language document.
In an embodiment of the present invention, the page processing apparatus 800 further includes:
the monitoring module 870 is configured to obtain an event triggered in a view of a page to be generated;
an updating module 880, configured to update the first markup language document obtained by the generating module 860 according to the attribute of the node in the data structure obtained by the constructing module 840 and the event obtained by the monitoring module 870, to obtain a second markup language document.
Fig. 9 is a schematic structural diagram of a page processing apparatus 900 according to yet another embodiment of the invention. The page processing apparatus 900 includes: a processor 910, a memory 920, a port 930, and a bus 940. The processor 910 and the memory 920 are interconnected by a bus 940. Processor 910 may receive and transmit data through port 930. Wherein the content of the first and second substances,
processor 910 is configured to execute modules of machine-readable instructions stored by memory 920.
Memory 920 stores modules of machine-readable instructions executable by processor 910. The processor 910 may execute instruction modules including: the template module 921, the parsing module 922, the obtaining module 923, the constructing module 924, the converting module 925, and the generating module 926. Wherein the content of the first and second substances,
the templating module 921, when executed by the processor 910, can be: generating a template character string according to the view of the page to be generated;
parsing module 922 when executed by processor 910 may be: analyzing the template character string generated by the templating module 921 to generate a template tree;
the obtaining module 923, when executed by the processor 910, may be: acquiring the attribute of at least one node in the template tree generated by the analysis module 922;
the building module 924 when executed by the processor 910 may be: according to the attribute of at least one node obtained by the obtaining module 923, a data structure associated with the data model of the page to be generated is constructed;
the conversion module 925 when executed by the processor 910 may be: converting the data structure obtained by the construction module 924 into a tree structure;
the generation module 926 when executed by the processor 910 may be: a first markup language document is generated from the tree structure obtained by the data model and conversion module 925 and a page is generated from the first markup language document.
In an embodiment of the present invention, the instruction modules executable by the processor 910 further include: a listening module 927 and an updating module 928, wherein,
the monitoring module 927 may be executed by the processor 910 to monitor whether the data model changes;
when executed by the processor 910, the updating module 928 may be configured to update the first markup language document obtained by the generating module 926 according to the data model and the attribute of the node in the data structure obtained by the constructing module 924 when the monitoring module 927 monitors that the data model changes, so as to obtain a second markup language document.
In another embodiment, the monitoring module 927, when executed by the processor 910, may be configured to obtain an event triggered in a view of a page to be generated;
the updating module 928, when executed by the processor 910, may update the first markup language document obtained by the generating module 926 according to the attribute of the node in the data structure obtained by the constructing module 924 and the event obtained by the monitoring module 927, so as to obtain a second markup language document.
It can thus be seen that the modules of instructions stored in memory 920, when executed by processor 910, perform the various functions of the templating module, parsing module, obtaining module, building module, transforming module, generating module, listening module, and updating module in the various embodiments described above.
In the above device and system embodiments, the specific method for each module and unit to implement its own function is described in the method embodiment, and is not described here again.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each module may exist alone physically, or two or more modules are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
In addition, each of the embodiments of the present invention can be realized by a data processing program executed by a data processing apparatus such as a computer. It is clear that the data processing program constitutes the invention. Further, the data processing program, which is generally stored in one storage medium, is executed by directly reading the program out of the storage medium or by installing or copying the program into a storage device (such as a hard disk and/or a memory) of the data processing device. Such a storage medium therefore also constitutes the present invention. The storage medium may use any type of recording means, such as a paper storage medium (e.g., paper tape, etc.), a magnetic storage medium (e.g., a flexible disk, a hard disk, a flash memory, etc.), an optical storage medium (e.g., a CD-ROM, etc.), a magneto-optical storage medium (e.g., an MO, etc.), and the like.
The invention therefore also discloses a storage medium in which a data processing program is stored which is designed to carry out any one of the embodiments of the method according to the invention described above.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (16)

1. A page processing method is characterized by comprising the following steps:
generating a template character string according to the view of the page to be generated;
analyzing the template character string to generate a template tree;
acquiring the attribute of at least one node in the template tree, and constructing a data structure associated with a data model of a page to be generated according to the attribute of the at least one node; and a process for the preparation of a coating,
converting the data structure into a tree structure, generating a first markup language document according to the data model and the tree structure, and generating the page according to the first markup language document;
wherein the obtaining of the attribute of at least one node in the template tree comprises:
traversing the template tree to obtain the at least one node;
judging whether the at least one node is a text node;
when a node is confirmed as a text node, analyzing sentences of the text node according to grammar of a script language to obtain at least one attribute name of the text node and an expression corresponding to the attribute name, wherein the expression corresponds to at least one script instruction;
the constructing of the data structure associated with the data model of the page to be generated according to the attribute of the at least one node comprises:
constructing an element for each text node in the data structure;
in the element, the attribute name of the text node is used as a key, the expression corresponding to the attribute name and the script instruction corresponding to the expression are used as values, and the field associated with the data model is constructed.
2. The method of claim 1, wherein the template string comprises a scripting language statement and a markup language statement, and wherein generating the template string from the view of the page to be generated comprises:
setting a first identifier for marking the scripting language statement;
setting a second identifier for marking an output variable when using the markup language statement.
3. The method of claim 1, wherein said determining whether the at least one node is a text node comprises:
and determining the type of each node, and judging whether the node is a text node according to the type.
4. The method of claim 1, further comprising:
presetting a script template of each script instruction;
analyzing the sentence of the text node according to the grammar of the script language to obtain at least one attribute name of the text node and an expression corresponding to the attribute name comprises:
and aiming at each script instruction, matching the sentences of the text nodes according to the script template of the script instruction to obtain an expression corresponding to the script instruction.
5. The method of claim 1, further comprising:
and when one node is confirmed to be a non-text node, reading the label and the attribute of the non-text node from the template tree.
6. The method of claim 1, further comprising:
monitoring whether the data model changes or not;
and when monitoring that the data model changes, updating the first markup language document according to the data model and the attributes of the nodes in the data structure to obtain a second markup language document.
7. The method of claim 6, wherein said updating the first markup language document according to the data model and attributes of nodes in the data structure to obtain a second markup language document comprises:
determining changed data fields in the data model;
determining a node in the data structure that is associated with the attribute of the data field;
determining in the first markup language document an element corresponding to the associated node;
and re-assigning the element according to the changed value of the data field to obtain the second markup language document.
8. The method of claim 1, further comprising:
acquiring an event triggered in a view of a page to be generated;
and updating the first markup language document according to the attributes of the nodes in the data structure and the event to obtain a second markup language document.
9. The method of claim 8, wherein said updating the first markup language document based on the attributes of the nodes in the data structure and the event, resulting in a second markup language document comprises:
determining a node associated with the event in the data structure according to a binding instruction preset in the attribute of the node;
determining in the first markup language document an element corresponding to the associated node;
and re-assigning the element according to the processing result of the event to obtain the second markup language document.
10. A page processing apparatus, comprising:
the template module is used for generating a template character string according to the view of the page to be generated;
the analysis module is used for analyzing the template character string generated by the templating module to generate a template tree;
the acquisition module is used for acquiring the attribute of at least one node in the template tree generated by the analysis module;
the building module is used for building a data structure associated with the data model of the page to be generated according to the attribute of the at least one node obtained by the obtaining module;
the transformation module is used for transforming the data structure obtained by the construction module into a tree structure; and a process for the preparation of a coating,
the generating module is used for generating a first markup language document according to the data model and the tree structure obtained by the converting module and generating the page according to the first markup language document;
the obtaining module is configured to traverse the template tree to obtain the at least one node; judging whether the at least one node is a text node; when a node is confirmed as a text node, analyzing sentences of the text node according to grammar of a script language to obtain at least one attribute name of the text node and an expression corresponding to the attribute name, wherein the expression corresponds to at least one script instruction;
the construction module is used for constructing an element for each text node in the data structure; in the element, the attribute name of the text node is used as a key, the expression corresponding to the attribute name and the script instruction corresponding to the expression are used as values, and the field associated with the data model is constructed.
11. The apparatus of claim 10, wherein the template string comprises a scripting language statement and a markup language statement, the templating module to set a first identifier for marking the scripting language statement; setting a second identifier for marking an output variable when using the markup language statement.
12. The apparatus of claim 10, wherein the obtaining module is configured to determine a type of each node, and determine whether the node is a text node according to the type.
13. The apparatus of claim 10, further comprising:
the monitoring module is used for monitoring whether the data model changes or not;
and the updating module is used for updating the first markup language document obtained by the generating module according to the data model and the attribute of the node in the data structure obtained by the constructing module when the monitoring module monitors that the data model changes, so as to obtain a second markup language document.
14. The apparatus of any of claims 10 to 12, further comprising:
the monitoring module is used for acquiring an event triggered in a view of a page to be generated;
and the updating module is used for updating the first markup language document obtained by the generating module according to the attribute of the node in the data structure obtained by the constructing module and the event obtained by the monitoring module to obtain a second markup language document.
15. A computer-readable storage medium having computer-readable instructions stored thereon for causing at least one processor to perform the method of any one of claims 1 to 9.
16. A terminal device comprising a memory and a processor, the memory having stored therein computer-readable instructions which, when executed by the processor, implement the method of any one of claims 1 to 9.
CN201811351835.6A 2018-11-14 2018-11-14 Page processing method and device and storage medium Active CN109522018B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811351835.6A CN109522018B (en) 2018-11-14 2018-11-14 Page processing method and device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811351835.6A CN109522018B (en) 2018-11-14 2018-11-14 Page processing method and device and storage medium

Publications (2)

Publication Number Publication Date
CN109522018A CN109522018A (en) 2019-03-26
CN109522018B true CN109522018B (en) 2021-06-18

Family

ID=65777684

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811351835.6A Active CN109522018B (en) 2018-11-14 2018-11-14 Page processing method and device and storage medium

Country Status (1)

Country Link
CN (1) CN109522018B (en)

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110244955B (en) * 2019-05-29 2023-04-18 广州至真信息科技有限公司 Application processing method, device, server and medium
CN110619096B (en) * 2019-06-12 2022-08-23 北京无限光场科技有限公司 Method and apparatus for synchronizing data
CN110955428A (en) * 2019-11-27 2020-04-03 北京奇艺世纪科技有限公司 Page display method and device, electronic equipment and medium
CN111259286A (en) * 2020-01-14 2020-06-09 上海英方软件股份有限公司 Universal WEB page layout generation device and method
CN111580830B (en) * 2020-05-12 2023-09-15 北京飞漫软件技术有限公司 Binding and parsing method for hypertext markup language document element
CN111563363B (en) * 2020-05-12 2023-08-15 北京飞漫软件技术有限公司 Method for generating and analyzing document content of hypertext markup language
CN111741257B (en) * 2020-05-21 2022-01-28 深圳市商汤科技有限公司 Data processing method and device, electronic equipment and storage medium
CN111857737A (en) * 2020-07-28 2020-10-30 苏州华望信息科技有限公司 Dynamic and static resource separation method based on SysML (SysML) model semantic web system
CN112650435A (en) * 2020-12-23 2021-04-13 平安普惠企业管理有限公司 Page content rolling processing method and device, computer equipment and storage medium
CN113961858A (en) * 2021-10-18 2022-01-21 广州创乐出海科技有限公司 Commodity page updating method and device, computer equipment and storage medium
CN114398578A (en) * 2021-12-23 2022-04-26 网易有道信息技术(北京)有限公司 Method for preprocessing HTML character string and related product
CN117453964B (en) * 2023-10-08 2024-04-30 北京融和云链科技有限公司 Template-based data structure acquisition and target template generation method and device

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104281575A (en) * 2013-07-01 2015-01-14 上海缪思信息科技有限公司 Webpage data obtaining method and template engine
CN108572819A (en) * 2017-12-21 2018-09-25 北京金山云网络技术有限公司 Method for updating pages, device, terminal and computer readable storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10031730B2 (en) * 2015-04-22 2018-07-24 Salesforce.Com, Inc. Systems and methods of implementing extensible browser executable components

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104281575A (en) * 2013-07-01 2015-01-14 上海缪思信息科技有限公司 Webpage data obtaining method and template engine
CN108572819A (en) * 2017-12-21 2018-09-25 北京金山云网络技术有限公司 Method for updating pages, device, terminal and computer readable storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于jQuery框架的前端模板引擎的研究与实现;刘烈毅;《中国优秀硕士学位论文全文数据库》;20170315;第8、39-42页 *

Also Published As

Publication number Publication date
CN109522018A (en) 2019-03-26

Similar Documents

Publication Publication Date Title
CN109522018B (en) Page processing method and device and storage medium
US8572494B2 (en) Framework for development and customization of web services deployment descriptors
WO2018082562A1 (en) Method and device for compiling page data and rendering page, and storage medium
US8423978B2 (en) Configurable java server pages processing framework
CN111045678A (en) Method, device and equipment for executing dynamic code on page and storage medium
CN109144567B (en) Cross-platform webpage rendering method and device, server and storage medium
CN113126990B (en) Page development method, device, equipment and storage medium
CN111831384B (en) Language switching method, device, equipment and storage medium
US20170111431A1 (en) Methods for transforming a server side template into a client side template and devices thereof
WO2022142743A1 (en) Visualized page rendering method, device, equipment, and storage medium
CN112148356B (en) Document generation method, interface development method, device, server and storage medium
CN110333863A (en) A kind of method and device for generating, showing the small routine page
CN112463152A (en) Webpage adaptation method and device based on AST
CN113377373A (en) Page loading method and device based on analysis engine, computer equipment and medium
CN114996619A (en) Page display method and device, computer equipment and storage medium
CN110851136A (en) Data acquisition method and device, electronic equipment and storage medium
CN114153459A (en) Interface document generation method and device
CN107766036B (en) Module construction method and device and terminal equipment
US20150169533A1 (en) Server-less HTML Templates
CN111078228A (en) Method and device for converting webpage into small program, server and storage medium
CN113495730A (en) Resource package generation and analysis method and device
US20040221228A1 (en) Method and apparatus for domain specialization in a document type definition
CN113127776A (en) Breadcrumb path generation method and device and terminal equipment
CN110851678A (en) Method and device for crawling data
CN115640279A (en) Method and device for constructing data blood relationship

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant