-
Notifications
You must be signed in to change notification settings - Fork 82
Add CDATA support #175
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
Add CDATA support #175
Conversation
Please note that a property declared as: {
type: 'element',
name: 'cdata',
typeInfo: 'CDATA'
} will be marshalled as: <![CDATA[element value]]> instead of: <cdata>
<![CDATA[element value]]>
</cdata> I hope that makes sense. This is because properties of type |
Thank you!
I'll check this when I come back from vacations (after 18.06).
To be honest, I'm a bit worried about marshalling an element property without element. How would that Even work on unmarshalling?
I think the type should be orthogonal to the property type. It should work no matter which property is used, and in both directions (marshalling and unmarshalling). This will probably require refactoring how simple types work, but then so be it.
… Am 08.06.2017 um 15:15 schrieb Olivier Guyot ***@***.***>:
Please note that a property declared as:
{
type: 'element',
name: 'cdata',
typeInfo: 'CDATA'
}
will be marshalled as:
<![CDATA[element value]]>
instead of:
<cdata>
<![CDATA[element value]]>
</cdata>
I hope that makes sense. This is because properties of type value can only be marshalled by writing text in the element, and that would have been difficult/messy to change. Using a property element made more sense in my opinion.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
You're probably right about unmarshalling, to be honest I haven't tested this yet as I needed pretty badly to have the marshalling part functional. After sleeping on it, I though that maybe the right way to do this would be to add another property type called The CDATA type I added wouldn't be needed altogether. Using a value property: {
type: 'value',
name: 'data',
typeInfo: 'String'
} would give: <root>element value</root> Whereas using a CDATA property: {
type: 'CDATA',
name: 'data',
typeInfo: 'String'
} would give: <root><![CDATA[element value]]></root> What do you think? |
No, CDATA property type won't work well. CDATA is actually just a modifier for marshalling simple types. I think this should be an option of the simple type or of the property.
… Am 09.06.2017 um 09:32 schrieb Olivier Guyot ***@***.***>:
You're probably right about unmarshalling, to be honest I haven't tested this yet as I needed pretty badly to have the marshalling part functional.
After sleeping on it, I though that maybe the right way to do this would be to add another property type called 'CDATA' ('c' in compact mode) which would work similar to the 'value' property type, except that it would write a CDATA section instead of a simple text node in the element.
The CDATA type I added wouldn't be needed altogether.
Using a value property:
{
type: 'value',
name: 'data',
typeInfo: 'String'
}
would give:
<root>element value</root>
Whereas using a CDATA property:
{
type: 'CDATA',
name: 'data',
typeInfo: 'String'
}
would give:
<root><![CDATA[element value]]></root>
What do you think?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Something like {
type: 'value',
name: 'data',
typeInfo: 'String',
asCDATA: true
} ? |
Yes, something of that kind.
… Am 09.06.2017 um 09:56 schrieb Olivier Guyot ***@***.***>:
Something like
{
type: 'value',
name: 'data',
typeInfo: 'String',
asCDATA: true
}
?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Perfect, I'll rework the PR in that direction and write some more tests! |
@highsource better? |
I'm on vacations, will be back on 18.06. Will be able to check it then first, sorry.
… Am 13.06.2017 um 16:01 schrieb Olivier Guyot ***@***.***>:
@highsource better?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
No problem, take your time! I just wanted to have this cleaned up & functional. |
Following #173
This PR adds a new data type:
CDATA
, along with a new method inOutput.js
calledwriteCDATA
.The
CDATA
type derives from theString
type and adds a specificparse
function for unmarshalling, as well as amarshal
function which uses thewriteCDATA
function.The following compiled files are included as well:
Jsonix-all.js
Jsonix-min.js
node/scripts/jsonix.js
I've added basic tests but I'm not sure this is enough so please don't hesitate to tell me if I need to add more. In particular, I couldn't find the right place to add a test that actually does marshalling/unmarshalling.