1

I am using Spark 2.2 XML library to write data in XML format. But i want add CDATA to every value in XML like below.

<RECORD> <PROP NAME="processingTime"> <PVAL> <![CDATA[ 1499713726138 ]]> </PVAL> </PROP> <PROP NAME="isActive"> <PVAL> <![CDATA[ true ]]> </PVAL> </PROP> <PROP NAME="lineOfBusiness"> <PVAL> <![CDATA[ abc ]]> </PVAL> </PROP> <PROP NAME="language"> <PVAL> <![CDATA[ EN ]]> </PVAL> </PROP> <PROP NAME="language"> <PVAL> <![CDATA[ FR ]]> </PVAL> </PROP> </RECORD> 

Can someone suggest me how to do this in Spark Java?.Thx

5
  • "i want add CDATA to every value" Why? It just makes the XML bigger, for no reason whatsoever. None of the shown values even has any special characters that would benefit from use of CDATA. And no XML processor should ever care whether text is in a CDATA or not. The processed text should always end up the same. CDATA is simple a special encoding that eliminates the need to use &lt;, &gt;, and &amp; entities, making the XML simpler if there are a lot of them. Commented Jul 26, 2018 at 5:00
  • You can check This post stackoverflow.com/questions/9473667/…. this will help you. Commented Jul 26, 2018 at 5:28
  • yeah. in provided XML, we don't have special characters. However, i have lot other fields which had special characters. So there i need CDATA. Commented Jul 26, 2018 at 7:38
  • We are not using any java xml library to use newElement.InnerXml to add CDATA. So is there any approach to do it Spark xml library?. Commented Jul 26, 2018 at 7:41
  • Hey @Sekhar Did You find the solution for this ? I have a similar problem Spark is not giving me CDATA string. Commented Sep 15, 2021 at 11:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.