imatix / gsl

iMatix GSL code generator
http://www.imatix.com
GNU General Public License v3.0
539 stars 107 forks source link

Handling XML <![CDATA[...]]> #98

Open saleyn opened 9 years ago

saleyn commented 9 years ago

It seems that there's a problem in the XML parser not recognizing <![CDATA[...]> constructs:

<protocol>
    <verbatim location="include" lang="c++"><![CDATA[#include "EventTypes.h"]]></verbatim>
    <msg name="order">
        <verbatim><![CDATA[static const size_t ID_NEW = to_int<'N','D'>::value;]]></verbatim>
        <field name="ord_cond"/>
    </msg>
</protocol>

Here's the output:

$ gsl -script:specs/test.gsl -dir:. specs/test.xml 
2015/06/06 13:05:55: GSL/4.1a/github Copyright (c) 1996-2011 iMatix Corporation
2015/06/06 13:05:55: gsl/4 I: Processing specs/test.xml...
2015/06/06 13:05:55: gsl/4 E: Error processing specs/test.xml...
2015/06/06 13:05:55: specs/test.xml 2:     <verbatim location="include" lang="c++"><![
'--' or DOCTYPE declaration expected
dajose commented 9 years ago

I am facing the same problem, is there any progress solving this?

dajose commented 9 years ago

I was reading the src, I came with a parcial solution by modifing "xml_load_item()" on sflxmll.c. Basically I added the following after the "DOCTYPE" conditional

      else if (c == '[') {
          item_name = buf_get_name (buf);
           if (!item_name || !strcmp (item_name, "![CDATA["))
             {
               set_error (buf, "'--' or ![CDATA[ declaration expected");
               return XML_LOADERROR;
             }
           mem_free (item_name);

           CHECK_BUF_STATE;
           if (res != XML_NOERROR)
                             {
               set_error (buf, "'>' expected");
               return res;
             }
         }

I wonder if that is the best place to fix our issue. I also have been thinking what should be best: remove the CDATA tag from output or not?

MaxSagebaum commented 6 years ago

I have the same problem and written up a crude patch as an example how it could be implemented.

If such an addition would be welcome I could then modify the patch in order to add more checks make it more robust etc.. If yes, I would appreciate some comments on how the same functionality can be archived with more functionality that is already available in gsl.

https://gist.github.com/MaxSagebaum/2c2e3443ca36e093e65025692bfc1220#file-0001-hanlding-of-cdata-as-one-single-value-item-patch