Summary of the invention
In order to solve the problem in above second kind of conversion method; The present invention provides a kind of method and system of resolving and creating the XML data in the XML document with multiple version and subclass; To remove the redundant data of XML organization definition; Save computer resource, simplify modification and the maintenance of application program, and make and between the different XML documents of same version and subclass, can share a XML organization definition metadata XML document.
In order to realize above purpose, the method for XML data parsing provided by the invention and establishment may further comprise the steps: the version scope of definition XML document form and the set of the mapping relations between subset range, XML structure and the program object model; Version identifier and the subclass of gathering and work as the XML document of pre-treatment according to said mapping relations identify dynamic creation XML organization definition metadata; Accomplish the mutual conversion of XML data and program object model according to said XML organization definition metadata.
In said mapping relations set, an element, the one or more elements in the program object model and the version scope of XML document form and the corresponding relation of subset range in each bar mapping relations definition XML structure.
In said mapping relations set; The version scope and the subset range of XML document form are options; If a undefined version scope of mapping relations and a subset range are then used the corresponding definition of the XML structural element in father's mapping relations of these mapping relations in the said mapping relations set.
The step of said dynamic creation XML organization definition metadata also can comprise the step that the XML organization definition metadata of creating is added buffer memory.In this case, the step of said dynamic creation XML organization definition metadata may further comprise the steps: in XML organization definition metadata cache, search version identifier and subclass sign when the XML document of pre-treatment; If in XML organization definition metadata cache, do not find said sign; Then the XML structure root node of definition begins to travel through the mapping relations set from said mapping relations set; Wherein, For each the bar mapping relations that traverses, carry out following steps: judge in whether the version identifier of the XML document of pre-treatment and subclass identify the version scope and subset range in these mapping relations; Be positioned at said scope if work as the version identifier and the subclass sign of the XML document of pre-treatment, the mode of then adding in the XML organization definition metadata through the corresponding relation with XML structural element that defines in these mapping relations and program object model element is created XML organization definition metadata; Identify not in said scope if work as the version identifier and the subclass of the XML document of pre-treatment, then continue to travel through mapping relations downwards and gather; XML organization definition metadata with dynamic creation after having traveled through adds buffer memory.
Correspondingly, comprise according to the system that is used to resolve and create the XML data provided by the invention: the sign acquiring unit, the version identifier that obtains when the XML document of pre-treatment identifies with subclass; The XML data processing unit; The version scope of definition XML document form and the set of the mapping relations between subset range, XML structure and the program object model; Identify dynamic creation XML organization definition metadata according to the set of said mapping relations and version identifier and the subclass obtained through the sign acquiring unit, and according to the mutual conversion of said XML organization definition metadata completion XML data and program object model.
Said XML data processing unit comprises: create the unit, define said mapping relations set, and identify dynamic creation XML organization definition metadata according to said mapping relations set and version identifier and the subclass obtained through the sign acquiring unit; Converting unit is accomplished the mutual conversion of XML data and program object model according to said XML organization definition metadata.
Said XML data processing unit also can comprise buffer unit, is used for buffer memory through creating the XML organization definition metadata that the unit is created.
For XML organization definition metadata static in the prior art; The present invention uses an XML structure mapping set of relationship; Just can create out the XML organization definition metadata of the XML document form that meets multiple version and subclass; Do not have redundant XML organization definition, saved, simplified modification and the maintenance of application program simultaneously XML document to the taking of computer resource; And the required XML organization definition of dynamic creation metadata when the processing XML data makes application program can use the multiple version and the subclass of unified method processing XML document format, has reduced the implementation complexity of application program.
On the other hand; XML organization definition metadata through with dynamic creation adds buffer memory; Can make and between XML document, share a XML organization definition metadata with version identifier of the same race and subclass identifier combination; For the XML organization definition metadata of the static state of using in the prior art, XML organization definition metadata cache only accounts for very little extra computation machine resource consumption.
Embodiment
The present invention is applicable to the application based on the XML document with multiple version and subclass, and its main technical schemes comprises: at first, and the version scope of definition XML document form and the set of the mapping relations between subset range, XML structure and the program object model three; Then, identify dynamic creation XML organization definition metadata according to the set of said mapping relations with when the version identifier and the subclass of the XML document of pre-treatment; At last; Accomplishing the mutual conversion of XML data and program object model according to said XML organization definition metadata, specifically, is program object model and from the multiple XML data with textural difference of program object model creation according to said XML organization definition metadata with multiple XML data parsing with textural difference; The concrete disposal route of this step is by the employed XML disposal route decision of application program; Belong to prior art, therefore, the descriptions thereof are omitted in this manual.
To combine accompanying drawing and embodiment that the present invention is elaborated below.In following examples, explain according to parsing of the present invention and create the method and system of the XML data in such XML document as the example that is applied as of XML document with multiple version and subclass with electronic document.
For using the situation of XML in the electronic document as the data representation mode; " version " and " subclass " these two notions are embodied in the influence of XML organization definition: between the different document format versions; The organization definition of XML (comprising node, attribute, text data) has increase, deletion; For the compatibility that keeps down, generally do not have the modification of conflict; Between the different subclass of same document format version, the organization definition of XML does not have mutual conflict, and the structure that occurs in all subclass is included among the complete or collected works.Fig. 1 and Fig. 2 illustrate the example that concerns of XML organization definition and documentation release and document subclass in the electronic document respectively.
As shown in Figure 1, in the different editions of electronic file form standard, XML root node 101 has comprised all different child nodes set; In 1 definition of the version the earliest shown in 102, comprise 3 node; In the definition of the version 2 shown in 103, except comprising 3 all in 102 node, increased by 1 node; In the definition of the version 3 shown in 104, deleted 1 child node that in 102 and 103, all comprises, comprised other 3 node in 103, and increased by 2 node.
As shown in Figure 2, to concentrate in the different sub of electronic file form standard, XML root node 201 has comprised all different child nodes set; Shown in 202 is that complete or collected works define, and comprises 6 all node; 203, two different sub shown in 204 concentrate, and respectively comprise 4 each child node, but all do not exceed complete or collected works 202 scope, and 203,204 child nodes that comprised have overlappingly, have 1 node not comprised by 203 and 204 in 202.
In embodiments of the present invention, the concrete definition of said mapping relations set is following:
Each bar mapping relations has defined element and the corresponding relation of the one or more elements in the program object model in the XML structure;
Each bar mapping relations has also defined element and the version scope of electronic file form and the corresponding relation of subset range in the XML structure; The implication of this corresponding relation is; Document format definition for any particular version and subclass; If this version and subclass are included within the version scope and subset range in these mapping relations, then in this specific document format definition, there is the XML structural element in these mapping relations;
The version scope of electronic file form and subset range are options in each bar mapping relations; If a undefined version scope of mapping relations and a subset range are then used the corresponding definition of the XML structural element in father's mapping relations of these mapping relations in the said mapping relations set;
Structural relation between structural each XML structural element of dependency information reflection between the mapping relations.
Below will be with reference to the XML structure mapping set of relationship of figure 3 detailed descriptions according to the embodiment of the invention.
With reference to Fig. 3, label 301-306 representes 6 XML structure mapping relations respectively.With mapping relations 301 is example, and in these mapping relations, the XML structure is < Root>node, and electronic document version scope is version 1-5, and the electronic file form subset range is all subclass, and corresponding program object model is program object R.The following relation of this mapping relations reflection: XML node < Root>has definition in all subclass of the version 1-5 of electronic file form standard; When the analyzing XML data, the data parsing in < Root>node is program object R; When creating the XML data, the data in < Root>node are obtained from program object R.In addition, mapping relations 301 comprise two sub-mapping relations 302 and 303, and this is illustrated in the XML structure, and < Root>node comprises two node < Parent1>and < Parent2 >.
In addition, version scope and subset range can be omitted in sub-mapping relations, in this case, find father's mapping relations according to the structural information between the mapping relations, use the corresponding definition of the XML structural element in father's mapping relations.For example; Mapping relations 304 have been omitted version scope and subset range simultaneously, and mapping relations 305 have been omitted subset range, then can know according to the data definition in his father's mapping relations 302; The version scope of 304 definition is version 1-5; Subset range is subclass A, B, and the version scope of 305 definition is version 3s-5, and subset range is A, B.
Fig. 4 A is the process flow diagram according to the method for the parsing of the embodiment of the invention and establishment XML data.With reference to Fig. 4 A, this method may further comprise the steps:
Step 401, obtain version identifier and subclass sign when the electronic document of pre-treatment;
Step 404, begin to travel through XML structure mapping set of relationship from root node; To each concrete mapping relations; Judge in whether the version identifier of the electronic document of pre-treatment and subclass identify the version scope and subset range in these mapping relations; Be positioned at said scope if work as the version identifier and the subclass sign of the electronic document of pre-treatment, then execution in step 405, identify not in said scope if work as the version identifier and the subclass of the electronic document of pre-treatment; Then continue traversal mapping relations set downwards and repeat above step, till having traveled through the mapping relations set;
Step 405, utilize the corresponding relation of XML structure and program object; Dynamic creation XML organization definition metadata; Specifically; Mode through the corresponding relation with defined XML structural element of said mapping relations and program object model element adds in the XML organization definition metadata is come dynamic creation XML organization definition metadata, and the concrete metadata creation method and the metadata format of establishment are by the employed XML disposal route decision of bottom;
The XML organization definition metadata of step 407, the use employed XML disposal route of bottom and dynamic creation is come the processing XML data, accomplishes the mutual conversion of XML data and program object model.
It is to be noted; In above method; When traversing when mapping relations within its version scope and subset range of the version scope of the electronic file form of pre-treatment and subset range; Just the corresponding relation with XML structural element in these mapping relations and program object model element adds in the XML organization definition metadata; Thereby accomplish the establishment of XML organization definition metadata gradually, that is to say, traversal XML structure mapping set of relationship, the process of choosing the corresponding relation of the XML structural element that had when the pre-treatment electronic file form and program object model element and creating XML organization definition metadata are carried out synchronously.In other embodiments; Can also be at first in traversal XML structure mapping set of relationship, select the whole XML structural elements that had when the pre-treatment electronic file form and the corresponding relation of program object model element, create the XML structural element according to the corresponding relation of these XML structural elements and program object model element then.
In above method, also can the XML organization definition metadata of dynamic creation be added buffer memory, so just can be implemented in and share a XML organization definition metadata between the different electric subdocument with same version and subclass.Below will use the method for caching mechanism and the difference of the method for describing with reference to Fig. 4 A with reference to Fig. 4 B explanation.
The difference of Fig. 4 B and Fig. 4 A is to have increased step 402,403 and 406, and all the other steps are identical with Fig. 4 A.
In step 402, in XML organization definition metadata cache, be designated key and inquire about with the version identifier that in step 401, obtains and subclass.
Then; In step 403; Judge whether to find XML organization definition metadata, if in step 402, in XML organization definition metadata cache, find corresponding value, then execution in step 407; If in XML organization definition metadata cache, do not exist in version identifier and the subclass sign obtained in the step 401, then execution in step 404.
In step 405, after the dynamic creation XML organization definition metadata, in step 406, the XML organization definition metadata of creating is added buffer memory.
Below will specify the processing procedure of step 404 (traversal XML structure mapping set of relationship) and step 405 (dynamic creation XML organization definition metadata) with reference to Fig. 5 A and Fig. 5 B through a specific embodiment.
In the present embodiment, use Castor as the XML disposal route, then XML organization definition metadata format itself also is an XML document, can use mode such as DOM to create XML document during establishment, again XML document is saved as character string forms.In addition, XML organization definition metadata cache takes known " key-value " to memory technology, can be to a certain specific key; Storage, unique value of inquiry, wherein, version identifier and subclass sign have been formed key jointly; XML organization definition metadata is value; That is to say that the key of preserving in the XML organization definition metadata cache is the version identifier that in step 401, obtains and subclass sign, the value of preservation is the XML document of the character string forms that in step 405, obtains.In step 407, use Castor disposal route and the XML organization definition metadata of obtaining to come the processing XML data, accomplish the conversion between XML data and the program object model.
In Fig. 5 A; 301-306 representes the XML structure mapping set of relationship that processing procedure is required respectively; 501 to be illustrated in the version identifier when the electronic document of pre-treatment that obtains in the step 401 be 4, and the subclass sign is A, and 502 corresponding to the step 404 and 405 among Fig. 4 A and Fig. 4 B; The XML document structure that defines among the electronic file form edition 4 that 503-506 representes to take out through step 502 treatment of selected, the subclass A, the 507th, the XML organization definition metadata of the Castor form of creating.
The concrete processing procedure of step 502 is: travel through XML structure mapping set of relationship since 301; In the present embodiment; Follow the traversal order of depth-first; Travel through 301,302,304,305,303,306 successively, certainly, also can adopt other order that XML structure mapping set of relationship is traveled through; To each mapping relations; Relatively version identifier, the subclass in its version scope, the subset range definition and 501 identifies; For example the version scope of 305 definition is version 1-5; Subset range is subclass A, B, and the edition 4 shown in 501, subclass A are positioned at this scope, becomes 506 so XML structure that defines in 305 and program object are selected out; And the version scope of 303 definition is 1-3, and the edition 4 shown in 501 is not in this scope, so 303 corresponding XML structures are not selected; The 503-506 that use is chosen creates the XML document shown in 507, is the XML organization definition metadata of required Castor form.
Note; As stated; The process of the traversal XML structure mapping set of relationship in the step 502, the XML structure that electronic file form had of choosing the version identifier that has in 501 and subclass sign and program object, establishment XML organization definition metadata also can be carried out synchronously; Promptly in processing procedure, the XML structural element 503-506 that chooses out is also unnecessary to be occurred to create XML organization definition metadata 507 simultaneously; Can choose after 503, promptly create a part of 507, choose after 504, create 507 counterpart again, so accomplish the establishment of XML organization definition metadata successively.
Fig. 5 B shown the process that version identifier is 2, subclass is designated the electronic document dynamic creation XML organization definition metadata of B, wherein, 502 represented traversals, choose identical with constructive process with the process of describing with reference to Fig. 5 A.In Fig. 5 B, XML structure and the program object selected through step 502 are expressed as 512-515 respectively, and have created the XML organization definition metadata 516 that version identifier is 2, subclass is designated the electronic document of B in view of the above.
Can find out from Fig. 5 A and Fig. 5 B; The present invention is for a kind of specific electronic document version identifier and subclass identifier combination; Only need a XML organization definition of dynamic creation metadata; With its buffer memory, use then thereby make this metadata between different electric subdocument, to share with this particular version sign and subclass sign.The static XML organization definition metadata of using in the prior art, buffer memory only takies very little extra computation machine resource consumption.
It is pointed out that present embodiment with the application of electronic document as the XML document with multiple version and subclass, but the present invention is applicable to other application that meets the following conditions: (1) is applied to the mutual conversion between XML data and the program object model; (2) have version, subclass or similar notion, between different versions and subclass, the XML organization definition has modification.In addition; Said XML structure mapping set of relationship is not limited to mapping relations set shown in Figure 3, all should be included within protection scope of the present invention as long as can show the version scope of XML document form and the set of the mapping relations between subset range, XML structure and the program object model.
Correspondingly, the present invention provides a kind of system that is used for resolving and create the XML data of the XML document with multiple version and subclass, in this system, and the known display unit that is used to show the application of using XML document that comprises with multiple version and subclass.Below will the peculiar part of this system be described with reference to Fig. 6.
Can find out that from Fig. 6 this system also comprises: sign acquiring unit 100, obtain version identifier and subclass sign when the XML document of pre-treatment; XML data processing unit 200; The version scope of definition XML document form and the set of the mapping relations between subset range, XML structure and the program object model; Identify dynamic creation XML organization definition metadata according to the set of said mapping relations and version identifier and the subclass obtained through sign acquiring unit 100, and according to the mutual conversion of said XML organization definition metadata completion XML data and program object model.
Said XML data processing unit 200 comprises: create unit 202, define said mapping relations set, and identify dynamic creation XML organization definition metadata according to said mapping relations set and version identifier and the subclass obtained through sign acquiring unit 100; Converting unit 206, according to the mutual conversion of said XML organization definition metadata completion XML data and program object model, and the result that will change sends display unit to.The operation of these unit is with above identical with reference to the described method step of Fig. 4 A, and therefore, the descriptions thereof are omitted.
For sharing of XML organization definition metadata between the different XML documents of realizing same version and subclass, said XML data processing unit 200 also can comprise buffer unit 204, is used for buffer memory through creating the XML organization definition metadata that the unit is created.The operation of the XML data processing unit 200 of this moment is with above identical with reference to the described method step of Fig. 4 B, and therefore, the descriptions thereof are omitted.
Can find out from above description; The present invention uses an XML structure mapping set of relationship; Just can create out the XML organization definition metadata of the XML document form that meets multiple version and subclass; Do not have redundant XML organization definition, can save the modification and the maintenance that take and simplify application program computer resource.On the other hand, the definition relevant with subclass with the version of XML document form only is defined in the XML structure mapping set of relationship, and application program just can handle multiple versions with single method and the XML document of subclass, reduced the implementation complexity of application program.In addition, also used caching mechanism in the foregoing description, thereby making between the different document of same version and subclass, can share uses a XML organization definition metadata.
Above reference implementation example has been described the present invention.But; It should be appreciated by those skilled in the art, the invention is not restricted to the disclosed embodiments, under the situation that does not break away from ultimate principle of the present invention; Any similar modification, replacement or distortion all should be included in protection scope of the present invention, and protection scope of the present invention is defined by the claims.