Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDATA support #214

Open
Programmierschmied opened this issue Mar 14, 2019 · 7 comments
Open

CDATA support #214

Programmierschmied opened this issue Mar 14, 2019 · 7 comments

Comments

@Programmierschmied
Copy link

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

@highsource
Copy link
Owner

highsource commented Mar 14, 2019 via email

@Programmierschmied
Copy link
Author

Programmierschmied commented Mar 14, 2019

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.

@Programmierschmied
Copy link
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!

@highsource
Copy link
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?

@Programmierschmied
Copy link
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.

@Programmierschmied
Copy link
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?

@Programmierschmied
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants