The analytic method of XML formatted data of dynamic content distribution client terminal
One, technical field
The present invention relates to the data parsing method in the TD-SCDMA portable terminal, the analytic method of particularly a kind of dynamic content dispensing (being called for short DCD) client XML formatted data all can be realized in various portable terminals.
Two, background technology
Dynamic content dispensing (DCD) is to experience for the information browse that strengthens the terminal use, the mode of downloading or pushing through the cycle, the content update of user individual customization in user's terminal.Dynamic content dispensing has greatly been simplified the mode that content is found and content obtains, and has reduced user's use difficulty, makes things convenient for the user to obtain the content of wanting most.These contents increase user's interactivity through lively representing, and attract the user initiatively to browse more relevant content.
DCD news flash service bearer on the TD-SCDMA network, has been reduced period of reservation of number, can better combine with multimedia function, promoted user experience, the user need not to stand wait process very long under the GSM/GPRS.
Specifically, the weak point of GSM/GPRS is: speed is not high, can not carry out voice service and data service simultaneously; TD-SCDMA then is that these application of carrying and business provide good platform, and TD-SCDMA is that application and business have been established powerful basis at following technical elements:
■ High Data Rate: TD-SCDMA can accomplish the maximum downstream data transmission bauds of 384kbps in the Release4 version, in the Release5 version, can reach the maximum downstream data transmission bauds above 2Mbps through the HSDPA technology especially.
■ voice service and data service are not disturbed mutually: possess the ability of carrying out voice service and data service simultaneously.
The ■ network automaticallyes switch: can carry out seamless business with existing GSM/GPRS network and switch, guarantee professional in time with the space on continuity.
The dynamic content distribution service system configuration is as shown in Figure 1, has described three professional big parts of whole news flash: DCD server, interior perhaps service provider and DCD client and relation thereof.Wherein DCD1 is the interface between dynamic content distribution server and the DCD terminal.The DCD1 interface adopts HTTP1.1 as bearing protocol, with the XML language expression.
Fig. 2 has explained the processing and the relation thereof of main affairs with mode end to end, has described the transaction of carrying out data sync and the relation thereof of DCD client and DCD server.Wherein data are downloaded the inclusion employing XML that responds and are organized data; Just said in the present invention DCD XML bag; Its structure is described in detail in 6.4 trifles in " the dynamic content distribution service interface specification v1.0.0 of China Mobile ", and this structure comprises starting and ending label, < meta>metadata tag, < feed>channel identication label, <entry>channel item label of < sync-pkg>response message etc.The analysis mode of XML document is had multiple, SimpleAPI for XML (SAX) is exactly wherein a kind of.Simple API for XML (being called for short SAX) is a kind of event driven API (application programming interfaces).The different piece of XML tag (like beginning and end-tag, text, entity) triggers special incident, and the developer is these event registration handler code.
Then, resolver sends flow of event according to the XML of input, and handler code is handled these incidents successively.The advantage of this processing is similar to the advantage of Streaming Media very much.Analysis can begin immediately, rather than waits for that all data are processed.And, because application program is just checked data when reading of data, therefore need be in internal memory with storage.This is a huge advantage for large-scale document.In fact, application program even must not resolved entire document.It can stop to resolve when certain condition is met.
And the Expat storehouse is the event-oriented XML parsing of the original open source code of James Clark storehouse, has followed the SAX rule.He has transferred a group among the SourceForge with this project.In numerous items, can find the Expat resolver, like open source code browser Mozilla, xslt processor Transformiix and RDF instrument repat.Pluses and minuses comprise: the code of relative lightweight, of many uses, comparative maturity is stable.But do not support checking.
The function interface in Expat storehouse involved in the present invention mainly contains beginning tag processes function XML_StartElementHandler, end-tag is handled function XML_EndElementHandler, tag data process function XML_CharacterDataHandler, resolver establishment function: XML_ParserCreate_MM, analyzing XML data function XML_Parse and resolver and discharged function: XML_ParserFree.
● beginning tag processes function: XML_StartElementHandler
[type definition]
typedef?void(*XML_StartElementHandler)(void*userData,
const?XML_Char*name,
const?XML_Char**atts);
[function performance]
By user definition, be used to handle the function of beginning label.
[parameter declaration]
[inlet]: userData: the user data pointer, represent not have during for NULL.
Name: the name word string of label.
Atts: the attribute word string array of pointers of label is end with NULL.
[outlet]: do not have
● end-tag is handled function: XML_EndElementHandler
[type definition]
typedef?void(*XML_EndElementHandler)(void*userData,
const?XML_Char*name);
[function performance]
By user definition, be used to handle the function of end-tag.
[parameter declaration]
[inlet]: userData: the user data pointer, represent not have during for NULL.
Name: the name word string of label.
[outlet]: do not have
● tag data process function: XML_CharacterDataHandler
[type definition]
typedef?void(*XML_CharacterDataHandler)(void*userData,
const?XML_Char*s,
int?len);
[function performance]
By user definition, be used to handle the function of label data.
[parameter declaration]
[inlet]: userData: the user data pointer, represent not have during for NULL.
S: the word string of label data.Note, do not finish with ' 0 '.Need to judge through len
Len: the length of word string.
[outlet]: do not have
● resolver is created function: XML_ParserCreate_MM
[function prototype]
XML_Parser?XML_ParserCreate_MM(const?XML_Char*encoding,
const?XML_Memory_Handling_Suite*memsuite,
const?XML_Char*namespaceSeparator);
[function performance]
Use the memory management function of user's appointment to create a new resolver object.
[parameter declaration]
[inlet]: encodingName: the coded system of resolution data.Represent to use built-in form during for NULL.
Totally four kinds: US-ASCII, UTF-8, UTF-16, ISO-8859-1
Memsuite: the memory management function of user's appointment.Use the function of standard C during for NULL.
NamespaceSeparator: whether handle name space.Do not handle during for NULL.
[outlet]: do not have
[return value]
XML_Parser: the Handler that points to the resolver object.
● analyzing XML data function: XML_Parse
[function prototype]
XML_Status?XML_Parse(XML_Parser?parser,
const?char?*s,
int?len,
int?isFinal);
[function performance]
Resolve the xml data.
[parameter declaration]
[inlet]: parser: the Handler of resolver.
The s:xml data pointer.
The len:xml data length.
The isFinal:xml end-of-data mark.
[outlet]: do not have
[return value]
XML_Status
● resolver discharges function: XML_ParserFree
[function prototype]
void?XML_ParserFree(XML_Parser?parser);
[function performance]
Discharge resolver.
[parameter declaration]
[inlet]: parser: the Handler of resolver.
[outlet]: do not have
[return value]
Void
Three, summary of the invention
The present invention proposes a kind of analytic method of XML formatted data of dynamic content distribution client terminal; Realize the analytic method of the XML formatted data of dynamic content dispensing (DCD) client, followed the interface standard in the dynamic content distribution service TD-SCDMA of the China Mobile terminal technology standard.
For solving the problems of the technologies described above, technical scheme of the present invention is following:
A kind of analytic method of XML formatted data of dynamic content distribution client terminal may further comprise the steps:
Step 1, dynamic content distribution client terminal are initiated data synchronization request to server;
After step 2, dynamic content distribution client terminal are downloaded server data sent synchronous response message and be saved in the memory cache district, wherein response inclusion is saved in the XML file;
Step 3, open said XML file, current parse state of record and position in beginning tag processes function if the beginning label is metadata, channel or channel item, will makes up or the initialization related data structure, and enter into corresponding parse state;
Step 4, according to current parse state and the beginning label metadata, channel or channel item are resolved;
Step 5, handle at end-tag that record changes current parse state and position in the function;
Step 6, close said XML file.
Said step 3 comprises:
Whether according to current beginning label is DCD XML bag, metadata, channel, channel item; Current parse state and position are set; If the beginning label is metadata, channel or channel item, then make up or the initialization related data structure, comprise following five kinds of situation:
3.1, to DCD XML packet start label:
Parse state is set is " analyzing XML begins "; Not and current not being in any metadata, channel or the channel item;
3.2, metadata is begun label:
Parse state is set is " the analytical element data begin "; And it is metadata that current parsing position is set;
3.3, channel is begun label:
Parse state is set is " resolving channel begins "; And make up channel and add in the channel list, current parsing position is set is this channel;
3.4, channel item is begun label:
Parse state is set is " resolving channel item begins "; And make up channel item and add in the channel item tabulation, current parsing position is set is this channel item;
3.5, to other beginning label: only write down current label, parse state and position need not be set.
Said step 4 comprises three kinds of situation:
4.1, parse state is " the analytical element data begin ":
Current metadata is resolved, and is the metadata data structure with the metadata conversion of XML form;
4.2, parse state is " resolve channel begin ":
Current channel is resolved, and is the channel data structure with the channel switch of XML form;
4.3, parse state is " resolve channel item begin ":
The current channel item is resolved, convert the channel item of XML form into the channel item data structure.
Said step 5 comprises:
5.1, to DCD XML end-of-packet label:
Parse state is set is " analyzing XML end ", and the current parsing position of resetting;
5.2, to the metadata end-tag:
Parse state is set is " analytical element ED ", and the current parsing position of resetting;
5.3, to the channel end-tag:
Parse state is set is " resolving channel finishes ", and the current parsing position of resetting;
5.4, to the channel item end-tag:
Parse state is set is " resolving channel item finishes ", and the current parsing position of resetting;
5.5, to other end-tags:
Parse state and parsing position are not handled.
Compared with prior art, the invention has the beneficial effects as follows:
The present invention proposes a kind of analytic method of XML formatted data of dynamic content distribution client terminal, in various portable terminals, all can realize.Analytic method of the present invention has good analytical framework, is easy to expansion.In addition, the inventive method is simple, and is well arranged, and higher reliability is arranged.
Four, description of drawings
The dynamic content distribution service system configuration sketch map of Fig. 1 the inventive method.
The data synchronization request message flow sketch map of Fig. 2 the inventive method.
The resolving flow process figure of the DCD XML file of Fig. 3 the inventive method.
The parse state of Fig. 4 the inventive method more newly-installed flow chart has explained how write down according to the beginning label and change current parse state and make up as required or the process of initialization related data structure.
The classification process of analysis figure of Fig. 5 the inventive method, explained according to altered parse state with the beginning label to metadata (meta), the process that channel (feed) or channel item (entry) are resolved.
The metadata of Fig. 6 the inventive method (meta) process of analysis figure, clear specifically parsing to metadata (meta).
The channel of Fig. 7 the inventive method (feed) process of analysis figure, clear specifically parsing to channel (feed).
The channel item of Fig. 8 the inventive method (entry) process of analysis figure, clear specifically parsing to channel item (entry).
The end-tag process chart of Fig. 9 the inventive method has been described the classification process that end-tag is carried out.
Five, embodiment
Do further detailed explanation below in conjunction with accompanying drawing and embodiment specific embodiments of the invention, but should not limit protection scope of the present invention with this.
As shown in Figure 2; After data synchronization request is initiated at the DCD terminal; Through the content that the mutual affirmation server with the DCD server need send, the DCD terminal is sent the data download request and is given the DCD server then, and the DCD server sends data sync response message and gives the DCD terminal then; The DCD terminal just can begin the resolving of DCD XML file after data download synchronous response message and response inclusion that will be wherein are saved in the file.
This method need interdependently realize in the mobile phone software and hardware of integral body.The concrete realization as follows:
One, the analytic method of XML formatted data is a standalone module, mainly relevant data structure is resolved and formed to the file of DCD XML form, and public interface function is being provided, and supplies other professional modules of news flash to use.
Two, concrete operations:
The analytic method of XML formatted data of dynamic content distribution client terminal of the present invention may further comprise the steps:
Step 1, dynamic content distribution client terminal are initiated data synchronization request to server;
After step 2, dynamic content distribution client terminal are downloaded server data sent synchronous response message and be saved in the memory cache district, wherein response inclusion is saved in the XML file;
Step 3, open said XML file, current parse state of record and position in beginning tag processes function if the beginning label is metadata, channel or channel item, will makes up or the initialization related data structure, and enter into corresponding parse state;
Step 4, according to current parse state and the beginning label metadata, channel or channel item are resolved;
Step 5, handle at end-tag that record changes current parse state and position in the function;
Step 6, close said XML file.
Specify the present invention below in conjunction with specific embodiment.Seeing also Fig. 3, is the main flow chart of resolving of the present invention.The resolving of DCD XML file is that the function interface that calls in the Expat storehouse comes whole XML file is resolved.
1, open the XML file of dynamic content distribution client terminal after, create function XML_ParserCreate_MM through resolver and create resolver handle (parser).
2, through tag processes function XML_SetElementHandler event handling is set; When running into the beginning label, call beginning tag processes function S tartElementHandler and handle, when running into end-tag, call end-tag processing function DCDXML_EndElementHandler and handle.
3, read the XML file to interim memory cache district, resolve the DCD XML data that read out, till the data in file have all been resolved, in the memory cache district, make up DCD XML packet (sync-pkg) through analyzing XML data function XML_Parse.
4, discharge function XML_ParserFree through resolver and discharge resolver handle (parser), and close DCD XML file.
The false code of the above-mentioned resolving of the present invention is described as:
{
Open file;
parser=XML_ParserCreate_MM(...);
// the tag processes function is set
// handle when meeting beginning label call function DCDXML_StartElementHandler
// call function DCDXML_EndElementHandler handles when running into end-tag
XML_SetElementHandler(parser,
DCDXML_StartElementHandler,
DCDXML_EndElementHandler);
Other settings to resolver;
do
{
Read file data;
XML_Parse (parser, file data ...);
While (file does not run through complete);
XML_ParserFree(parser);
Close file;
}
Main DCD XML data parsing is carried out with handling by beginning tag processes function (DCDXML_StartElementHandler) and end-tag processing function (DCDXML_EndElementHandler), and related label, function and the flow process in the face of above-mentioned two functions describes down:
1. general description
1.1 beginning tag processes function (DCDXML_StartElementHandler): write down current parse state and position; If the beginning label is metadata (meta); Channel (feed) or channel item (entry) will make up or the initialization related data structure, and enter into corresponding parse state (idiographic flow is explained in part 2); And according to current parse state with the beginning label to metadata (meta), channel (feed) or channel item (entry) are resolved (idiographic flow is explained) in the 3rd part;
1.2 end-tag is handled function (DCDXML_EndElementHandler): record changes current parse state and position (idiographic flow is explained) in the 4th part;
1.3 related main label comprises: DCD XML packet (sync-pkg), metadata (meta), channel (feed), channel item (entry).
2. whether be DCD XML bag (sync-pkg), metadata (meta), channel (feed) or channel item (entry) according to current beginning label; Current parse state and position are set; If the beginning label is metadata, channel or channel item; Then make up or the initialization related data structure, comprise following five kinds of situation, as shown in Figure 4.
2.1 to DCD XML packet start label (< sync-pkg >):
Be provided with parse state for " analyzing XML begins " (DCDXML_START); And the current any metadata (meta) that is not in, channel (feed) is in the channel item (entry);
False code is following:
The label that cur_element_id=is current;
parser_status=DCDXML_START;
cur_meta=NULL;
cur_feed=NULL;
cur_entry=NULL;
Wherein variable declaration is as shown in table 1:
Table 1
Name variable |
Variable declaration |
cur_element_id |
Represent current label |
parser_status |
Represent that current parse state has following parse state: " initial condition "; (DCDXML_INIT) " analyzing XML begins "; (DCDXML_START) " analytical element data; (meta) beginning "; (DCDXML_META_START) " analytical element data; (meta) finish "; (DCDXML_META_END) " resolve channel; (feed) beginning "; (DCDXML_FEED_START) " resolve channel item; (entry) finish "; (DCDXML_ENTRY_END) " resolve channel item; (entry) beginning "; (DCDXML_ENTRY_START) " resolve channel; (feed) finish "; (DCDXML_FEED_END) " end-state "; (DCDXML_END) |
cur_meta |
Characterize current parsing position, if the current analytical element data (meta) that are in just exist<meta>With</meta>Between, cur_meta will be set to current metadata of resolving (meta) data structure |
cur_feed |
Characterize current parsing position,, just exist if current being in resolved channel (feed)<feed>With</feed>Between, cur_feed will be set to current channel of resolving (feed) data structure |
cur_entry |
Characterize current parsing position,, just exist if current being in resolved channel item (entry)<entry>With</entry>Between, cur_entry will be set to current channel item of resolving (entry) data structure |
2.2 metadata is begun label (< meta >):
Be provided with parse state for " analytical element data (meta) beginning " (DCDXML_META_START); And it is metadata that current parsing position is set; False code is following:
The label that cur_element_id=is current;
parser_status=DCDXML_META_START;
Meta attribute in cur_meta=DCD XML bag (sync_pkg) data structure;
cur_feed=NULL;
cur_entry=NULL;
2.3 channel is begun label (< feed >):
Be provided with parse state for " resolve channel (feed) beginning " (DCDXML_FEED_START); And make up channel and add in the channel list, current parsing position is set is this channel; False code is following:
The label that cur_element_id=is current;
parser_status=DCDXML_FEED_START;
cur_meta=NULL;
Cur_feed=distributes the feed memory space;
Cur_feed is joined in DCD XML bag (sync_pkg) feed that data structure comprised tabulation;
cur_entry=NULL;
2.4 channel item is begun label (<entry >):
Be provided with parse state for " resolve channel item (entry) beginning " (DCDXML_ENTRY_START); And make up channel item and add in the channel item tabulation, current parsing position is set is this channel item; False code is following:
The label that cur_element_id=is current;
parser_status=DCDXML_ENTRY_START;
Cur_entry=distributes entry data structure storage space;
Cur_entry is joined in the entry tabulation that cur_feed comprises;
2.5 to other beginning label: only write down current label, parse state and position need not be set; False code is following:
The label that cur_element_id=is current.
According to current parse state and position to metadata (meta), channel (feed) or channel item (entry) are resolved.As shown in Figure 5, be divided into 3 kinds of situation:
3.1 parse state is that " analytical element data (meta) beginning " (DCDXML_META_START), idiographic flow is as shown in Figure 6:
(meta) resolves to current metadata, with the metadata (meta) of XML form, just<meta>With</meta>Between the XML format file convert metadata (meta) data structure into; False code is following:
void?MetaParser(...)
{
switch(cur_element_id)
{
Case label < generator >:
{
Convert the attribute of < generator>label into related data structure, and be saved among the cur_meta;
}
break;
Case label < global-meta >:
{
Convert the attribute of < global-meta>label into related data structure, and be saved among the cur_meta;
}
break;
Case label < feed-meta >:
{
For distributing feed-meta data structure memory allocated space;
The attribute of < feed-meta>label is set in the feed-meta data structure of distributing just now;
The feed-meta data structure is added in the feed-meta tabulation that cur_meta comprises;
}
break;
Other begin label case:
{
}
break;
default:
break;
}
}
3.2 parse state is that " resolving channel (feed) beginning " (DCDXML_FEED_START), idiographic flow is as shown in Figure 7.
(feed) resolves to current channel, with the channel (feed) of XML form, just<feed>With</feed>Between the XML format file convert channel (feed) data structure into; False code is following:
void?FeedParser(...)
{
switch(cur_element_id)
{
Case label < feed >:
{
Converting the attribute of < feed>label into related data structure is saved among the cur_feed;
}
break;
Case label < link >:
{
Converting the attribute of < link>label into related data structure is saved in the link structure that cur_feed comprises;
}
break;
Case label < content >:
{
The memory space that distributes the content structure;
Converting the attribute of < content>label into related data structure is saved in this content structure;
This content structure is joined in the content structure list that cur_feed comprises;
}
break;
Other begin label case:
{
}
break;
default:
break;
}
}
3.3 parse state is that " resolving channel item (entry) beginning " (DCDXML_ENTRY_START), idiographic flow is as shown in Figure 8.
(entry) resolves to the current channel item, with the channel (entry) of XML form, just<entry>With</entry>Between the XML format file convert channel item (entry) data structure into; False code is following:
void?EntryParser(...)
{
switch(cur_element_id)
{
Case label <entry >:
{
Convert the attribute of label <entry>into related data structure, and be set among the cur_entry;
}
break;
Case label < link >:
{
Convert the attribute of label < link>into related data structure, and be set in the link data structure that cur_entry comprises;
}
break;
Case label < content >:
{
The memory space that distributes the content structure;
Converting the attribute of < content>label into related data structure is saved in this content structure;
This content structure is joined in the content structure list that cur_entry comprises;
}
break;
Other begin label case:
{
}
break;
default:
break;
}
}
4. handle current parse state and the position of record change in the function at end-tag.End-tag is handled, and idiographic flow is as shown in Figure 9.
4.1 to DCD XML end-of-packet label (</sync-pkg>):
Be provided with parse state for " analyzing XML end " (DCDXML_END), and the current parsing position of resetting; False code is following:
parser_status=DCDXML_END;
cur_meta=NULL;
cur_feed=NULL;
cur_entry=NULL;
4.2 to the metadata end-tag (</meta>):
Be provided with parse state for " analytical element data (meta) end " (DCDXML_META_END), and the current parsing position of resetting; False code is following:
parser_status=DCDXML_META_END;
cur_meta=NULL;
cur_feed=NULL;
cur_entry=NULL;
4.3 to the channel end-tag (</feed>):
Be provided with parse state for " resolve channel (feed) finish " (DCDXML_FEED_END), and the current parsing position of resetting; False code is following:
parser_status=DCDXML_FEED_END;
cur_meta=NULL;
cur_feed=NULL;
cur_entry=NULL;
4.4 to the channel item end-tag (</entry>):
Be provided with parse state for " resolve channel item (entry) finish " (DCDXML_ENTRY_END), and the current parsing position of resetting; False code is following:
parser_status=DCDXML_ENTRY_END;
cur_entry=NULL;
4.5 to other end-tags:
Parse state and parsing position are not handled.
The above is merely preferred embodiment of the present invention, is not to be used for limiting practical range of the present invention.Be that all equivalences of doing according to the content of claim of the present invention change and modification, all should be technological category of the present invention.