How to Use CDATA in Spring Configuration Entries

Today I had to create a map in Spring XML configuration file, where both keys and values ought to be XML elements by their own. Obviously, using CDATA is the most readable way to achieve that – but it was not immediately clear how to use CDATA for entry’s key and value attributes.

Here is what I ended with:

<util:map id="patterns">
  <entry>
    <key><value><![CDATA[<original>old-value</original>]]></value></key>
    <value><![CDATA[<replacement>new-value</replacement>]]></value>
  </entry>
</util:map>

Enjoy!

Leave a Reply