CN104753891B - A kind of XML message analysis method and device - Google Patents
A kind of XML message analysis method and device Download PDFInfo
- Publication number
- CN104753891B CN104753891B CN201310752479.XA CN201310752479A CN104753891B CN 104753891 B CN104753891 B CN 104753891B CN 201310752479 A CN201310752479 A CN 201310752479A CN 104753891 B CN104753891 B CN 104753891B
- Authority
- CN
- China
- Prior art keywords
- xml message
- character
- node
- parsed
- specified
- 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
Links
- 238000004458 analytical method Methods 0.000 title abstract description 21
- 238000000034 method Methods 0.000 claims abstract description 28
- 230000006870 function Effects 0.000 claims description 13
- 230000001960 triggered effect Effects 0.000 claims description 2
- 238000012986 modification Methods 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 2
- 238000004321 preservation Methods 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000006243 chemical reaction Methods 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 235000012054 meals Nutrition 0.000 description 1
- 238000004064 recycling Methods 0.000 description 1
Landscapes
- Data Exchanges In Wide-Area Networks (AREA)
- Information Transfer Between Computers (AREA)
Abstract
The embodiment of the invention provides a kind of analysis method and devices of XML message, this method comprises: determining the position of the termination character of first specified node in XML message to be resolved, and XML message is divided into the first XML message and the second XML message as line of demarcation by the position to determine;Determine the position that the bebinning character of node is specified in the first XML message, and from bebinning character is intercepted in the first XML message to the character string between the position of termination character;The character string of interception is parsed, obtain the relevant information for each element that specified node is included, using next specified node as first specified node, using the second XML message as XML message after, the step of returning to the position for determining termination character, until having parsed all specified nodes.The present invention need to only parse in the corresponding a part of character string of node where the element required for comprising user, save the more parsing time.
Description
Technical field
The present invention relates to field of communication technology more particularly to a kind of XML message analysis method and devices.
Background technique
Currently, extensible markup language (Extensible Markup Language, XML) packet parsing is in WEB application
In using more and more extensive, be particularly applied in Web service (Web service), for example, in parsing Web service
When XML message, generallys use jdom method and dom4J method realizes parsing.
Specifically, when using jdom method parsing XML message, the specific process of analysis of resolver SAX execution are as follows: will
Alphabet string in XML message is converted to document object (document), i.e. dom tree shape structure;Then to the text after conversion
Shelves object carries out sequential scan and traversing operation, finally obtains the relevant information of element needed for user, such as element or element category
Property value.During SAX parses document object, the beginning and end of document object, the beginning of element and the place terminated are encountered
A series of event handling function will be triggered, completes corresponding operation by these functions.
Assuming that XML character string needed for user has been obtained using jdom method, then, specific implementation code can be such as
Under:
When using dom4J method parsing XML message, specific process of analysis is similar with jdom method, different,
In dom4J method, largely used application programming interface (Application Programming Interface,
API the Collections class in), and some alternatives are additionally provided to obtain better analysis feature or more direct
Coding mode can use in many open source projects, such as Hibernate.
Assuming that XML character string needed for user has been obtained using dom4j method, then, specific implementation code can be such as
Under:
As can be seen that being required to regardless of which kind of process of analysis used by institute in XML message from above two process of analysis
There is character string to be converted to document object, and in practical applications, data all in XML message may can't be used, this is just
The time for keeping system consumption excessive parses the data that these will not be used, and causes the time for parsing XML message longer.
Summary of the invention
The embodiment of the invention provides a kind of analysis method and devices of XML message, are reported to solve using existing XML
The time longer problem of the analysis mode parsing XML message of text.
Based on the above issues, the analytic method of a kind of XML message provided in an embodiment of the present invention, comprising:
It determines the position of the termination character of first specified node in XML message to be resolved, and is with the position determined
The XML message is divided into the first XML message and the second XML message by line of demarcation;
Determine the position that the bebinning character of node is specified described in first XML message, and from first XML message
It is middle to intercept the bebinning character to the character string between the position of the termination character;
The character string of interception is parsed, the relevant information for each element that the specified node is included is obtained, will under
One specified node as first specified node, using second XML message as the XML message after, return determine described in
The step of position of termination character, until having parsed all specified nodes.
A kind of resolver of XML message provided in an embodiment of the present invention, comprising:
Determining module, for determining the position of the termination character of first specified node in XML message to be resolved;And really
The position of the bebinning character of node is specified described in the first XML message that the fixed division module divides;
Division module, the position for being determined using the determining module are divided into as line of demarcation, by the XML message
One XML message and the second XML message;
Interception module, for intercepting the bebinning character to the position of the termination character from first XML message
Between character string;
Parsing module, the character string for intercepting to the interception module parse, and obtain the specified node and are wrapped
The relevant information of each element contained, using next specified node as first specified node, using second XML message as institute
After stating XML message, the step of determining module determines the position of the termination character is returned to, until having parsed all specify
Node.
The beneficial effect of the embodiment of the present invention includes:
A kind of analytic method of XML message provided in an embodiment of the present invention determines XML report to be resolved in the method
The position of the termination character of first specified node in text, and the XML message is divided by the position to determine as line of demarcation
First XML message and the second XML message;Determine the position that the bebinning character of node is specified described in first XML message, and
The bebinning character is intercepted from first XML message to the character string between the position of the termination character;To interception
Character string is parsed, and the relevant information for each element that the specified node is included is obtained, using next specified node as
First specified node, using second XML message as the XML message after, return to the position for determining the termination character
Step, until having parsed all specified nodes.In embodiments of the present invention, the element that user needs in parsing XML message
Relevant information when, only need to be according to above-mentioned stream it is not necessary that the alphabet string in XML message to be converted to complicated document object
Journey parses in the corresponding a part of character string of node where the element required for comprising user, without recycling every time
Entire message is traversed, the more parsing time is saved, i.e., the time that aforementioned this analysis mode uses is shorter.
Detailed description of the invention
Fig. 1 is the flow chart of the analytic method of XML message provided in an embodiment of the present invention;
Fig. 2 is the structural schematic diagram of the resolver of XML message provided in an embodiment of the present invention.
Specific embodiment
With reference to the accompanying drawings of the specification, to the specific of the analysis method and device of XML message provided in an embodiment of the present invention
Embodiment is illustrated.
A kind of analytic method of XML message provided in an embodiment of the present invention, as shown in Figure 1, specifically includes the following steps:
S11: the position of the termination character of first specified node in XML message to be resolved, and the position to determine are determined
It is set to line of demarcation, XML message is divided into the first XML message and the second XML message;
S12: the position that the bebinning character of node is specified in the first XML message is determined, and from intercepting in the first XML message
Beginning character is to the character string between the position of termination character;
S13: parsing the character string of interception, obtains the relevant information for each element that specified node is included, will under
One specified node as first specified node, using the second XML message as XML message after, return above-mentioned steps S11, until
All specified nodes are parsed.
In embodiments of the present invention, for XML message to be resolved, which node in this message is needed to parse, is
It is pre-set, that is to say, that node to be resolved is known.
Preferably, in above-mentioned steps S11, function specifically is found using position, is found first in XML message to be resolved
The position of the termination character of a specified node, specific search procedure are the prior art, and this will not be detailed here.
Preferably, in above-mentioned steps S12, function still is found using position, finds and specifies node in the first XML message
Bebinning character position.
Preferably, in above-mentioned steps S13, existing process of analysis can be used, the character string of interception is parsed, have
Body resolving is no longer described in detail.It certainly, can also be according to the format of practical message when being parsed using existing process of analysis
Existing procedure is optimized.
Further, in embodiments of the present invention, in the related letter for parsing each element that all specified nodes are included
After breath, can by these information preservations to Hash table (HASHMAP) so that called side call required for element related letter
Breath.Herein, the relevant information of element generally includes the value etc. of element term and/or element property.
In embodiments of the present invention, it when the relevant information for the element that user needs in parsing XML message, is not necessarily to XML
Alphabet string in message is converted to complicated document object, only needs according to the above process, from including member required for user
It parses in the corresponding a part of character string of node where plain, without looping through entire message every time, saves more
The parsing time.
It is described in detail below with reference to analytic method of following specific embodiments to above-mentioned XML message.
Assuming that following XML messages are the detailed single response messages of common a set meal and fixed charge, wherein<r></R>for root
Node,<h></H><B></B>for two leaf nodes under root node.
And<s></S>and<m></M>for two child nodes under leaf node B, S node is made of multiple elements;M node by
2 child nodes<l></L>composition;Such a multilayer nest structure constitutes a complete XML message, this message is one
The character string of a XML form.
Specific XML message is as follows:
<?xml version="1.0"encoding="UTF-8"?>
<R>
<H>
<F n="RESULT_CODE">0</F>
<f n="RESULT_INFO">it calls successfully</F>
<F n="ERROR_RETURN_CODE"></F>
<F n="BUSI_RETURN_CODE">0</F>
<F n="ERROR_TYPE"></F>
</H>
<B>
<S>
<F n="F1">3</F>
<F n="ACYC_START_TIME">2013-09-0100:00:00</F>
<F n="CYCLE_BEGINDATE">2013-09-0100:00:00</F>
<F n="F2">125.33</F>
<F n="ACYC_END_TIME">2013-09-2223:59:59</F>
<F n="CYCLE_ENDDATE">2013-09-3023:59:59</F>
<F n="NUM">1</F>
</S>
<M>
<L>
<F n="TRANSDATA2">2013-09-01-2013-09-30</F>
<f n="TRANSDATA3">10 yuan of shelves of flow monthly package</F>
<F n="TRANSDATA4">10.00</F>
<F n="CYCLE_BEGIN_DAY">20130901</F>
<F n="TRANSDATA1">201309</F>
<F n="CYCLE_END_DAY">20130930</F>
</L>
<L>
<F n="TRANSDATA2">2013-09-01-2013-09-30</F>
<f n="TRANSDATA3">10 yuan of music set packets of fashion plan</F>
<F n="TRANSDATA4">7.33</F>
<F n="CYCLE_BEGIN_DAY">20130901</F>
<F n="TRANSDATA1">201309</F>
<F n="CYCLE_END_DAY">20130930</F>
</L>
</M>
</B>
</R>。
Assuming that needing to parse in this XML message<h></H>,<s></S>, first<l></L>these three specified node institutes
The relevant information (such as element term and/or the value of element property etc.) for the element for including, then, it is first in above-mentioned steps S11
The termination character that function finds first specified node is found first with position</H>position, using this position as line of demarcation, will
XML message from</H>this position is divided into the first XML message and the second XML message, for example following code institutes of the first XML message
Show, the second XML message be since<B>to</R>that a part of character string.
Specific first XML message is as follows:
<?xml version="1.0"encoding="UTF-8"?>
<R>
<H>
<F n="RESULT_CODE">0</F>
<f n="RESULT_INFO">it calls successfully</F>
<F n="ERROR_RETURN_CODE"></F>
<F n="BUSI_RETURN_CODE">0</F>
<F n="ERROR_TYPE"></F>
</H>。
Further, in the first XML message, bebinning character < H that function finds first specified node is found using position
>position, and intercepted out from the first XML message<h>it arrives</H>between character string;It then, can for this partial character string
By using these functions of splitMulti, splitSingle, splitLeft, splitRight, by first specified node<H>
</H>the relevant information of the elements such as the RESULT_CODE for being included parses, and is saved into HASHMAP, to adjust
With the relevant information of element required for can obtaining from HASHMAP, such as RESULT_CODE this element is entitled
KEY, the value 0 of element property are VALUE.
Next, general<B>arrive</R>this part of message as above-mentioned XML message, using with parse first specified node
The identical process of the process of the relevant information for the element for being included, further parsing obtains<s></S>this specified node is wrapped
The relevant information parsed is equally saved in HASHMAP by the relevant information of the element contained;
Finally, will<m>it arrives</R>this part of message is used as above-mentioned XML message again, using with parse first specified section
The identical process of process of the relevant information of the included element of point, further parsing obtains first<l></L>node is wrapped
The relevant information parsed is equally also saved in HASHMAP by the relevant information of the element contained, and so, these three refer to
The relevant information for determining node, which parses, to be finished.;
Based on the same inventive concept, the embodiment of the invention also provides a kind of resolvers of XML message, due to the device
The principle of solved problem is similar to the analytic method of aforementioned XML message, therefore the implementation of the device may refer to preceding method
Implementation, overlaps will not be repeated.
A kind of resolver of XML message provided in an embodiment of the present invention, as shown in Figure 2, comprising:
Determining module 21, for determining the position of the termination character of first specified node in XML message to be resolved;And
Determine the position that the bebinning character of node is specified in the first XML message of the division of division module 22;
XML message is divided into first as line of demarcation by division module 22, the position for being determined using determining module 21
XML message and the second XML message;
Interception module 23, for from bebinning character is intercepted in the first XML message to the character between the position of termination character
String;
Parsing module 24, the character string for intercepting to interception module 23 parse, and obtain specified node and are included
The relevant information of each element, using next specified node as first specified node, using the second XML message as XML message after,
The step of determining module 21 determines the position of termination character is returned to, until having parsed all specified nodes.
Preferably, above-mentioned determining module 21 is specifically used for finding function using position, determines XML message to be resolved
In first specified node termination character position;And function is found using position, it determines to specify section in the first XML message
The position of the bebinning character of point.
Preferably, above-mentioned apparatus, further includes:
Preserving module 25, the correlation for each element that all specified nodes for respectively obtaining parsing module 24 are included
Information preservation is into HASHMAP, so that called side calls the relevant information of required element.
Obviously, various changes and modifications can be made to the invention without departing from essence of the invention by those skilled in the art
Mind and range.In this way, if these modifications and changes of the present invention belongs to the range of the claims in the present invention and its equivalent technologies
Within, then the present invention is also intended to include these modifications and variations.
Claims (6)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310752479.XA CN104753891B (en) | 2013-12-31 | 2013-12-31 | A kind of XML message analysis method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310752479.XA CN104753891B (en) | 2013-12-31 | 2013-12-31 | A kind of XML message analysis method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN104753891A CN104753891A (en) | 2015-07-01 |
CN104753891B true CN104753891B (en) | 2019-04-05 |
Family
ID=53593006
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201310752479.XA Active CN104753891B (en) | 2013-12-31 | 2013-12-31 | A kind of XML message analysis method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104753891B (en) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106169988B (en) * | 2016-02-26 | 2019-10-15 | 北京元心科技有限公司 | The method of data is transmitted in cruising inspection system |
CN108076010B (en) * | 2016-11-10 | 2020-09-08 | 中国移动通信集团广东有限公司 | XML message parsing method and server |
EP3913879B1 (en) * | 2019-02-21 | 2024-09-25 | Huawei Technologies Co., Ltd. | Message parsing method, data sending end, data receiving end, and system |
CN112328838B (en) * | 2020-10-30 | 2024-01-26 | 中国民航信息网络股份有限公司 | Message analysis preprocessing method, system and storage medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1896992A (en) * | 2006-06-15 | 2007-01-17 | Ut斯达康通讯有限公司 | Method and device for analyzing XML file based on applied customization |
CN101071446A (en) * | 2007-06-22 | 2007-11-14 | 腾讯科技(深圳)有限公司 | Marked language archive analytical method, analytical module and user terminal |
CN102622444A (en) * | 2012-03-15 | 2012-08-01 | 深圳市同洲视讯传媒有限公司 | XML (extensible markup language) message processing method and XML message processing device |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7191186B1 (en) * | 2002-11-27 | 2007-03-13 | Microsoft Corporation | Method and computer-readable medium for importing and exporting hierarchically structured data |
KR101123426B1 (en) * | 2003-04-04 | 2012-03-23 | 야후! 인크. | A system for generating search results including searching by subdomain hints and providing sponsored results by subdomain |
JP4688111B2 (en) * | 2008-11-28 | 2011-05-25 | インターナショナル・ビジネス・マシーンズ・コーポレーション | Information processing apparatus, database system, information processing method, and program |
-
2013
- 2013-12-31 CN CN201310752479.XA patent/CN104753891B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1896992A (en) * | 2006-06-15 | 2007-01-17 | Ut斯达康通讯有限公司 | Method and device for analyzing XML file based on applied customization |
CN101071446A (en) * | 2007-06-22 | 2007-11-14 | 腾讯科技(深圳)有限公司 | Marked language archive analytical method, analytical module and user terminal |
CN102622444A (en) * | 2012-03-15 | 2012-08-01 | 深圳市同洲视讯传媒有限公司 | XML (extensible markup language) message processing method and XML message processing device |
Also Published As
Publication number | Publication date |
---|---|
CN104753891A (en) | 2015-07-01 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN104753891B (en) | A kind of XML message analysis method and device | |
CN108881172A (en) | The analysis method and device of message | |
US8145794B2 (en) | Encoding/decoding while allowing varying message formats per message | |
CN108337236A (en) | A kind of gRPC call methods and device based on Protobuf and HTTP/1.1 | |
CN101159760B (en) | Method and system for implementing communication protocol based on XML data interchange file | |
CN105099994B (en) | Message parsing method and device | |
CN1996878A (en) | A method for information conversion of the simple object access protocol service management interface | |
CN109981676A (en) | One kind being based on the customized Internet of Things information interacting method of binary system analysis protocol | |
CN109446093A (en) | A kind of expansion platform interface test method and device | |
CN106792855A (en) | The collocation method and device of a kind of WiFi equipment | |
CN109947435A (en) | The dispositions method and system of server cluster software environment | |
CN109002390A (en) | A kind of test case dynamic state of parameters configuration method and device | |
CN109767257A (en) | Advertisement placement method, system and electronic equipment based on big data analysis | |
CN104932910A (en) | Method and system for application program interface extension | |
CN105843663B (en) | Decoding method suitable for the description of ASN.1 recursion resolution data structure | |
CN110069566A (en) | Heterogeneous database synchronization method in a kind of one-way import system | |
CN105094787B (en) | Method and device for processing enterprise internet application | |
CN104572730B (en) | Digital resource importing, deriving method and device | |
US20070143330A1 (en) | Processing an XML schema | |
CN104598277A (en) | Method for building mobile terminal applications, mobile terminal and system | |
CN108494613A (en) | A kind of test system and method to interconnect between police digital cluster system | |
CN106293862B (en) | A kind of analysis method and device of expandable mark language XML data | |
CN109788034B (en) | Configuration method for gateway access equipment, electronic equipment and storage medium | |
CN106919615A (en) | Data access method and system | |
CN107133077A (en) | A kind of page end calls the method and device of locally applied function |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |