navinseshadri / iksemel

Automatically exported from code.google.com/p/iksemel
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Issue about SAX parser #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I used following SAX parser given in iksemel.pdf

code:
//---------------------------------------------------------
// file name : test_sax.c

#include <stdio.h>
#include <iksemel.h>
int pr_tag (void *udata, char *name, char **atts, int type)
{
    switch (type) {
        case IKS_OPEN:
            printf ("TAG <%s>\n", name);
            break;
        case IKS_CLOSE:
            printf ("TAG </%s>\n", name);
            break;
        case IKS_SINGLE:
            printf ("TAG <%s/>\n", name);
            break;
    }
    if (atts) {
        int i = 0;
        while (atts[i]) {
            printf (" ATTRIB %s=’%s’\n", atts[i], atts[i+1]);
            i += 2;
        }
    }
    return IKS_OK;
}
enum ikserror pr_cdata (void *udata, char *data, size_t len)
{
    int i;
    printf ("CDATA [");
    for (i = 0; i < len; i++)
        putchar (data[i]);
    printf ("]\n");
    return IKS_OK;
}
int main (int argc, char *argv[])
{
    iksparser *p;
    p = iks_sax_new (NULL, pr_tag, pr_cdata);
    switch (iks_parse (p, argv[1], 0, 1)) {
        case IKS_OK:
            puts ("OK");
            break;
        case IKS_NOMEM:
          puts ("Not enough memory");
          exit (1);
      case IKS_BADXML:
          puts ("XML document is not well-formed");
          exit (2);
      case IKS_HOOK:
          puts ("Our hooks didn’t like something");
          exit (2);
  }
  iks_parser_delete (p);
  return 0;
}
//----------------------------------------------------------
code ends

I compile the code as

#gcc test_sax.c -o test_sax -l iksemel

then execute as

#./test_sax "<status>ptr -&gt; /dev/null</status>"

output

TAG <status>
CDATA [ptr -]
CDATA [>]
CDATA [ /dev/null]
TAG </status>
OK

I think output should look like

TAG <status>
CDATA [ptr -> /dev/null]
TAG </status>
OK

Precisely this is the output of program when I run it as

#./test_sax "<status>ptr -> /dev/null</status>"

output

TAG <status>
CDATA [ptr -> /dev/null]
TAG </status>
OK

Original issue reported on code.google.com by deshpand...@gmail.com on 9 Apr 2009 at 5:02

GoogleCodeExporter commented 9 years ago
CDATA callback is allowed to return data in multiple chunks. Parser uses this 
freedom
in order to avoid more complex string handling.

Original comment by meduke...@gmail.com on 4 Jul 2009 at 7:54