0

I have a requirement to read Json from config xml with name value pair which has CDATA.

My xml structure looks like below

<cfgsection name="test" value="<![CDATA[{Json data goes here}]]>"/>

I would like to know can CDATA be inside a plane string [""] since the documentation suggests that it should be inside a node/element?

Can any one shed some light on this?

1 Answer 1

1

CDATA can only appear as part of element content, not as part of an attribute value. (It's easier to ask questions and understand the answers if you learn the correct terminology...)

That means you can write

<prop name="test"><![CDATA[{Some Json}]]></prop>

but you can't write

<prop name="test" value="<![CDATA[{Some Json}]]>"/>

CDATA, of course is just a device for escaping special characters, and there are other ways of escaping special characters in attributes. In fact, if you use single quotes around an attribute

<prop name="test" value='{"key":value, "data":[1,2,3]}'/>

then you usually won't need any escaping at all, unless your JSON data happens to contain strings with "'" or "<" in them -- in which case they can be written as XML character references.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.