[Expat-discuss] is the string passed by expat handler available ...

BZ Wright bzwright at 163.com
Fri Jun 3 05:28:54 CEST 2011


thanks nick, i got it.
At 2011-06-03 03:18:04,"Nick MacDonald" <nickmacd at gmail.com> wrote:
>Well you cannot use the same block of memory, but you could have a
>means to make a copy.  You probably want to use the user data
>parameter (the first parameter to the callback) to have your own data
>structure in which to copy the data you want to save.
>
>So, something like this:
>
>struct sMyData
>{
>  char myString[128];
>};
>
>struct sMyData myData;
>
>XMLParse(..., &myData);
>
>static void XMLCALL start_element(void *data, const char *el, const char **attr)
>{
>  struct sMyData* myData = data;
>
>  if (null != attr)
>  {
>    if (null != attr[0])
>    {
>       strncpy(myData->myString, attr[0], sizeof(myData.myString));
>    }
>  }
>}
>
>
>On Thu, Jun 2, 2011 at 4:56 AM, BZ Wright <bzwright at 163.com> wrote:
>> hello everyone, who can tell me whether a string passed by an handler available after
>> the handler return. for code like below:
>> const char *reserve_for_use;
>> static void XMLCALL start_element(void *data, const char *el, const char **attr)
>> {
>>   reserve_for_use = el;   // or attr
>> }
>> after the start_element return, is reserve_for_use available for future use ?
>> I have tested this and it works (before XML_ParserFree), I wonder is this a valid usage in expat.



More information about the Expat-discuss mailing list