[Expat-discuss] Getting xml element data...
Jez Higgins
jez at jezuk.co.uk
Fri Jul 21 11:04:33 CEST 2006
Nikola wrote:
> Hello,
>
> I am trying to parse simple xml file and process text value in elements
> (eg. <e>some text</e>).
> but when my "processText" functions gets called on text element....it
> also contains ending tag.....
>
> How can I get only text....i am sure that library is not designed to
> return ending tag in text value
> of xml element.
>
> I accept posibility that I am doing soemthing wrong.....
>
You are :)
> static void XMLCALL
> processText(void *userData, const char *data, int len)
> {
>
> if(status && !strcmp(gname,"data")){
> printf("[%s]",data);
> status = 0;
> }
> }
You are treating data as a pointer to a nul-terminated string. It
isn't. It points into the buffer expat is parsing. The len parameter
tell you the end point of the character data.
The text you want is from data to data+len. In the example you've given
you could use a loop and putchar to output it.
Jez
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 250 bytes
Desc: OpenPGP digital signature
Url : http://mail.libexpat.org/pipermail/expat-discuss/attachments/20060721/101900e3/attachment.pgp
More information about the Expat-discuss
mailing list