Skip to content

CDATA support #214

Open
Open

Description

@Programmierschmied

Dear developers,

I have to use mixed CDATA contents. It means that the node can have CDATA or text or both mixed.
I am not able to change the XSD Schema for a new simply type. For a fast solution I added a regex detection for the use of cdata in the jsonix.js, but I don't think that this is a good solution.
Is there a way to keep CDATA from XML file?

My fast solution:
if (this.asCDATA && value.match(/<.+>/g) != null)

Best regards,
Justin

Activity

  1. highsource commented on Mar 14, 2019

    @highsource
    Owner
  2. Programmierschmied commented on Mar 14, 2019

    @Programmierschmied
    Author

    For example:
    <content lang="de"><![CDATA[<p>Something<latex>$m \ge 1 g$</latex> text.</p>]]></content>

    if i convert it to js and back it gets to:
    <content lang="de">&lt;p&gt;Something &lt;latex&gt;$m \ge 1 g$&lt;/latex&gt; text.&lt;/p&gt;<content>

    Edit: If I turn CDATA on for this simpletype then every node gets CDATA. Even these which hadn't CDATA before.

  3. Programmierschmied commented on Mar 15, 2019

    @Programmierschmied
    Author

    Sorry to did bother you.

    I have researched in other XML to objects Parser. To mix CDATA with normal content is a mistake by XSD Design. I will please the writer of xsd file to change this.

    Thank you for your fast support!

  4. highsource commented on Mar 15, 2019

    @highsource
    Owner

    I'm on FOSSGIS2019 so I can't reply promptly.

    Technically this

    <content lang="de"><![CDATA[<p>Something<latex>$m \ge 1 g$</latex> text.</p>]]></content>
    

    is exactly the same as this

    <content lang="de">&lt;p&gt;Something &lt;latex&gt;$m \ge 1 g$&lt;/latex&gt; text.&lt;/p&gt;<content>
    

    I understand that these are different cosmetics but technically it is not really relevant.

    However I can follow that you might be interested in actual cosmetics to make XML more readable. The problem is, however the presentation in the JS side. Somehow you will need to distinguish between normal text and CDATA-text. So improving cosmetics on the XML side might lead to much more complex models on the JS side. Which, in my PoV is a too high price.

    But here's an idea. Maybe we could implement some automatic that Jsonix automatically produces CDATA sections if the text contains too much markup/special characters? Like if there are more that N &lt;s, &gt;s, &apos;es and &amp;s then automatically create a CDATA-section.
    What do you think?

  5. Programmierschmied commented on Mar 15, 2019

    @Programmierschmied
    Author

    I think this is a really good idea.
    Then we got a feature which other parsers like JAXB don't got.
    I just found out that this is a general parser problem.

  6. Programmierschmied commented on Mar 15, 2019

    @Programmierschmied
    Author

    I reopen it. So we can find a solution for. Should I write some code and do a merge request. Or do you want to write code yourself?

  7. Programmierschmied commented on Mar 15, 2019

    @Programmierschmied
    Author

    I just had an idea. Maybe you like:
    #215

    This would allow the user to do a conditional CDATA by regex.

    if ((this.asCDATA && this.CDATAcondition == null) || (this.asCDATA && value.match(new RegExp(this.CDATAcondition)) ))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions