From bzwright at 163.com Thu Jun 2 10:56:56 2011 From: bzwright at 163.com (=?UTF-8?Q?BZ=C2=A0Wright?=) Date: Thu, 2 Jun 2011 16:56:56 +0800 (CST) Subject: [Expat-discuss] is the string passed by expat handler available ... Message-ID: <54964016.1f146.1304f91db3c.Coremail.bzwright@163.com> 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. From nickmacd at gmail.com Thu Jun 2 21:18:04 2011 From: nickmacd at gmail.com (Nick MacDonald) Date: Thu, 2 Jun 2011 15:18:04 -0400 Subject: [Expat-discuss] is the string passed by expat handler available ... In-Reply-To: <54964016.1f146.1304f91db3c.Coremail.bzwright@163.com> References: <54964016.1f146.1304f91db3c.Coremail.bzwright@163.com> Message-ID: 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 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. From bzwright at 163.com Fri Jun 3 05:28:54 2011 From: bzwright at 163.com (BZ Wright) Date: Fri, 3 Jun 2011 11:28:54 +0800 (CST) Subject: [Expat-discuss] is the string passed by expat handler available ... In-Reply-To: References: <54964016.1f146.1304f91db3c.Coremail.bzwright@163.com> Message-ID: <2ba0cf83.68c9.130538be24b.Coremail.bzwright@163.com> thanks nick, i got it. At 2011-06-03 03:18:04?"Nick MacDonald" 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 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. From alexander.nikiforov at vocord.ru Sat Jun 25 11:01:51 2011 From: alexander.nikiforov at vocord.ru (gmane) Date: Sat, 25 Jun 2011 13:01:51 +0400 Subject: [Expat-discuss] question about parsing Message-ID: I All, I have this file =================== http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe urn:uuid:6973e851-f104-41e0-ba50-6e46ef649115 http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous urn:schemas-xmlsoap-org:ws:2005:04:discovery dp0:NetworkVideoTransmitter =================== but simple parser give me ====================== s:Envelope xmlns:s='http://www.w3.org/2003/05/soap-envelope' xmlns:a='http://schemas.xmlsoap.org/ws/2004/08/addressing' s:Header a:Action s:mustUnderstand='1' a:MessageID a:ReplyTo a:Address a:To s:mustUnderstand='1' s:Body Probe xmlns='http://schemas.xmlsoap.org/ws/2005/04/discovery' d:Types xmlns:d='http://schemas.xmlsoap.org/ws/2005/04/discovery' xmlns:dp0='http://www.onvif.org/ver10/network/wsdl' ====================== Why libexpat dont parse dp0:NetworkVideoTransmitter string ???? some sources init with ============================== p3_od->p = XML_ParserCreate(NULL); //p3_od->p = XML_ParserCreateNS(NULL, ' '); if( p3_od->p == NULL ) { fprintf(stderr, "Couldn't allocate memory for parser\n"); exit(-1); } XML_SetElementHandler(p3_od->p, start, end); ============================== parse with =============================== static void start(void *data, const char *el, const char **attr) { int i; p3_onvif_t *p3_od = &p3_onvif_data; for(i = 0; i < p3_od->Depth; i++) printf(" "); printf("%s", el); /* attr is array of name/value pairs, terminated by 0; */ /* names and values are 0 terminated. */ for (i = 0; attr[i]; i += 2) { printf(" %s='%s'", attr[i], attr[i + 1]); } printf("\n"); p3_od->Depth++; } /* End of start handler */ static void end(void *data, const char *el) { p3_onvif_t *p3_od = &p3_onvif_data; p3_od->Depth--; } /* End of end handler */ =============================== From fdrake at acm.org Tue Jun 28 13:17:04 2011 From: fdrake at acm.org (Fred Drake) Date: Tue, 28 Jun 2011 07:17:04 -0400 Subject: [Expat-discuss] question about parsing In-Reply-To: References: Message-ID: On Sat, Jun 25, 2011 at 5:01 AM, gmane wrote: > Why libexpat dont parse dp0:NetworkVideoTransmitter string ???? You didn't set a handler for character data. -Fred -- Fred L. Drake, Jr.? ? "Give me the luxuries of life and I will willingly do without the necessities." ?? --Frank Lloyd Wright From alexander.nikiforov at vocord.ru Wed Jun 29 12:54:13 2011 From: alexander.nikiforov at vocord.ru (gmane) Date: Wed, 29 Jun 2011 14:54:13 +0400 Subject: [Expat-discuss] question about parsing In-Reply-To: References: Message-ID: <4E0B0455.7020708@vocord.ru> Thx Fred, I'll check it and if I'll have some other problems, I'll write again. Fred Drake wrote: > On Sat, Jun 25, 2011 at 5:01 AM, gmane wrote: >> Why libexpat dont parse dp0:NetworkVideoTransmitter string ???? > > You didn't set a handler for character data. > > > -Fred >