Re: is the string passed by expat handler available ...
Nick MacDonald <[email protected]> Thu, 2 Jun 2011 15:18:04 -0400
| Newsgroups | gmane.text.xml.expat.general |
|---|---|
| Message-ID | <[email protected]> |
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 =3D data;
if (null !=3D attr)
{
if (null !=3D attr[0])
{
strncpy(myData->myString, attr[0], sizeof(myData.myString));
}
}
}
On Thu, Jun 2, 2011 at 4:56 AM, BZ=A0Wright <[email protected]> wrote:
> hello everyone, who can tell me whether a string passed by an handler ava=
ilable 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)
> {
> =A0 reserve_for_use =3D el; =A0 // or attr
> }
> after the start_element return, is reserve_for_use available for future u=
se ?
> I have tested this and it works (before XML_ParserFree), I wonder is this=
a valid usage in expat.