Virtual label implementation method and device of XML-like structure document and medium

By adding virtual tags to XML structure documents and blocking label differences and nested structures, the problem of translators paying attention to XML structure differences is solved, and the effect of simplifying parsing and improving translation efficiency is achieved.

CN119538867APending Publication Date: 2025-02-28SICHUAN LAN-BRIDGE INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411696465.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

When translating XML structural documents, in the prior art, the tags in the XML structure are not fixed and have nested structures, translators need to pay extra attention to the structural differences of XML, which reduces the quality and efficiency of translation.

Method used

By adding virtual tags, masking the differences and nested structure of the tags to which the text belongs, simplifying the parsing and restoring of XML documents. The specific steps include reading the XML document, recursively traversing to obtain text nodes, deleting and rebinding the text nodes to virtual tags, generating a unique id, and removing the virtual tags after translation.

Benefits of technology

Use virtual tag technology to block the structural differences and nested relationships of XML text nodes, simplifying the parsing and restoration of XML-like structural documents, allowing translators to only pay attention to the content, thereby improving translation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119538867A_ABST
    Figure CN119538867A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of XML (Extensible Markup Language) structure document analysis and restoration, and provides a virtual tag implementation method and device for an XML-like structure document and a medium. According to the method, the difference of labels to which texts belong is shielded in a virtual label mode, a nested structure between XML text nodes is shielded, analysis and reduction processing of all types of XML documents can be simplified, the difference of labels to which texts of XML files with high freedom degrees belong is shielded by using a virtual label technology, and the nested structure is shielded; the translator only needs to pay attention to the content and does not need to pay attention to the structural difference of the content deliberately, so that the translation efficiency is improved, and the problems existing in the prior art are effectively solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of XML structured document parsing and restoration, and in particular, relates to a method, device and medium for realizing a virtual tag of a quasi-XML structured document. Background Art

[0002] An obvious feature of XML-structured documents is that they have a very high degree of freedom, that is, text can exist under any node and can be nested arbitrarily. Therefore, the complexity and degree of freedom of the entire document are very high. In the field of translation, translators only focus on the content to be translated, and do not need to pay attention to the structure of XML. However, in the prior art, due to the fact that the tags in the XML structure are not fixed and have a nested structure in the translation scenario, translators need to pay extra attention to the differences in the XML structure when they come into contact with XML-structured documents, which reduces the translation quality and efficiency. Summary of the invention

[0003] The purpose of the present invention is to provide a method for realizing virtual tags of XML-like structured documents to solve the technical problems existing in the prior art.

[0004] In order to achieve the above object, the technical solution adopted by the present invention is as follows: A method for implementing a virtual tag of a quasi-XML structured document, comprising: (1) Adding a virtual label includes the following steps: (11) Read the XML document of the text to be translated and obtain the rootElement of the Document; (12) Recursively traverse the rootElement of Document, obtain all text nodes, and execute steps (13) to (14) based on all text nodes; (13) Delete the text node from its parent node parentElement, create a virtual tag yyqt, and bind the text node to the current virtual tag yyqt; (14) Bind the virtual tag yyqt to the parent node parentElement and generate a unique id for the virtual tag yyqt; (15) Extract all virtual tags yyqt and add them to the same set, and obtain the text content corresponding to all virtual tags yyqt; (2) Removing virtual labels, including the following steps: (21) Read the XML document of the translated text, obtain all translation information, the translation information includes the unique ID of the virtual tag yyqt, and execute steps (22) to (25) based on all translation information; wherein the translated text is obtained by the translator after translating the text content of (15); (22) Find the corresponding virtual tag yyqt through the unique id in (21), and delete the virtual tag yyqt from the parent node parentElement; (23) Extract the text node in the virtual tag yyqt; (24) Setting the value of the text node in step (23) to the translation to obtain the replaced text node; (25) Bind the replaced text node to the parent node parentElement.

[0005] In one embodiment, the recursive traversal method in (12) is as follows: start traversal from the root node, obtain all nodes under the root node, call the current method cyclically, and pass all nodes under the root node cyclically until all node information is traversed.

[0006] In one embodiment, the reading of the XML document of the text to be translated in (11) and the reading of the XML document of the translated text in (21) are performed using the same reading method.

[0007] In one embodiment, the reading method uses Java's SaxReader framework for reading.

[0008] In order to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium on which a computer program is stored. The computer program is executed by a processor to implement the virtual tag implementation method of the XML-like structured document.

[0009] In order to achieve the above-mentioned purpose, the present invention also provides a virtual tag implementation device for XML-like structured documents, which includes: a processor and a memory; the memory is used to store a computer program; the processor is connected to the memory and is used to execute the computer program stored in the memory, so that the virtual tag implementation device for XML-like structured documents executes the virtual tag implementation method for XML-like structured documents.

[0010] Compared with the prior art, the present invention has the following beneficial effects: The present invention uses virtual tags to shield the differences in tags belonging to texts and shields the nested structures between XML text nodes, which can simplify the parsing and restoration processing of all XML-like documents. The virtual tag technology is used to shield the differences in tags belonging to texts in XML files with a high degree of freedom and shield the nested structures; the translator only needs to focus on the content without deliberately paying attention to the differences in its structure, thereby improving the translation efficiency and effectively solving the problems existing in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 The figure is a flow chart of adding a virtual label in Example 1 of the present invention.

[0012] Figure 2 The figure is a schematic diagram of the process of removing virtual labels in Example 1 of the present invention.

[0013] Figure 3 This is a principle block diagram of Example 3 of the present invention. DETAILED DESCRIPTION

[0014] In order to enable those skilled in the art to have a clearer understanding and knowledge of the present invention, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described below are only used to explain the present invention, and are convenient for understanding. The technical solutions provided by the present invention are not limited to the technical solutions provided by the following embodiments, and the technical solutions provided by the embodiments should not limit the protection scope of the present invention.

[0015] It should be noted that the illustrations provided in the following embodiments are only used to illustrate the basic concept of the present invention in a schematic manner. Therefore, the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the form, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0016] Example 1 like Figure 1 and 2 As shown, this embodiment provides a method for implementing virtual tags in XML-like structured documents. The method uses virtual tag technology to shield the differences in tags belonging to texts in XML files with a high degree of freedom, as well as to shield nested structures. The method is mainly applied to XML structured documents and XML-like structured documents.

[0017] In this embodiment, the virtual tag implementation method of the XML-like structured document includes two parts: adding virtual tags and removing virtual tags, wherein adding virtual tags is applied to the processing of the text to be translated, and removing virtual tags is applied to the processing of the translated text, and the translated text is based on the text to be translated after the virtual tags are added.

[0018] 1. Add virtual tags (11) Reading the XML document of the text to be translated and obtaining the rootElement of the Document; preferably, the method for reading the XML document of the text to be translated adopts the Java SaxReader framework; for those skilled in the art, other adapted XML document reading methods that can achieve the purpose of this step may also be adopted.

[0019] (12) Recursively traverse the rootElement of Document, obtain all text nodes, and execute steps (13) to (14) based on all text nodes, that is, perform steps (13) and (14) on all text nodes. In this embodiment, the recursive traversal method is as follows: start traversal from the root node, obtain all nodes under the root node, call the current method cyclically, and pass all nodes under the root node cyclically until all node information is traversed.

[0020] (13) Delete the text node from its parent node parentElement (abbreviated as parent node p), create a virtual tag yyqt (i.e. yyqt node), and bind the text node to the current virtual tag yyqt.

[0021] (14) Bind the virtual label yyqt to the parent node parentElement and generate a unique id for the virtual label yyqt; the virtual label yyqt in this step refers to the virtual label yyqt processed in step (13), which should be a complete virtual label yyqt.

[0022] (15) Extract all virtual tags yyqt and add them to the same set, and obtain the text content corresponding to all virtual tags yyqt; the text content is included in the virtual tag yyqt.

[0023] After the virtual tags are added, the text content corresponding to the extracted virtual tags is returned to the translator for translation. After the translator completes the translation, the translated text is formed and the document needs to be exported. At this time, the added virtual tag information needs to be removed.

[0024] 2. Remove virtual labels (21) Read the XML document of the translated text and obtain all translation information. The translation information includes the unique ID of the virtual tag yyqt. Based on all the translation information, execute steps (22) to (25); the purpose of obtaining the translation information is to perform value coverage, because in the translation process, the text of the original file needs to be replaced with the corresponding translation, and their correspondence is achieved through the ID. Preferably, the reading method of the XML document of the translated text adopts the Java SaxReader framework to read; for those skilled in the art, other adapted XML document reading methods that can achieve the purpose of this step can also be adopted, and the method should be adapted to the reading method adopted in step (11).

[0025] (22) Find the corresponding virtual tag yyqt (i.e., yyqt node) through the unique id in (21), and delete the virtual tag yyqt from the parent node parentElement; in the process of reading XML, all virtual tags yyqt can be obtained, because the corresponding id is added during the parsing process, so the id attribute in the XML node is directly obtained to obtain the id information, and the id is used as the key and the virtual tag yyqt is used as the value to store it in a hash table. In subsequent processing, the virtual tag yyqt can be directly obtained through the id.

[0026] (23) Extract the text node in the virtual tag yyqt; (24) Setting the value of the text node in step (23) to the translation, replacing the content of the text node, and obtaining a replaced text node; (25) Bind the replaced text node to the parent node parentElement.

[0027] Complete the processing of all nodes and output the final document.

[0028] By removing the processing flow of virtual tags, the translation is backfilled to the corresponding position, so as to complete the parsing and restoration of the entire XML document.

[0029] Example scenario:

[0030] For example, the above is part of the XML fragment content in an XML document in a certain translation scenario. For the translator, he only needs to know the content that needs to be translated and does not need to care about the structure of the XML. However, the above scenario does not apply. The translator also needs to pay extra attention to the differences in the XML structure.

[0031] Since the tags in the XML structure of the translation scenario are not fixed, the tags are fixed by adding virtual tags (yyqt) to the text content. For example, the XML fragment in the above scenario is changed to:

[0032] A new yyqt tag is added under the tag where the original text is located. This is the introduced virtual tag. Its function is to shield the differences in the tags where the text is located in different XML files and to shield all nested relationships, so that flat extraction can be performed during parsing.

[0033] Example 2 This embodiment provides a computer-readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to implement the method for implementing a virtual tag of a quasi-XML structured document provided in Embodiment 1. A person of ordinary skill in the art can understand that all or part of the steps of implementing the method provided in Embodiment 1 can be completed by hardware related to the computer program, and the above-mentioned computer program can be stored in a computer-readable storage medium, and when the program is executed, the steps of the method provided in Embodiment 1 are executed; and the above-mentioned storage medium includes: ROM, RAM, magnetic disk or optical disk, etc., various media that can store program codes.

[0034] Example 3 like Figure 3 As shown, this embodiment provides a virtual tag implementation device for an XML-like structured document, comprising: a processor and a memory; the memory is used to store a computer program; the processor is connected to the memory, and is used to execute the computer program stored in the memory, so that the virtual tag implementation device for an XML-like structured document executes the virtual tag implementation method for an XML-like structured document provided in Example 1.

[0035] Specifically, the memory includes: ROM, RAM, disk, USB flash drive, memory card or CD and other media that can store program codes.

[0036] Preferably, the processor can be a general-purpose processor, including a central processing unit, a network processor, etc.; it can also be a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component.

[0037] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.

Claims

1. A method for implementing virtual tags in XML-like structured documents, characterized in that: include: (1) Adding a virtual label includes the following steps: (11) Read the XML document of the text to be translated and obtain the rootElement of the Document; (12) Recursively traverse the rootElement of Document, obtain all text nodes, and execute steps (13) to (14) based on all text nodes; (13) Delete the text node from its parent node parentElement, create a virtual tag yyqt, and bind the text node to the current virtual tag yyqt; (14) Bind the virtual tag yyqt to the parent node parentElement and generate a unique id for the virtual tag yyqt; (15) Extract all virtual tags yyqt and add them to the same set, and obtain the text content corresponding to all virtual tags yyqt; (2) Removing virtual labels, including the following steps: (21) Read the XML document of the translated text, obtain all translation information, the translation information includes the unique ID of the virtual tag yyqt, and execute steps (22) to (25) based on all translation information; wherein the translated text is obtained by the translator after translating the text content of (15); (22) Find the corresponding virtual tag yyqt through the unique id in (21), and delete the virtual tag yyqt from the parent node parentElement; (23) Extract the text node in the virtual tag yyqt; (24) Setting the value of the text node in step (23) to the translation to obtain the replaced text node; (25) Bind the replaced text node to the parent node parentElement.

2. The method for implementing virtual tags of XML-like structured documents according to claim 1, characterized in that: The recursive traversal method in (12) is as follows: start traversing from the root node, obtain all nodes under the root node, call the current method cyclically, and pass all nodes under the root node cyclically until all node information is traversed.

3. The method for implementing virtual tags of XML-like structured documents according to claim 2, characterized in that: The same reading method is used for reading the XML document of the text to be translated in (11) and for reading the XML document of the translated text in (21).

4. The method for implementing virtual tags of XML-like structured documents according to claim 3, characterized in that: The reading method adopts the SaxReader framework of Java for reading.

5. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program is executed by a processor to implement the method for implementing a virtual tag of an XML-like structured document as described in any one of claims 1 to 4.

6. A virtual tag implementation device for XML-like structured documents, characterized in that: include: Processor and memory; The memory is used to store computer programs; the processor is connected to the memory and is used to execute the computer program stored in the memory, so that the virtual tag implementation device of the XML-like structured document executes the virtual tag implementation method of the XML-like structured document as described in any one of claims 1 to 4.

Citation Information

Cited By

  • Method and device for realizing conversion from xml tiled structure to nested structure by using prefix tree and medium

    CN122174796A