An XML document processing method, device, electronic device and storage medium

By labeling metadata on the class template document and generating mapping tables, the duplicate encoding problem in complex XML document analysis is solved, efficient and accurate attribute analysis is achieved, and development efficiency is improved.

CN114253548BActive Publication Date: 2025-07-11HANYUN TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111461261.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-03
Publication Date
2025-07-11
Estimated Expiration
2041-12-03

AI Technical Summary

Technical Problem

The prior art is prone to errors when parsing complex multi-layer nested XML documents, requiring developers to write a lot of duplicate code, and it is difficult to efficiently handle property mapping in XML documents.

Method used

By obtaining the XML document and attributes to be parsed, determining the class template document and labeling metadata on it, generating a metadata mapping table, and using metadata to parse attributes to obtain entity class objects to avoid duplicate encoding.

Benefits of technology

It improves the coding efficiency of developers and has high adaptability, reduces the repetitive workload of developers when parsing complex XML documents, and improves the accuracy and efficiency of analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114253548B_ABST
    Figure CN114253548B_ABST
Patent Text Reader

Abstract

The present application provides an XML document processing method, apparatus, electronic device, and storage medium. Obtain a to-be-parsed XML document and at least one to-be-parsed attribute in the to-be-parsed XML document; determine whether there is a corresponding class template document for the to-be-parsed attribute, and if so, annotate the class template document; for each to-be-parsed attribute, determine whether there is a corresponding metadata in the annotation of the class template document corresponding to the to-be-parsed attribute; if so, perform parsing based on the corresponding metadata to obtain an entity class object corresponding to the to-be-parsed attribute, so as to provide a parsing method for dealing with complex multi-layer nested XML and improve the coding efficiency of developers.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of document parsing. Specifically, it relates to a method, device, electronic device, and storage medium for processing XML documents. Background Art

[0002] In the prior art, XML is widely used as an extensible markup language. For XML parsing, one existing method is as follows: By defining attribute annotations, a mapping relationship between entity class attributes and the required attributes in the XML document is established. Using the reflection principle, the corresponding attribute values in the XML are parsed and assigned to the entity class. This method is prone to errors when finding the corresponding paths of entity class attributes. In practical applications, some of the attributes to be extracted in the XML are placed in the attributes of the tags, and some are placed in the Text between two tags. Moreover, the XML nesting level reaches more than 5 levels, and the same attributes exist in large quantities in the same XML document. It is difficult to cope with the parsing of such complex XML documents by the above method, and developers need to edit a lot of repetitive code. Therefore, there is an urgent need for a parsing method for dealing with complex multi-level nested XML documents. Summary of the Invention

[0003] In view of this, the purpose of this application is to provide a method, device, electronic device, and storage medium for processing XML documents, which is used to provide a parsing method for dealing with complex multi-level nested XMLs, so as to improve the coding efficiency of developers.

[0004] In a first aspect, an embodiment of this application provides a method for processing an XML document, including:

[0005] Obtain the XML document to be parsed and at least one attribute to be parsed in the XML document to be parsed; determine whether there is a corresponding class template document for the attribute to be parsed. If so, annotate the class template document; for each attribute to be parsed, determine whether there is corresponding metadata in the annotation of the class template document corresponding to the attribute to be parsed. If so, perform parsing based on the corresponding metadata to obtain the entity class object corresponding to the attribute to be parsed.

[0006] Preferably, the corresponding class template document for the attribute to be parsed is determined by the following method: for each attribute to be parsed, determine the root attribute node corresponding to the attribute to be parsed; determine the full path name of the corresponding entity class according to the root attribute node; match the corresponding class template document according to the full path name of the entity class corresponding to the root attribute node.

[0007] Preferably, the class template document is annotated in the following manner: determining metadata of the same class as the class template document according to the XML document to be parsed; matching the attributes of each metadata in the metadata with the attributes in the class template document, and generating a corresponding metadata mapping table, where the key of the metadata mapping table is the class name of the class template document, and the key value of the metadata mapping table is the metadata information corresponding to the class name; wherein, the metadata information includes the position of the metadata in the class template document, the class name corresponding to the metadata, and the metadata attribute mapping table.

[0008] Preferably, the key of the metadata attribute mapping table is each metadata attribute in the metadata, and the key value is the metadata parsing information for parsing the metadata attribute, wherein the metadata parsing information includes the full path name of the metadata attribute, the parsing position of the metadata attribute, and the additional attributes of the metadata attribute, and the additional attributes of the metadata are at least one of the child node attributes of the metadata attribute.

[0009] Preferably, the full path name of the metadata is determined in the following manner: determining the metadata attribute as the target attribute node; determining the class name corresponding to the metadata attribute as the root attribute node; determining at least one attribute node on the path from the root attribute node to the target attribute node, and concatenating them in sequence to generate the full path name of the metadata.

[0010] Preferably, the entity class object includes a target class name, multiple target attributes, and target attribute values corresponding to the target attributes. The entity class object corresponding to the attribute to be parsed is obtained in the following manner: determining the class name of the class template document corresponding to the attribute to be parsed as the target class name; for each attribute to be parsed, determining the metadata attribute corresponding to the attribute to be parsed; determining the attribute to be parsed and the additional attributes of the metadata attribute corresponding to the attribute to be parsed as multiple target attributes; according to the metadata attribute mapping table, determining the target attribute value corresponding to each target attribute.

[0011] Preferably, the target attribute value corresponding to each target attribute is determined in the following manner: obtaining the parsing position of the corresponding metadata attribute according to the metadata attribute corresponding to the target attribute; determining the target attribute value corresponding to the target attribute according to the parsing position of the metadata attribute.

[0012] In a second aspect, an XML document processing apparatus provided by an embodiment of the present application further includes:

[0013] An acquisition module, configured to acquire an XML document to be parsed and at least one attribute to be parsed in the XML document to be parsed;

[0014] A marking module, configured to determine whether there is a corresponding class template document for the attribute to be parsed, and if so, mark the class template document;

[0015] A judgment module, configured to determine, for each attribute to be parsed, whether there is corresponding metadata in the annotation of the class template document corresponding to the attribute to be parsed;

[0016] An analysis module, configured to, if there is, perform analysis based on the corresponding metadata to obtain an entity class object corresponding to the attribute to be parsed.

[0017] In a third aspect, an embodiment of the present application further provides an electronic device, including: a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the memory through the bus, and the processor executes the machine-readable instructions to perform the steps of the XML document processing method as described above.

[0018] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, it performs the steps of the XML document processing method as described above.

[0019] An XML document processing method, device, electronic device, and storage medium provided by an embodiment of the present application. By obtaining an XML document to be parsed and at least one attribute to be parsed in the XML document to be parsed, determining a matching class template document according to the attribute to be parsed, and annotating the metadata of the attribute to be parsed in the corresponding class template document, these steps can be completed during program initialization. When parsing the attribute to be parsed, for each data to be parsed, it is possible to determine the metadata annotated in the class template document and perform parsing on the attribute to be parsed based on the metadata to obtain an entity class object corresponding to the attribute to be parsed, realizing that the attributes to be parsed of the same type can share a class template document, avoiding repeated coding by developers, improving the coding efficiency of developers, and having high adaptability.

[0020] To make the above objects, features, and advantages of the present application more obvious and understandable, the following specifically enumerates preferred embodiments and, in conjunction with the accompanying drawings, makes a detailed description as follows. Description of the Drawings

[0021] To more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required in the embodiments. It should be understood that the following drawings only show some embodiments of the present application and should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.

[0022] Figure 1 A flowchart of an XML document processing method provided by an embodiment of the present application;

[0023] Figure 2A flowchart of steps for obtaining an entity class object corresponding to an attribute to be parsed provided by an embodiment of the present application;

[0024] Figure 3 A schematic structural diagram of an XML document processing device provided by an embodiment of the present application;

[0025] Figure 4 A schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners

[0026] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. It should be understood that the accompanying drawings in the present application are only for the purposes of illustration and description, and are not used to limit the protection scope of the present application. In addition, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in the present application illustrate operations implemented according to some embodiments of the present application. It should be understood that the operations in the flowchart may not be implemented in sequence, and steps without a logical context relationship may be reversed or implemented simultaneously. In addition, those skilled in the art may add one or more other operations to the flowchart or remove one or more operations from the flowchart under the guidance of the content of the present application.

[0027] In addition, the described embodiments are only some embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application usually described and illustrated in the accompanying drawings here may be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application to be protected, but only represents selected embodiments of the present application. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative efforts fall within the protection scope of the present application.

[0028] In the prior art, XML is widely used as an extensible markup language. For XML parsing, an existing method is: by defining attribute annotations, establishing a mapping relationship between entity class attributes and the required attributes in the XML document, and using the reflection principle to parse the corresponding attribute values in the XML and assign them to the entity class. This method is prone to errors when finding the corresponding paths of entity class attributes. In practical applications, some of the attributes to be extracted in part of the XML are placed in the attributes of the tags, and some are placed in the Text between two tags, and the XML nesting level reaches more than 5 layers. The same attributes exist in large quantities in the same XML document. It is difficult to cope with the parsing of such complex XML documents by the above method, and developers need to edit a lot of repetitive code. Therefore, a parsing method for coping with complex multi-level nested XML documents is needed.

[0029] In view of the above problems, embodiments of the present application provide an XML document processing method, apparatus, electronic device, and storage medium, which will be described below through embodiments.

[0030] For ease of understanding of the present application, the technical solutions provided by the present application will be described in detail below in conjunction with specific embodiments.

[0031] Please refer to Figure 1 , which is an XML document processing method provided by an embodiment of the present application. The method includes:

[0032] S101. Obtain an XML document to be parsed and at least one attribute to be parsed in the XML document to be parsed.

[0033] The XML document to be parsed here refers to the XML document that needs to be parsed currently, which can be an XML document newly input by the system for executing the XML document processing method. The attribute to be parsed here is the attribute that wants to be parsed, and the attribute to be parsed is at least one of the attributes existing in the XML document to be parsed. The attribute here can be an element corresponding to each tag in the XML document. For example <code>#{code}< / code> in, <code>and< / code> are the start field and end field of the tag, where code can be an attribute. The user can input the entity class or the attribute in the entity class that he currently wants to extract in the system as the attribute to be parsed. If what the user inputs is an entity class, the attribute to be parsed is all the attributes in the entity class.

[0034] S102. Determine whether there is a corresponding class template document for the attribute to be parsed. If so, mark the class template document.

[0035] The class template document here is a preset template document. All the attributes under an entity class are included in a class template document. That is, different entity classes can have different preset class template documents, which can be distinguished by the class name of the class template document. The class name here is the name of the entity class.

[0036] Specifically, a class template document can be created based on a complex XML document. First, all entity classes in the XML document are determined. For each entity class, all its attributes are determined. All the metadata corresponding to a class is used as a class template document. Here, a mapping can be established between the fully qualified name of the entity class and the class template document, that is, it is explained which entity class this class template document needs to be parsed into. For example, through demo = cn.whitetown.smartxml.demo.entity.DemoSubject, this class template document named demo is parsed into the DemoSubject class. The metadata here refers to the original field data in the XML document. Each class template document includes the original field data corresponding to all the attributes in a class.

[0037] S103. For each attribute to be parsed, determine whether there is corresponding metadata in the annotation of the class template document corresponding to the attribute to be parsed.

[0038] S104. If there is, perform parsing based on the corresponding metadata to obtain the entity class object corresponding to the attribute to be parsed.

[0039] Exemplarily, as shown in the following XML document:

[0040]

[0041] Among them, the class name is Person. This entity class includes five attributes: id, code, tel, birth, and addr. For the attributes id and birth, the parsing positions of the corresponding attribute values are in the tags, while for the attributes code, tel, and addr, the parsing positions of the corresponding attribute values are in the text. These are two different parsing positions.

[0042] Exemplarily, if all the attributes of the Person class are to be parsed at this time, first, the fully qualified name of the Person class needs to be parsed through Java. For example, the parsed fully qualified name can be com.hanclouds.DemoTest, and the corresponding class template document is determined through this fully qualified name. Here, a class template document with the class name Person can be determined. Then, find the metadata of the Person class in the document to be parsed. For each attribute (in this embodiment, it can refer to the above five attributes), determine whether the parsing position of the attribute value in the metadata corresponding to the attribute in the document to be parsed is the same as the parsing position of the attribute value of the attribute in the class template document. If they are the same, it can be determined that this class template document is the class template document corresponding to the attribute to be parsed, and the metadata information corresponding to Person in the XML document to be parsed is marked in this class template document. The metadata information here is used to parse this class (in this embodiment, it can refer to Person). The purpose of marking is to mark the positions of the metadata attributes that need to be parsed in the entity class in the class template document.

[0043] The metadata information can include the position of the metadata in the class template document, the class name corresponding to the metadata, and the metadata attribute mapping table. The position of the metadata in the class template document here can refer to the address of the entity class in this class template document, and the class name corresponding to the metadata here can refer to the class name of this entity class. It can be understood that the class name of the attribute to be parsed and the class name of the class template document are the same.

[0044] Furthermore, if no class template document corresponding to the attribute to be parsed is matched here, a matching failure result needs to be returned for the attribute to be parsed for which the matching fails. Developers can collect the matching failure results in a subsequent stage and update the class template document based on these results, thereby improving the parsing ability of this application for XML documents in different formats.

[0045] Specifically, after determining the class template document corresponding to the attribute to be parsed, based on each attribute to be parsed, determine the metadata attribute corresponding to the attribute to be parsed and the metadata parsing information for parsing this metadata attribute in the class template document corresponding to the attribute to be parsed. And generate the corresponding entity class object according to the metadata parsing information.

[0046] An XML document processing method provided by an embodiment of the present application, by obtaining a to-be-parsed XML document and at least one to-be-parsed attribute in the to-be-parsed XML document, determining a matching class template document according to the to-be-parsed attribute, and annotating the metadata of the to-be-parsed attribute in the corresponding class model document. These steps can be completed during program initialization. When parsing the to-be-parsed attribute, for each to-be-parsed data, the metadata annotated in the class template document can be determined, and the to-be-parsed attribute can be parsed based on the metadata to obtain an entity class object corresponding to the to-be-parsed attribute. It realizes that the to-be-parsed attributes of the same class can share a class template document. In the traditional mode, developers need to manually find the attributes to be parsed, then record them in another document, and then parse them one by one through programming. This solution only needs to annotate the attributes to be parsed in the template document and then automatically realizes the parsing, avoiding the repeated coding of developers and improving the coding frequency of developers.

[0047] In an embodiment of the present application, the metadata information includes the location of the metadata in the class template document, the class name corresponding to the metadata, and the metadata attribute mapping table. Among them, the location of the metadata in the class template document and the class name corresponding to the metadata are both for parsing the metadata, and the metadata attribute mapping table plays an important role in parsing the metadata.

[0048] Among them, the key of the metadata attribute mapping table is each metadata attribute in the metadata, and the key value is the metadata parsing information used to parse the corresponding metadata attribute. The metadata parsing information here includes the full path name of the metadata attribute, the parsing location of the metadata attribute, and the additional attributes of the metadata attribute.

[0049] The full path name of the metadata attribute here refers to the XPath value of the metadata attribute in the XML document. Specifically, the open-source framework Jsoup can be used to parse the annotated class template document to determine all metadata attributes. For one of the metadata attributes, determine the metadata attribute as the target attribute node, determine the class name corresponding to the metadata attribute as the root attribute node, and sequentially search for the parent attribute nodes of the target attribute node until reaching the root attribute node. Concatenate all the attribute nodes on the path in order to finally obtain the full path name of the metadata. Exemplarily, person / addr is the full path name of addr.

[0050] The additional attributes of the metadata attribute here are at least one of the child node attributes of the metadata attribute. Exemplarily, in the tag <id code=001 value=#{personId}>, there may be multiple id tags in the same path, and these tags are distinguished by the value of code. If only the XPath and the parsing position are known, they cannot be distinguished. At this time, it is necessary to record the additional attribute code=001 as the judgment basis during parsing. Here, code is a child node attribute of id.

[0051] Please refer to Figure 2 , which is a flowchart of the steps for obtaining the entity class object corresponding to the attribute to be parsed provided by an embodiment of the present application. The steps specifically include:

[0052] S201. Determine the class name of the class template document corresponding to the attribute to be parsed as the target class name.

[0053] S202. For each attribute to be parsed, determine the metadata attribute corresponding to the attribute to be parsed.

[0054] S203. Determine the attribute to be parsed and the additional attributes of the metadata attribute corresponding to the attribute to be parsed as multiple target attributes.

[0055] S204. According to the metadata attribute mapping table, determine the target attribute value corresponding to each target attribute.

[0056] The entity class object here includes the target class name, multiple target attributes, and the target attribute values corresponding to the target attributes. It can be understood that for the attribute to be parsed, it can be parsed into the corresponding entity class. Therefore, the finally output entity class object includes the class name of the entity class, multiple target attributes under the entity class, and the corresponding target attribute values. For example, when the attribute to be parsed is Person, the finally output entity class object can be obtained through public class Person{private Integer id;private String code;private String tel;private Date birthdayDate;private String addr}. When the attribute to be parsed is id, the finally output entity class object can be obtained through public class Person{private Integer id;private String code}.

[0057] It can be understood that if there are attributes with the same name, it is necessary to record the additional attributes at the same time. The additional attributes and the attributes to be parsed are used as multiple target attributes under the entity class object, and then the target attribute values of each target attribute are parsed to finally obtain the output entity class object. This can avoid parsing deviations caused by attributes with the same name in other positions of the current document to be parsed, and improve the parsing accuracy of this application.

[0058] Specifically, for each target attribute, according to the metadata attribute corresponding to the target attribute, the parsing position of the corresponding metadata attribute is determined. For example, <Person1 id=”#{id1}”>, where id1 is located within the tag, such as <tel>#{tel1}< / tel> the tel of, is located in the text, that is, between the tags. According to the parsing position of the metadata attribute, the target attribute value corresponding to the target attribute is determined. For example, the target attribute value of id is id1, and the target attribute value of tel is tel1.

[0059] In the embodiment of this application, when a new XML needs to be parsed, only the corresponding entity class needs to be defined, and then the metadata information corresponding to the attributes to be parsed is written into the XML template, and then the attributes to be parsed and the corresponding attribute values are automatically parsed. Developers no longer need to care about the complex XML parsing process and do not need to write a large amount of repetitive code for data parsing. The embodiment of this application is particularly suitable for parsing complex multi-layer nested type XML documents into entity classes, without caring about the XPath path information of the attributes to be parsed. As long as simple marking is performed, the parsing can be automatically completed by the program, and the development efficiency is greatly improved.

[0060] Based on the same inventive concept, in the embodiment of this application, an XML document processing device corresponding to the XML document processing method is also provided. Since the principle of solving problems by the XML document processing device in the embodiment of this application is similar to the above XML document processing method in the embodiment of this application, the implementation of the XML document processing device can refer to the implementation of the method, and the repeated parts will not be described again.

[0061] Please refer to Figure 3 , Figure 3 which is a schematic structural diagram of an XML document processing device provided by the embodiment of this application. As Figure 3 shown in, the XML document processing device 300 includes:

[0062] An acquisition module 310, configured to acquire a to-be-parsed XML document and at least one to-be-parsed attribute in the to-be-parsed XML document;

[0063] A marking module 320, configured to determine whether there is a corresponding class template document for the to-be-parsed attribute, and if so, mark the class template document;

[0064] A determination module 330, configured to determine, for each attribute to be parsed, whether there is corresponding metadata in the annotation of the class template document corresponding to the attribute to be parsed;

[0065] A parsing module 340, configured to, if there is, perform parsing based on the corresponding metadata to obtain an entity class object corresponding to the attribute to be parsed.

[0066] In a preferred embodiment, the annotation module 320 is specifically configured to: for each attribute to be parsed, determine a root attribute node corresponding to the attribute to be parsed; determine a full path name of the corresponding entity class according to the root attribute node; and match a corresponding class template document according to the full path name of the entity class corresponding to the root attribute node.

[0067] In a preferred embodiment, the annotation module 320 is specifically configured to: determine metadata of the same class as the class template document according to the XML document to be parsed; match the attributes of each metadata in the metadata with the attributes in the class template document, and generate a corresponding metadata mapping table, where the key of the metadata mapping table is the class name of the class template document, and the key value of the metadata mapping table is the metadata information corresponding to the class name; wherein, the metadata information includes the position of the metadata in the class template document, the class name corresponding to the metadata, and a metadata attribute mapping table.

[0068] In a preferred embodiment, the key of the metadata attribute mapping table is each metadata attribute in the metadata, and the key value is metadata parsing information for parsing the metadata attribute, where the metadata parsing information includes the full path name of the metadata attribute, the parsing position of the metadata attribute, and additional attributes of the metadata attribute, and the additional attributes of the metadata are at least one of the sub-node attributes of the metadata attribute.

[0069] In a preferred embodiment, the annotation module 320 is further configured to: determine the metadata attribute as a target attribute node; determine the class name corresponding to the metadata attribute as a root attribute node; determine at least one attribute node on the path from the root attribute node to the target attribute node, and splice them in order to generate a full path name of the metadata.

[0070] In a preferred embodiment, the entity class object includes a target class name, a plurality of target attributes, and target attribute values corresponding to the target attributes. The parsing module 340 is specifically configured to: determine the class name of the class template document corresponding to the attribute to be parsed as the target class name; for each attribute to be parsed, determine the metadata attribute corresponding to the attribute to be parsed; determine the attribute to be parsed and the additional attributes of the metadata attribute corresponding to the attribute to be parsed as a plurality of target attributes; and determine the target attribute value corresponding to each target attribute according to the metadata attribute mapping table.

[0071] In a preferred embodiment, the parsing module 340 is further configured to: obtain the parsing position of the corresponding metadata attribute according to the metadata attribute corresponding to the target attribute; and determine the target attribute value corresponding to the target attribute according to the parsing position of the metadata attribute.

[0072] Please refer to Figure 4 , Figure 4 , which is a schematic structural diagram of an electronic device provided by an embodiment of the present application. As Figure 4 shown in the figure, the electronic device 400 includes a processor 410, a memory 420, and a bus 430.

[0073] The memory 420 stores machine-readable instructions executable by the processor 410. When the electronic device 400 runs, the processor 410 communicates with the memory 420 through the bus 430. When the machine-readable instructions are executed by the processor 410, the steps of the above XML document processing method can be executed. The specific implementation manner can refer to the method embodiment and will not be elaborated herein.

[0074] An embodiment of the present application further provides a computer-readable storage medium. A computer program is stored on the storage medium. When the computer program is run by a processor, the steps of the above XML document processing method can be executed. The specific implementation manner can refer to the method embodiment and will not be elaborated herein.

[0075] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the above-described systems, devices, and units can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated herein.

[0076] In several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. For another example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some communication interfaces. The indirect coupling or communication connection of devices or units can be in an electrical, mechanical, or other form.

[0077] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place, or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0078] In addition, in each embodiment of the present application, each functional unit can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit.

[0079] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a non-volatile computer-readable memory executable by a processor. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in various embodiments of the present application. The aforementioned memory includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store program codes.

[0080] Finally, it should be noted that the above-described embodiments are only specific implementation manners of the present application, used to illustrate the technical solutions of the present application, rather than limiting them. The protection scope of the present application is not limited thereto. Although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that any technician familiar with the technical field of the present application can still modify the technical solutions described in the foregoing embodiments, or can easily think of changes, or perform equivalent replacements for some of the technical features; and these modifications, changes, or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. An XML document processing method, characterized in that, Including: Obtain the XML document to be parsed and at least one attribute to be parsed in the XML document to be parsed; Determine whether there is a corresponding class template document for the attribute to be parsed. If so, annotate the class template document; For each attribute to be parsed, determine whether there is corresponding metadata in the annotation of the class template document corresponding to the attribute to be parsed; If so, perform parsing based on the corresponding metadata to obtain the entity class object corresponding to the attribute to be parsed; Determine the class template document corresponding to the attribute to be parsed in the following way: For each attribute to be parsed, determine the root attribute node corresponding to the attribute to be parsed; Determine the full path name of the corresponding entity class according to the root attribute node; Match the corresponding class template document according to the full path name of the entity class corresponding to the root attribute node; Annotate the class template document in the following way: Determine the metadata of the same class as the class template document according to the XML document to be parsed; Match the attributes of each metadata in the metadata with the attributes in the class template document, and generate a corresponding metadata mapping table. The key of the metadata mapping table is the class name of the class template document, and the key value of the metadata mapping table is the metadata information corresponding to the class name; Wherein, the metadata information includes the position of the metadata in the class template document, the class name corresponding to the metadata, and the metadata attribute mapping table.

2. The method according to claim 1, wherein The key of the metadata attribute mapping table is each metadata attribute in the metadata, and the key value is the metadata parsing information for parsing the metadata attribute. Wherein, the metadata parsing information includes the full path name of the metadata attribute, the parsing position of the metadata attribute, and the additional attributes of the metadata attribute. The additional attributes of the metadata are at least one of the child node attributes of the metadata attribute.

3. The method according to claim 2, characterized in that, Determine the full path name of the metadata in the following way: Determine the metadata attribute as the target attribute node; Determine the class name corresponding to the metadata attribute as the root attribute node; Determine at least one attribute node on the path from the root attribute node to the target attribute node, and splice them in order to generate the full path name of the metadata.

4. The method according to claim 2, characterized in that, The entity class object includes a target class name, multiple target attributes, and target attribute values corresponding to the target attributes. Obtain the entity class object corresponding to the attribute to be parsed in the following way: Determine the class name of the class template document corresponding to the attribute to be parsed as the target class name; For each attribute to be parsed, determine the metadata attribute corresponding to the attribute to be parsed; Determine the attribute to be parsed and the additional attributes of the metadata attribute corresponding to the attribute to be parsed as multiple target attributes; According to the metadata attribute mapping table, determine the target attribute value corresponding to each target attribute.

5. The method according to claim 4, characterized in that Determine the target attribute value corresponding to each target attribute in the following way: Obtain the parsing position of the corresponding metadata attribute according to the metadata attribute corresponding to the target attribute; Determine the target attribute value corresponding to the target attribute according to the parsing position of the metadata attribute.

6. An XML document processing device, characterized in that, Including: An acquisition module for acquiring the XML document to be parsed and at least one attribute to be parsed in the XML document to be parsed; A labeling module, configured to determine whether there is a corresponding class template document for the attribute to be parsed. If so, label the class template document. Specifically, the labeling module is configured to, for each attribute to be parsed, determine the root attribute node corresponding to the attribute to be parsed; determine the full path name of the corresponding entity class according to the root attribute node; match the corresponding class template document according to the full path name of the entity class corresponding to the root attribute node, and determine the metadata of the same class as the class template document according to the XML document to be parsed; match the attributes of each metadata in the metadata with the attributes in the class template document, and generate a corresponding metadata mapping table. The key of the metadata mapping table is the class name of the class template document, and the key value of the metadata mapping table is the metadata information corresponding to the class name. The metadata information includes the position of the metadata in the class template document, the class name corresponding to the metadata, and the metadata attribute mapping table; A judgment module, configured to, for each attribute to be parsed, determine whether there is corresponding metadata in the label of the class template document corresponding to the attribute to be parsed; A parsing module, configured to, if so, perform parsing based on the corresponding metadata to obtain the entity class object corresponding to the attribute to be parsed.

7. An electronic device, characterized in that, It includes: A processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the memory through the bus. The processor executes the machine-readable instructions to perform the steps of the XML document processing method according to any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, A computer program is stored on the storage medium. When the computer program is run by the processor, it performs the steps of the XML document processing method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Generating a parser and parsing a document

    US20060155726A1