The parsing of ODX document and generation technique based on DOM frame

文档序号:1742141 发布日期:2019-11-26 浏览:14次 中文

阅读说明:本技术 基于dom框架的odx文档解析和生成技术 (The parsing of ODX document and generation technique based on DOM frame ) 是由 许蕾 王晓雷 李言辉 徐宝文 于 2018-05-16 设计创作,主要内容包括:本发明提出了一种基于DOM框架的ODX文档的解析和生成技术,主要分为三个模块:XML Schema解析模块,ODX文档解析模块和ODX文档生成模块。XML Schema解析模块将ODX文档的XML Schema规则分成了基本数据类型规则、复杂数据类型规则、结构类型规则、约束类型规则和扩展类型规则,并根据各种类规则设计了符合ODX文档格式的Java类映射规则,使得ODX文档中的每一个类都可以标准化生成对应的Java类映射;ODX文档解析模块首先利用反射机制,循环提取待解析类继承的所有类成员信息,接下来通过DOM框架,获取根节点的所有属性和元素信息放入待解析队列中。最后把待解析队列中的属性或元素的值映射到目标类对应的成员变量中:对于基本数据类型进行直接赋值,对于成员对象进行递归赋值,对于数组变量循环每个数组成员并根据各数组成员的实际类型选择直接赋值或进行递归操作;ODX文档生成模块与解析模块类似,首先循环提取待解析类继承的所有类成员信息,作为待生成队列。接下来对待生成队列的每个成员通过其是否经过解析或修改,判断该成员变量是否应该输出,最后根据不同的数据类型递归的完成ODX文档生成操作:对于基本数据类型进行直接生成,对于成员对象进行递归生成,对于数组变量循环每个数组成员并根据各数组成员的实际类型选择直接生成或进行递归操作。(The invention proposes a kind of parsing of ODX document based on DOM frame and generation techniques, are broadly divided into three modules: XML Schema parsing module, ODX document parsing module and ODX document creation module.The XML Schema rule of ODX document is divided into basic data type rule, complex data type rule, structure type rule, constrained type rule and expansion type rule by XML Schema parsing module, and the java class mapping ruler for meeting ODX document format is devised according to various rule-likes, so that each of ODX document class, which can standardize, generates corresponding java class mapping;ODX document parsing module extracts all class members's information of Similar integral to be resolved first with reflection mechanism, circulation, and followed by DOM frame, all properties and element information for obtaining root node are put into queue to be resolved.Finally the value of attribute or element in queue to be resolved is mapped in the corresponding member variable of target class: indirect assignment is carried out for basic data type, recurrence assignment is carried out for member object, each array member is recycled for aray variable and indirect assignment is selected according to the actual type of each array member or carries out recursive operation;ODX document creation module is similar with parsing module, first all class members's information of circulation extraction Similar integral to be resolved, as queue to be generated.Next each member of queue to be generated is parsed or is modified by the way that whether it passes through, judge whether the member variable should export, finally according to the different recursive completion ODX document generation operations of data type: basic data type is directly generated, recursive generation is carried out for member object, each array member is recycled for aray variable and directly generates or carry out recursive operation according to the selection of the actual type of each array member.)

1. ODX (the Open that one kind is based on DOM (Document Object Model, DOM Document Object Model) frame Diagnostic data exchange, the open diagnostic data of road vehicle) document parses and generation technique, it is characterized in that root According in ODX document XML Schema file construct Java object mapping ruler, be ODX document each class standard metaplasia at Java data structure;The operation for being resolved to Java object can be carried out to ODX document, i.e., extract member using reflection mechanism and believe It ceases, and extracts the attribute and element of root node to be resolved using DOM frame, recurrence assignment behaviour is carried out according to different types of data Make;Corresponding ODX document can be generated for Java object, i.e., extract information about firms using reflection mechanism, and to each member Whether judgement should export, and be exported ODX document recurrence using DOM frame.

2. a kind of described parsing of ODX document and generation technique, feature based on DOM frame includes according to claim 1 Following steps:

1) transformation rule collection is formulated based on the XML Schema document in ODX document, in the building Java data structure stage, is Corresponding mapping ruler is formulated in every kind of constraint in XML Schema document, and formation rule collection generates Java number for standardizing According to structure;

2) degree of coupling is reduced based on Java reflection mechanism, structure is come for class a operation Java reflection mechanism a large amount of in ODX document Build unified interface;

3) exploitation of XML parsing and Core Generator based on DOM frame selects DOM frame when parsing and generating ODX document To carry out the parsing and generation of xml code.

3. the parsing of ODX document and generation technique according to claim 2 based on DOM frame, it is characterized in that in step 1) Transformation rule collection is formulated based on the XML Schema document in ODX document, is XML in the building Java data structure stage Corresponding mapping ruler is formulated in every kind of constraint in Schema document, and formation rule collection generates Java data knot for standardizing Structure;The legacy structure content and limitation that XML Schema is used to describe XML document define sharable vocabulary, it is provided The necessary frame of XML document and the limitation for acting on this document, are described in detail the different elements and attribute of an XML document Resulting structure and data type, the XML Schema document rule in ODX document is divided into following five seed type: base by the present invention Notebook data typing rule, complex data type rule, structure type rule, constrained type rule and expansion type rule, and needle To the corresponding mapping ruler collection of each type of Rulemaking, it is ensured that the Java data structure of generation can correspond to the institute of ODX document It requires.

4. the parsing of ODX document and generation technique according to claim 2 based on DOM frame, it is characterized in that in step 2), The degree of coupling is reduced based on Java reflection mechanism, unification is constructed for class a operation Java reflection mechanism a large amount of in ODX document Interface;Java reflection mechanism to provide unified parsing for different classes a large amount of in ODX document and generates interface offer May, in the present invention, Java reflection mechanism is mainly used among ODX document analytic technique and ODX document structure tree technology, tool Gymnastics is made as follows:

ODX document analytic technique: in the algorithm incipient stage, believed using the member of Java reflection mechanism Dynamic Extraction class to be resolved Breath;The type of member variable is judged using reflection mechanism in assignment phase, and finally completes assignment operation using reflection mechanism;

ODX document structure tree technology: in the algorithm incipient stage, believed using the member of Java reflection mechanism Dynamic Extraction class to be generated Breath, constructs list to be generated;In document output stage, the type of member variable is judged using Java reflection mechanism and extracts member The value of variable.

5. the parsing of ODX document and generation technique according to claim 2 based on DOM frame, it is characterized in that in step 3), The exploitation of XML parsing and Core Generator based on DOM frame selects DOM frame to carry out when parsing and generating ODX document The parsing and generation of xml code;DOM framework technology apply to XML Schema document analysis module, ODX document creation module and ODX document parsing module all among three modules, specifically includes: the reading and information extraction of XML Schema file;ODX text The reading and information extraction of shelves;The generation of ODX document.

Technical field

The invention belongs to field of computer technology, especially software technology field.The invention proposes one kind to be solved based on DOM The parsing of universal ODX document and the generation technique for analysing frame and Java reflection mechanism, being capable of System design ODX document and Java Mapping between class, and the mutual conversion between any ODX document and Java object can be completed.In terms of vehicle-mounted Have a wide range of applications demand.

Background technique

The open diagnostic data of road vehicle (Open diagnostic data exchange, abbreviation ODX) is a kind of base Format is diagnosed in the vehicle data of XML.It is used to describe the relevant number with automobile ECU (Electronic Control Unit) According to.Including control primitive, data communication primitive, messaging parameter, information of vehicles and configuration instruction between vehicle and ECU etc. with The relevant information of ECU.Vehicle diagnosing system based on ODX database schema can be by reading and parsing the ODX of each ECU File obtains all information relevant to the ECU, meets the needs of each phases diagnostic data.

Before ODX data model proposes, due to the difference of application scenarios, developing instrument, the not same order of vehicle diagnostics exploitation The data format that section uses is all different.However the interdependence again of each stage in development process is diagnosed, it is inseparable.If Diagnostic requirements descriptor format is constantly converted, it may be difficult to be guaranteed the consistency of data, not only increased the complexity of demand management, but also make Each stage work linking is difficult, increases overall cost.If using ODX as diagnostic data in entirely diagnosis development process Format, since its open source and standardized nature, the above problem are all addressed.

Vehicle communication interface of new generation based on ODX database schema is had been widely used at present in the U.S. and Germany Among leading Automobile Enterprises, however most of Chinese vehicle enterprise is in development phase, the parsing and life of ODX document for D-Server At, as D-Server building important component, have very high application value.Therefore, the present invention bases oneself upon vehicle enterprise demand Pain spot, efficient, the accurate ODX document of trial proposition automatically parses and generating algorithm, for independent research ODX Database Systems and newly Generation vehicle diagnosing system provides reference.

ODX document is mainly write by XML (eXtensible Markup Language, extensible markup language). XML is widely used in field of data exchange, because of the flexibility and scalability of its height to guarantee the uniformity of data. Relative to common XML file, ODX document exists simultaneously document architecture and greatly solves with the feature of logical relation complexity, traditional XML Analysis technology is unable to satisfy the demand of ODX document parsing, need to customize and solve for the parsing of the document of ODX and generation technique The parsing and generation problem of ODX document.

In conclusion the parsing and generation of ODX document are for building ODX database or even young mobile diagnostic system There is important role;And XML document analytic method traditional at present is unable to satisfy the demand of ODX document parsing.On meeting Demand is stated, the invention proposes a kind of design methods of ODX document parsing and generation technique.

Summary of the invention

Groundwork of the invention be propose it is a kind of based on DOM analytical framework and the universal ODX of Java reflection mechanism text Shelves parsing and generation technique.The technology is broadly divided into three modules: XML Schema parsing module, ODX document parsing module and ODX document creation module.It is respectively intended to solve the problems, such as that the java class mapping ruler of ODX document, ODX document to Java object turn Change problem and Java object to ODX document transfer problem.Wherein XML Schema module design meets ODX document format XML Schema transformation rule maps each of ODX document class standard metaplasia at corresponding java class;ODX document solution Analysis and generation module are based on DOM analytical framework, in conjunction with Java reflection mechanism, devise the efficient ODX document of lower coupling and Mutual transfer algorithm between Java object.In view of the above problems, work and contribution of the invention is as follows:

1.XML Schema rule parsing.XML Schema rule parsing module is ODX document parsing module and ODX document The basis of generation module is responsible for constructing legal Java data structure according to ODX XML Schema file (odx.xsd). Suitable data structure is only constructed, just can be carried out subsequent parsing and generation operation.Odx.xsd file, as ODX document In XML Schema file, the content structure of specified in more detail ODX document each class and its mutual relationship.This module Effect be exactly to be converted to the rule in odx.xsd: firstly the need of the strictly all rules that occur in identification odx.xsd file, Next need to realize each rule to the mapping between Java data structure, to guarantee parsing and the adequacy generated and complete Property, it lays the foundation for two modules below.

The parsing of 2.ODX document.What this module was responsible for completing to export from ODX document to XML Schema rule parsing module The conversion process of Java class.Input is ODX document, exports Java object.This module firstly the need of creation ODX Java object, Then the content according to ODX document, all classes occurred in the efficient parsing document of lower coupling are needed, and parsing result is stored up There are in Java object.

3.ODX document structure tree.This module is responsible for completing from the java class that XML Schema rule parsing module exports to ODX The conversion process of document.Input is Java object, is exported as ODX document.This module is firstly the need of new ODX document is created, so It is needed afterwards according to the content and the definition of XML file structure in Java object, the efficient generation object of lower coupling needs to export All member variables in ODX document, output one meet odx.xsd requirement XML document.

Detailed description of the invention

Fig. 1 is three modules and its corresponding relationship of ODX document parsing and generation technique, and the present invention is first to ODX document XML Schema rule parsed, next complete the mutual conversion between ODX document and Java object.Detailed process is such as Under:

1) XML Schema rule is converted: XML Schema file of the strictly all rules of ODX document in ODX document There are clear stipulaties in odx.xsd.To realize the mutual conversion between ODX document and Java it is necessary to various to what is wherein occurred The mapping under Java data structure is explained and provided to rule, to achieve the effect that standardization generates java class.

2) after XML Schema is converted, many Java objects can ODX document structure tree algorithm: be generated.It needs to use at this time DOM frame parses ODX document, and the high degree of coupling of DOM frame, recursive parsing are substantially reduced using reflection mechanism ODX document.

3) ODX document structure tree algorithm: ODX document is created by DOM frame first, is next passed with Java reflection mechanism Return the xml code for generating ODX document.

Fig. 2 is the pseudocode of ODX document parsing module, and specific step is as follows for module:

1) firstly, utilizing the indiscriminate all information about firms for extracting parsing class of reflection mechanism.

2) attribute and element information that root node to be resolved is next extracted using DOM frame, construct queue to be resolved.

3) finally, carrying out recursive assignment operation to variable for different types of data.

Fig. 3 is the pseudocode of ODX document creation module, and specific step is as follows for module:

1) firstly, utilizing the indiscriminate all information about firms for extracting parsing class of reflection mechanism.

2) next using the information about firms extracted in step 1) as queue to be generated, each member change is looped to determine Whether amount should export, and if it is execute output operation.

Specific embodiment

The present invention includes three modules, therefore describes specific steps respectively according to these three modules.

XML Schema parsing module specifically includes the following steps:

1) it firstly, summarizing the strictly all rules occurred in the XML Schema file (odx.xsd) of ODX document, and carries out Classifying Sum.

2) different mapping rulers is designed for different types of rule that step 1) extracts, it is ensured that corresponding java class It can satisfy these rules

The rule that rule in step 1) summarizes in ODX document white paper summarizes.All rules can be divided For basic data type rule, complex data type rule, structure type rule, constrained type rule and expansion type rule.

Step 2) devises corresponding mapping method for different types of rule that step 1) extracts.Master data class The conversion method of type rule are as follows:

The conversion method of complex data type rule are as follows:

Structure, the conversion method of constraint and expansion type are as follows:

As shown in Fig. 2, ODX document parsing module comprising the following steps:

1) firstly, using the indiscriminate all information about firms for extracting parsing class of reflection mechanism, code 3- in corresponding diagram 2 8 rows.

2) attribute and element information that root node to be resolved is next extracted using DOM frame, construct queue to be resolved, right Answer code 9-12 row in Fig. 2.

3) finally, carrying out recursive assignment operation, code 14-34 in corresponding diagram 2 to variable for different types of data Row.

Step 1) extracts all class members's information that class TARGET to be resolved is inherited by reflection mechanism, circulation.It counts at this time What is stored in group fields is all variables that possible use in this parsing.

Step 2) obtains all properties and element information of root node ROOT by DOM frame.Queue to be resolved at this time What is stored in parserQueue is all XML attributes or element for waiting and being resolved, next the category in parserQueue Property or the value of element are mapped in the corresponding member variable of TARGET class.

Step 3) does following two pieces thing: (1) In to each of queue parserQueue to be resolved element or attribute Corresponding member variable is searched out in fields;(2) according to the different recursive completion assignment operations of data type: for base Notebook data type carries out indirect assignment, carries out recurrence assignment for member object, recycles each array member for aray variable And indirect assignment is selected according to the actual type of each array member or carries out recursive operation.

As shown in figure 3, ODX document creation module comprising the following steps:

1) firstly, using the indiscriminate all information about firms for extracting parsing class of reflection mechanism, code 3- in corresponding diagram 3 7 rows.

2) next using the information about firms extracted in step 1) as queue to be generated, loop to determine each at Whether member's variable should export, and if it is execute output operation.Code 8-33 row in corresponding diagram 2.

Step 1) extracts all class members's information that class TARGET to be resolved is inherited by reflection mechanism, circulation.It counts at this time What is stored in group fields is all variables that possible use during this ODX document structure tree.

Step 2) does following two pieces thing using fields as queue to be generated, to each member of fields array: (1) By the member variable whether by parsing or modification, judge whether the member variable should export;(2) according to different data The recursive completion ODX document generation operation of type: basic data type is directly generated, member object is passed Return generation, for aray variable recycle each array member and according to the actual type of each array member selection directly generate or into Row recursive operation.

After three above module is completed, the present invention carries out the relevant analysis of Time & Space Complexity.

In the whole process of parsing, the operation carried out is needed to have: (1) constructing dom tree for the document of input;(2) recursive solution Analysis input document.Before analysing in depth this two-part time complexity, need to define what some analyses needed to use first Variable: N is the sum of element and attribute of the ODX document of input;X is the member variable number that an average java class includes.

The building process of dom tree is looked first at, the essence of dom tree is traversal XML document, constructs mapping tree.In XML document In, if XML document can regard the tree for having N number of node as attribute as leaf node.It is available, no matter It is depth-first traversal or breadth first traversal, time complexity is O (N).Resolving is looked next at, according to solution above Analysis algorithm it is found that analytical algorithm can be locating to each attribute or element traversal all member variables of class match, with Recursion resolution afterwards, therefore the time complexity of resolving is O (xN).The time complexity of entire analytical algorithm are as follows:

O (xN)+O (N)=O (N)

In the entire parsing and generating process, the following information of major storage in JVM heap: the dom tree of building is parsed Java variable and recurrence stack.Still assume that n1 is the first prime number for inputting document at this time, n2 is attribute number, and N is element and attribute Sum, a are storage space of the attribute in dom tree, and b is storage space of the element in dom tree, and t is Java change The ratio of variable is resolved in amount, x is the member variable number that average each java class possesses.It is available, the space of dom tree Complexity are as follows:

O (a × n1)+O (b × n2)=O (N)

Store the space complexity of Java variable are as follows:

O (N ÷ t)=O (N)

The space complexity of recurrence information are as follows:

O (N ÷ x)=O (N)

Therefore, algorithm total space complexity is O (N).

In short, the invention proposes a kind of parsing of universal ODX document and generation technique, which is divided into three moulds Block: XML Schema parsing module, ODX document parsing module and ODX document creation module.XML Schema module design The XML Schema transformation rule for meeting ODX document format, to each of ODX document class standard metaplasia at corresponding Java Class mapping;The parsing of ODX document and generation module are based on DOM analytical framework and it is efficient to devise lower coupling in conjunction with Java reflection mechanism Mutual transfer algorithm between the ODX document and Java object of rate.The parsing and generation technique that this discovery is proposed have linear Time & Space Complexity, have clear superiority in the parsing of large-scale ODX document.

11页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种CN-DRGs与C-DRG的自动映射和转换方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!