#412 XML_SetCharacterDataHandler callback function not parsing

Test Required
closed-works-for-me
nobody
None
5
2006-07-01
2006-06-15
Anonymous
No

Hello,

I have a XML_SetCharacterDataHandler callback function
that uses the text to build a directory path. I have
noticed that at times the 1st node or last node will
result in a partial capture of the text.

example.

<directory>my-57/actual image/</directory>

will return with "my-57/actual" only. I've attached my
callback functions, startelement, endelement and
dataelement.

Thank you,

Satyajit

Discussion

  • Karl Waclawek

    Karl Waclawek - 2006-06-15

    Logged In: YES
    user_id=290026

    Do not expect Expat to return all character data within an
    element in one call-back. You have to accumulate the text in
    a buffer until the end-tag is reported. Are you doing this?

     
  • sssketkar man!

    sssketkar man! - 2006-06-15

    Logged In: YES
    user_id=944435

    Thank you very much. I was expecting that the
    CharacterHandler was collecting all non-XML data in 1-shot.
    I wasn't using the EndElement as a check. I'll try that.

    Satyajit

     
  • sssketkar man!

    sssketkar man! - 2006-06-16

    Logged In: YES
    user_id=944435

    Okay, I changed my approach, so that the StartElementHandler
    sets a flag that is used by the CharacterHandler to collect
    user text until the EndElementHandlers is called at which
    point the buffered text is retreived. This approach seems
    to work expect for the last "iteration", i.e if there are 5
    nodes, the first 4 are parsed properly. The last one is
    still not getting buffered all the way or correctly.

    Here is a debug output from each Handler...

    START: tool
    START: tooladdress
    END: tooladdress
    START: imageid
    END: imageid
    START: directory
    END: directory
    XXY-WER/Actual Image/ <-- correct
    END: tool
    START: tool
    START: tooladdress
    END: tooladdress
    START: imageid
    END: imageid
    START: directory
    END: directory
    XYZ-W3/Actualage//e/ <-- not so correct
    END: tool

    As you can see the last tool node directory is incorrect, it
    should have been XYZ-W3/Actual Image/

    Thank you,

    Satyajit

     
  • sssketkar man!

    sssketkar man! - 2006-06-16

    Logged In: YES
    user_id=944435

    Also, out of curiousity, is the CharacterHandler called on a
    timed basis, ie time-sliced? Many the last node directory
    isn't getting buffered correctly because of timing issue
    between the StartElementHandler and EndElementHandler.

    Satyajit

     
  • sssketkar man!

    sssketkar man! - 2006-06-16

    Logged In: YES
    user_id=944435

    Thought it might be useful, here is the XML file.

    <XRT><Well>test</Well><Run>500</Run><DownloadTimeELS>1150211188</DownloadTimeELS><DownloadTime>13-Jun-06
    15:06:28</DownloadTime><Tools><Tool><ToolAddress>1</ToolAddress><ImageID>0</ImageID><Directory>A/Actual
    Image/</Directory></Tool><Tool><ToolAddress>7</ToolAddress><ImageID>0</ImageID><Directory>L/Actual
    Image/</Directory></Tool><Tool><ToolAddress>7</ToolAddress><ImageID>1</ImageID><Directory>D/Acoustic
    Image/</Directory></Tool><Tool><ToolAddress>1</ToolAddress><ImageID>0</ImageID><Directory>R-5/Actual
    Image/</Directory></Tool><Tool><ToolAddress>7</ToolAddress><ImageID>0</ImageID><Directory>F/Actual
    Image/</Directory></Tool><Tool><ToolAddress>6</ToolAddress><ImageID>0</ImageID><Directory>P/Actual
    Image/</Directory></Tool><Tool><ToolAddress>8</ToolAddress><ImageID>0</ImageID><Directory>P-F/Actual
    Image/</Directory></Tool><Tool><ToolAddress>11</ToolAddress><ImageID>0</ImageID><Directory>P-M/Actual
    Image/</Directory></Tool></Tools></XRT>

     
  • Karl Waclawek

    Karl Waclawek - 2006-06-16

    Logged In: YES
    user_id=290026

    I have no problem with your file.
    Maybe your parsing loop treats the last buffer incorrectly?

     
  • sssketkar man!

    sssketkar man! - 2006-06-16

    Logged In: YES
    user_id=944435

    Could you point me to an example I can look at to compare.
    I'm probably missing something obvious.

    Thanks for all your help.

    Satyajit.

     
  • Karl Waclawek

    Karl Waclawek - 2006-06-16

    Logged In: YES
    user_id=290026

    Expat comes with a few demo apps, just look at them.
    This is taken from the "elements" demo:

    main(int argc, char *argv[])
    {
    char buf[BUFSIZ];
    XML_Parser parser = XML_ParserCreate(NULL);
    int done;
    int depth = 0;
    XML_SetUserData(parser, &depth);
    XML_SetElementHandler(parser, startElement, endElement);
    do {
    int len = (int)fread(buf, 1, sizeof(buf), stdin);
    done = len < sizeof(buf);
    if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) {
    fprintf(stderr,
    "%s at line %" XML_FMT_INT_MOD "u\n",
    XML_ErrorString(XML_GetErrorCode(parser)),
    XML_GetCurrentLineNumber(parser));
    return 1;
    }
    } while (!done);
    XML_ParserFree(parser);
    return 0;
    }

     
  • Fred L. Drake, Jr.

    • status: open --> closed-works-for-me
     
  • Fred L. Drake, Jr.

    Logged In: YES
    user_id=3066

    There's no clear indication of a bug here; general Q&A
    should occur on the mailing lists, not in the bug tracker.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks