[Expat-discuss] Special html char handling

Karl Waclawek karl at waclawek.net
Tue Dec 10 21:16:26 EST 2002



> Just a quick question, with a simple answer, I'm sure.
> 
> I have set XML_SetCharacterDataHandler to a quickly hacked function that
> should just print the element text i.e:
> 
> void showtext(void *userData, const char *s, int len)
> {
> 
> char Buff2[BUFFSIZE];
> int cnt;
> 
>   if ( ( Depth > 2) && (Element[0] != '\0') ) {
> 
>     printf("Element %s is ", Element);
> 
>     for (cnt=0; cnt < len ; cnt++)
>       Buff2[cnt]=s[cnt];
>     Buff2[cnt]='\0';
> 
>     printf("%s\n", Buff2);
>   }
>   strcpy(Element,"\0");
> }
> 
> But when parsing an XML file, html special chars such as &lt; and &amp;
> cause the output to be truncated at the spoecial character ampersand. Does
> XML_Parse do the conversion or am I missing something obvious here?

It could be that Expat reports the character data in multiple calls,
since the dereferencing of the character entity references interrupts
the character stream. Maybe you are only checking the first callback,
instead all of them.

Karl



More information about the Expat-discuss mailing list