Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.

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

Open
saleyn opened this issue Jun 6, 2015 · 3 comments
Open

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

saleyn opened this issue Jun 6, 2015 · 3 comments

Comments

@saleyn
Copy link
Contributor

saleyn commented Jun 6, 2015

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
Copy link

dajose commented Jul 1, 2015

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

@dajose
Copy link

dajose commented Jul 6, 2015

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?

Sekenre added a commit to Sekenre/gsl that referenced this issue Sep 26, 2016
Solution: Treat it as a comment. Possible fix for issue imatix#98
@MaxSagebaum
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants