CN101739245B - Method and device for convertion between extensive makeup language (XML) message and C language program structure - Google Patents

Method and device for convertion between extensive makeup language (XML) message and C language program structure Download PDF

Info

Publication number
CN101739245B
CN101739245B CN 200810173686 CN200810173686A CN101739245B CN 101739245 B CN101739245 B CN 101739245B CN 200810173686 CN200810173686 CN 200810173686 CN 200810173686 A CN200810173686 A CN 200810173686A CN 101739245 B CN101739245 B CN 101739245B
Authority
CN
China
Prior art keywords
xml message
programmer
node
field
programmer structure
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN 200810173686
Other languages
Chinese (zh)
Other versions
CN101739245A (en
Inventor
闫京生
杨军
黄治华
王华驰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Fiberhome Digtal Technology Co Ltd
Original Assignee
Wuhan Fiberhome Digtal Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Fiberhome Digtal Technology Co Ltd filed Critical Wuhan Fiberhome Digtal Technology Co Ltd
Priority to CN 200810173686 priority Critical patent/CN101739245B/en
Publication of CN101739245A publication Critical patent/CN101739245A/en
Application granted granted Critical
Publication of CN101739245B publication Critical patent/CN101739245B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Document Processing Apparatus (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention discloses a method for convertion between an extensive makeup language (XML) message and a C language program structure, and the corresponding relation between the XML message and the format of the C language program structure is set. The method comprises the following steps of: receiving the XML message and analyzing field information and the format of the C language program structure corresponding to the XML message from the XML message; constructing the corresponding C language program structure; or constructing the XML message corresponding to the C language program structure according to the C language program structure and the corresponding relation. The invention also discloses a corresponding device which comprises a memory module and an execution module. The invention can automatically finish the conversion between the XML message and the C language program structure, reduce error and improve the efficiency.

Description

Method and the device of XML message and the conversion of C programmer structure
Technical field
The present invention relates to extend markup language (XML, eXtensible Markup Language) Message Processing technology, particularly method and the device of the conversion of a kind of XML message and C programmer structure.
Background technology
XML is a kind of working standard of exchanges data between software application and the web services, particularly often uses XML message as Message Call Interface in the web programming.And C programmer is programming language commonly used in the software application, and nature can not lack the use of XML message in the application software that C programmer is realized.
C programmer and outside interactive interface are generally externally mutual with the form of byte stream message, and inside represents external information with structure usually.In the practical application, exchange message between C programmer and the web program has dual mode usually, byte stream mode and XML message mode:
Byte stream mode: C programmer deals with comparatively easy, the factor that consider such as syllable sequence, when cross-platform to filling of structure etc.; But then cumbersome in web program side, usually also to encapsulate one deck conversion; And the expressive ability of the message under the byte stream mode is relatively poor, could understand its implication to byte analysis;
The XML message mode: the web program comparision is good at; Because XML message is actually character string, does not have like this syllable sequence problem and cross-platform problem, and directly can find out implication and the value of each field from XML message, be conducive to the unified of Message Call Interface analyzed and test.Problem is C programmer for the generation of XML message and resolves cumbersomely, and the information redundancy of XML message is relatively large.
In the prior art, usually manually finish generation and parsing for XML message by the programmer, when XML message was complicated, mistake appearred in artificial parsing unavoidably, and efficient is not high.
Summary of the invention
In view of this, fundamental purpose of the present invention is to provide method and the device of a kind of XML message and the conversion of C programmer structure, automatically finishes the conversion of XML message and C programmer structure, raises the efficiency.
For achieving the above object, technical scheme of the present invention is achieved in that
The method of a kind of XML message and C programmer structure conversion arranges the corresponding relation of XML message and C programmer structure form, and the method comprises:
A1, reception also parse field information and C programmer structure form that described XML message is corresponding from XML message; According to described field information and C programmer structure form, set up corresponding C programmer structure;
Perhaps,
A2, according to C programmer structure and described corresponding relation, set up the XML message corresponding with this C programmer structure;
Wherein, according to described field information and C programmer structure form, set up corresponding C programmer structure and specifically comprise:
A11, according to described field information and C programmer structure form corresponding to described XML message, set up the C programmer structure node of current Related fields;
Whether A12, the current field of analysis comprise lower one deck field, if so, set up the C programmer structure node of lower one deck Related fields of current field; Set up until finish the C programmer structure node of the N layer field of current field;
A13, set up the C programmer structure node of the next Related fields of XML message, set up until finish the C programmer structure node of all Related fields of XML message;
Wherein, described according to C programmer structure and described corresponding relation, the method for setting up the XML message corresponding with this C programmer structure is:
Each field of XML message is considered as character string, corresponding relation according to C programmer structure and this structure and XML message, namely obtain node level relational tree, the data type of each node, the position of each node in internal memory of C programmer structure, data in the structure internal memory are write each field of XML message, thereby set up corresponding XML message.
Described XML message is corresponding one by one with C programmer structure form.
The node type of the field type of described XML message or C programmer structure comprises: integer, character type, digit group type or structure.
The device of a kind of XML message and the conversion of C programmer structure, this device comprises:
The first module is for the corresponding relation that XML message and C programmer structure form are set;
The second module is used for receiving and parsing field information and C programmer structure form corresponding to described XML message from XML message;
The 3rd module is used for according to described field information and C programmer structure form, sets up corresponding C programmer structure;
Four module is used for according to C programmer structure and described corresponding relation, sets up the XML message corresponding with this C programmer structure;
Wherein, described the 3rd module comprises:
First module is used for according to described field information and C programmer structure form corresponding to described XML message, sets up the C programmer structure node of current Related fields;
Second unit is used for analyzing current field and whether comprises lower one deck field, if so, sets up the C programmer structure node of lower one deck Related fields of current field; Set up until finish the C programmer structure node of the N layer field of current field;
Unit the 3rd is used for setting up the C programmer structure node of the next Related fields of XML message, sets up until finish the C programmer structure node of all Related fields of XML message;
Wherein, described four module comprises:
Unit the 4th, be used for each field of XML message is considered as character string, corresponding relation according to C programmer structure and this structure and XML message, namely obtain node level relational tree, the data type of each node, the position of each node in internal memory of C programmer structure, data in the structure internal memory are write each field of XML message, thereby set up corresponding XML message.
The present invention sets in advance corresponding relation between XML message and the C programmer structure form according to user's request, during communication, automatically finish the parsing of XML message, and so that XML message can map directly in the corresponding C programmer structure internal memory, simplify conversion work, thereby so that the C programmer easier use XML message of energy and external program, particularly the web program is carried out alternately.On the other hand, according to the information of C programmer structure node, also can directly be converted to corresponding XML message.When the XML of needs message format changed, the corresponding relation that upgrades between XML message and the C programmer structure form can satisfy new demand, strong adaptability.
Description of drawings
Fig. 1 is the process flow diagram of the method for XML message of the present invention and the conversion of C programmer structure;
Fig. 2 is the C programmer structure form schematic diagram among the embodiment of the inventive method;
Fig. 3 is the apparatus structure schematic diagram of XML message of the present invention and the conversion of C programmer structure.
Embodiment
The present invention is by setting in advance the corresponding relation of XML message and C programmer structure form, the field information that the XML message parse is gone out is automatically converted to the structure node description that C programmer can be identified, and perhaps C programmer structure nodal information is converted to XML message; This conversion is finished automatically, has avoided the various mistakes of artificial conversion, simultaneously, can increase the corresponding relation of XML message and C programmer structure form according to user's needs.
Below by specific embodiment and description of drawings technical scheme of the present invention.
Method flow of the present invention as shown in Figure 1, the corresponding relation of XML message and C programmer structure form is set, wherein: the value of the field name in the XML message, field type and each field is mapped as the hierarchical relationship between nodename, node type, node side-play amount and each node of C programmer structure.The method comprises two parts: the XML message conversion is the C programmer structure, or the C programmer structure is converted to XML message.
Step 101, reception also parse field information and C programmer structure form corresponding to described XML message from XML message;
XML message for example:
Figure GSB00000921990100051
Figure GSB00000921990100061
Wherein<p〉</p〉field of expression and value thereof,<sp〉</sp〉represent it is a structure,<ap〉</ap〉represent it is an array.The present invention only relates to parsing and the generation of the XML message of C programmer and extraneous program usefulness XML interacting message.If consider the transmission needs of network program, such as the TCP transmission, also to add some information in the front of XML message, such as message overall length, type of message etc., correctly receive XML message and processing for C programmer.These information formats and content be not in the scope of the invention.The numbering of C programmer structure form corresponding to XML message is set in the reserved place of XML message, like this, by this numbering, determines corresponding C programmer structure form.
Each field information comprises field name, the value of field type and field, XML message in the upper example can not directly be identified by C programmer, need at first resolve C programmer structure corresponding to this XML message, and then the field information that comprises of Analysis of X ML message, each field has a C programmer structure node corresponding with it, as shown in Figure 2, the C programmer structure name corresponding with this XML message is called c_java_firstmsg_info_t, comprise 5 ground floor nodes: first nodename Int32Element, type is integer (int), and side-play amount calculates according to size and the c_java_firstmsg_info_t structure memory start address reference position of Int32Element; Second nodename is Int32ElementArray, type is array (Array), and side-play amount is according to calculating gained, and this node comprises two next node layers, be the second layer node of c_java_firstmsg_info_t structure: title is respectively 1 and 2, and type is int; The 3rd nodename of the ground floor of c_java_firstmsg_info_t structure is Int8ElementArray, and type is character string (string), and the maximum length of character string was 4 (comprising '/0 '), and side-play amount is according to calculating gained; The 4th nodename of the ground floor of c_java_firstmsg_info_t structure is StructElement, and type is structure, comprises two second layer nodes: first nodename is Uint32Element, and type is int; Second nodename is Uint8Element, type string, and the character string maximum length was 11 (comprising ' 0/ '), side-play amount is all by calculating; The 5th nodename of the ground floor of c_java_firstmsg_info_t structure is SturctElementArray, type is array, comprise two second layer nodes: first nodename is 1, type is structure, this node comprises two the 3rd node layers: first nodename is Int8Element, and type is array, and this array comprises two the 4th node layers, title is respectively 1 and 2, and type is int; Second nodename of second layer node structure body 1 is Int32Element, and type is character string; Second second layer nodename of SturctElementArray array is 2, and type is structure, and this node comprises two the 3rd node layers: first nodename is Int8Element, type is array, this array comprises two the 4th node layers, and title is respectively 1 and 2, and type is int; Second nodename of second layer node structure body 2 is Int32Element, and type is character string; The calculating of the side-play amount of each node layer is similar to common side-play amount account form in the C programmer, and this repeats no more.
Step 102, according to described field information and C programmer structure form, set up corresponding C programmer structure.
The C programmer structure name corresponding with the field information of XML message reaction is called c_java_firstmsg_info_t, is specially:
Figure GSB00000921990100071
Figure GSB00000921990100081
The hierarchical relationship that embodies in this structure is:
Figure GSB00000921990100082
Figure GSB00000921990100091
According to described field information and C programmer structure form corresponding to described XML message, set up the C programmer structure node of current Related fields;
Figure GSB00000921990100092
Figure GSB00000921990100101
Analyze current field and whether comprise lower one deck field, if so, set up the C programmer structure node of lower one deck Related fields of current field; Set up until finish the C programmer structure node of the N layer field of current field;
First field does not contain lower one deck field, so continue to set up second node of c_java_firstmsg_info_t;
Figure GSB00000921990100102
Figure GSB00000921990100111
Five nodes of the 3rd node to the set up process and the first two node is similar, and are specific as follows:
Figure GSB00000921990100112
Figure GSB00000921990100121
Figure GSB00000921990100131
Figure GSB00000921990100141
Figure GSB00000921990100151
Figure GSB00000921990100161
Can see, when setting up this hierarchical relationship, each field there are its title (with identical in the XML message), data type (such as XMLAGT_TYPE_INT, XMLAGT_TYPE_STRING, XMLAGT_TYPE_ARRAY, XMLAGT_TYPE_STRUCT) with respect to the skew of structure memory start address, if array type or structure type also will be distributed the node of lower one deck; If character string type then will be write down its maximum length with anti-spilled.Then, by the title c_java_firstmsg_info_t of structure, set up the structure that C programmer shown in Figure 2 can Direct Recognition with the hierarchical relationship of each node.
During use, call the such interface of similar ParseCall (char*pBuf, int bufLen, void * pStruct, int structLen, const char * pStructTypeName), wherein pBuf is XML message; BufLen is the length of XML message; PStruct, the pointer of the structure of this XML message of the correspondence of returning corresponds to example and points to exactly a c_java_firstmsg_info_t structure; StructLen, the size of the structure of corresponding this XML message, corresponding to example is exactly sizeof (c_java_firstmsg_info_t); PStructTypeName, the typonym of the structure of corresponding this XML message, corresponding to example is exactly " c_java_firstmsg_info_t ".
In this ParseCall () interface, just can encapsulate the function in certain C/C++xml storehouse (such as libxml2), untiing of one-level one-level, simultaneously with the name of each field (as<p id=" Int32Element " value=" 1 "/, the name of this field is " Int32Element ", its value is 1) with the hierarchical tree of structure in the title of field be mapped, if the type of this field is not array type or structure type, the value of field is write the side-play amount of this field; If the type of this field is array or structure, so also to continue to solve the value of lower one deck field downwards.
More than be the processing procedure of analyzing XML message, when needs are converted to XML message from the C programmer structure, adopt step 103: according to C programmer structure and described corresponding relation, set up the XML message corresponding with this C programmer structure.
The process that generates XML message is relatively simple, each field of XML message is considered as character string, corresponding relation according to C programmer structure and this structure and XML message, namely obtain node level relational tree, the data type of each node, the position of each node in internal memory of C programmer structure, data in the structure internal memory are write each field of XML message, thereby set up corresponding XML message.
The present invention also provides the device of corresponding XML message and the conversion of C programmer structure, and as shown in Figure 3, this device comprises memory module and execution module, wherein,
Memory module is used for the XML message of storage setting and the corresponding relation of C programmer structure;
It is corresponding C programmer structure that execution module is used for the XML message conversion, perhaps, the C programmer structure is converted to corresponding XML message.
Described execution module comprises parsing module, modular converter and package module, wherein,
Parsing module is used for receiving and parsing field information from XML message;
Modular converter is used for field information and the described corresponding relation according to the XML message of resolving, and sets up corresponding C programmer structure;
Package module is used for according to C programmer structure and described corresponding relation, sets up corresponding XML message.
The above is preferred embodiment of the present invention only, is not for limiting protection scope of the present invention.

Claims (4)

1. the method for an XML message and C programmer structure conversion is characterized in that, the corresponding relation of XML message and C programmer structure form is set, and the method comprises:
A1, reception also parse field information and C programmer structure form that described XML message is corresponding from XML message; According to described field information and C programmer structure form, set up corresponding C programmer structure;
Perhaps,
A2, according to C programmer structure and described corresponding relation, set up the XML message corresponding with this C programmer structure;
Wherein, according to described field information and C programmer structure form, set up corresponding C programmer structure and specifically comprise:
A11, according to described field information and C programmer structure form corresponding to described XML message, set up the C programmer structure node of current Related fields;
Whether A12, the current field of analysis comprise lower one deck field, if so, set up the C programmer structure node of lower one deck Related fields of current field; Set up until finish the C programmer structure node of the N layer field of current field;
A13, set up the C programmer structure node of the next Related fields of XML message, set up until finish the C programmer structure node of all Related fields of XML message;
Wherein, described according to C programmer structure and described corresponding relation, the method for setting up the XML message corresponding with this C programmer structure is:
Each field of XML message is considered as character string, corresponding relation according to C programmer structure and this structure and XML message, namely obtain node level relational tree, the data type of each node, the position of each node in internal memory of C programmer structure, data in the structure internal memory are write each field of XML message, thereby set up corresponding XML message.
2. the method for XML message according to claim 1 and C programmer structure conversion is characterized in that, described XML message is corresponding one by one with C programmer structure form.
3. the method for XML message according to claim 1 and C programmer structure conversion is characterized in that, the node type of the field type of described XML message or C programmer structure comprises: integer, character type, digit group type or structure.
4. the device of an XML message and C programmer structure conversion is characterized in that, this device comprises:
The first module is for the corresponding relation that XML message and C programmer structure form are set;
The second module is used for receiving and parsing field information and C programmer structure form corresponding to described XML message from XML message;
The 3rd module is used for according to described field information and C programmer structure form, sets up corresponding C programmer structure;
Four module is used for according to C programmer structure and described corresponding relation, sets up the XML message corresponding with this C programmer structure;
Wherein, described the 3rd module comprises:
First module is used for according to described field information and C programmer structure form corresponding to described XML message, sets up the C programmer structure node of current Related fields;
Second unit is used for analyzing current field and whether comprises lower one deck field, if so, sets up the C programmer structure node of lower one deck Related fields of current field; Set up until finish the C programmer structure node of the N layer field of current field;
Unit the 3rd is used for setting up the C programmer structure node of the next Related fields of XML message, sets up until finish the C programmer structure node of all Related fields of XML message;
Wherein, described four module comprises:
Unit the 4th, be used for each field of XML message is considered as character string, corresponding relation according to C programmer structure and this structure and XML message, namely obtain node level relational tree, the data type of each node, the position of each node in internal memory of C programmer structure, data in the structure internal memory are write each field of XML message, thereby set up corresponding XML message.
CN 200810173686 2008-11-07 2008-11-07 Method and device for convertion between extensive makeup language (XML) message and C language program structure Active CN101739245B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN 200810173686 CN101739245B (en) 2008-11-07 2008-11-07 Method and device for convertion between extensive makeup language (XML) message and C language program structure

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN 200810173686 CN101739245B (en) 2008-11-07 2008-11-07 Method and device for convertion between extensive makeup language (XML) message and C language program structure

Publications (2)

Publication Number Publication Date
CN101739245A CN101739245A (en) 2010-06-16
CN101739245B true CN101739245B (en) 2013-04-03

Family

ID=42462772

Family Applications (1)

Application Number Title Priority Date Filing Date
CN 200810173686 Active CN101739245B (en) 2008-11-07 2008-11-07 Method and device for convertion between extensive makeup language (XML) message and C language program structure

Country Status (1)

Country Link
CN (1) CN101739245B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103209100B (en) * 2012-01-12 2015-12-16 百度在线网络技术(北京)有限公司 service monitoring method and system
CN102750152B (en) * 2012-06-21 2015-02-04 新浪网技术(中国)有限公司 Method and device of application for generating a plurality of programming languages based on descriptive language
CN103019689B (en) * 2012-11-21 2017-02-15 上海富欣智能交通控制有限公司 Universal object serialization realizing method
CN106528228B (en) * 2016-11-01 2019-12-24 中国银联股份有限公司 Method and device for realizing operation of storage system
CN106550026B (en) * 2016-11-01 2020-08-04 武汉斗鱼网络科技有限公司 Network communication device and method

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1791119A (en) * 2005-12-12 2006-06-21 中兴通讯股份有限公司 Tracking method for mobile communication system signaling message

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1791119A (en) * 2005-12-12 2006-06-21 中兴通讯股份有限公司 Tracking method for mobile communication system signaling message

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
JP特开2004-265164A 2004.09.24

Also Published As

Publication number Publication date
CN101739245A (en) 2010-06-16

Similar Documents

Publication Publication Date Title
CN101739245B (en) Method and device for convertion between extensive makeup language (XML) message and C language program structure
CN100483419C (en) Data format verification method and device
CN101841515B (en) Target variable protocol data unit codec code automatic generation implementation method
CN102542002B (en) Satellite telemetry data treatment system and realization method thereof
CN102447585B (en) Method and device for converting network configuration protocol response message into command line
CN101697125B (en) Method and device for development environment conversion
CN100561476C (en) A kind of code generating method based on the ASN type object
CN101996132A (en) Method and device for automatically testing common object request broker architecture (CORBA) interfaces
CN101126981A (en) Script order registration method, method and device for calling source program code
CN101222365B (en) Similar C structure interface packet processing method
CN100511140C (en) Method for script language calling multiple output parameter interface by component software system
CN107861723A (en) Mass data processing method and its system
CN107450993A (en) A kind of data interactive method of distributed IEC61850 communication components
CN101425010B (en) Deploy and collocation method under general computation surroundings
CN113467972A (en) Communication interface construction method, communication interface construction device, computer equipment and storage medium
CN103378994A (en) Method and terminal for testing communication equipment
CN102111160A (en) Coding and decoding system and codec for reactive system test
CN104423986A (en) Method and device for embedding script into application system
CN101572624B (en) Cross-platform cross-method SNMP extension MIB realization method
CN109683873A (en) Utilize the coding method of aerospace information interface and system architecture of ASN1 rule
CN100362817C (en) Software module testing method
CN101393554A (en) Conversion method and device from IDL information to OWL information
CN107306256A (en) A kind of communications protocol analytic method based on character string type data
CN105793842B (en) Conversion method and device between serialized message
CN116795351A (en) Method and device for generating software tool package and readable storage medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
ASS Succession or assignment of patent right

Owner name: WUHAN FIBERHOME ZHONGZHI DIGITAL TECHNOLOGY CO., L

Free format text: FORMER OWNER: WUHAN HONGXIN COMMUNICATION TECHNOLOGY CO., LTD.

Effective date: 20111115

C41 Transfer of patent application or patent right or utility model
COR Change of bibliographic data

Free format text: CORRECT: ADDRESS; FROM: 430073 WUHAN, HUBEI PROVINCE TO: 430074 WUHAN, HUBEI PROVINCE

TA01 Transfer of patent application right

Effective date of registration: 20111115

Address after: 430074 Wuhan, Hongshan Province District Road, Department of mail, No. 88 hospital

Applicant after: Wuhan Fiberhome Digtal Technology Co., Ltd.

Address before: 430073 Hubei province Wuhan Dongxin East Lake high tech Development Zone, Road No. 5

Applicant before: Wuhan Hongxin Communication Technology Co., ltd.

C14 Grant of patent or utility model
GR01 Patent grant