CDATA Attributes in java.util.prefs.Preferences

Anyone know why CDATA contents don't seem to work as a value in a key/value pair with java.util.prefs.Preferences? I'm using jdk1.4.2. It would be _really_ nice to allow embedded XML

via a mechanism like:

<node name="MyNodeName">

<map>

<entry key="aSpecificKey" value='&lt;![CDATA[This <begin>is a test</begin> string]]&gt;' />

</map>

</node>

but the parser chokes on this. [Note: yes, I do know that I can use the "put" method followed by the exportSubtree to get the XML encoded in a manner that is digestable by Preferences. However, this isn't very useful as I was planning another, GUI-based, means of creating the XML, so CDATA seemed like a natural fit...]

[777 byte] By [jgamache] at [2007-9-30 16:09:08]
# 1

You don't need the CDATA stuffed in that way. CDATA is part of the dtd description at http://java.sun.com/j2se/1.5.0/docs/api/java/util/prefs/Preferences.html

You would write the xml like:

<node name="MyNodeName">

<map>

<entry key="aSpecificKey" value="is a test" />

</map>

</node>

You code use an XML editor with validation turned on. to check the xml as you go.

Martin3 at 2007-7-5 23:39:52 > top of Java-index,Administration Tools,Sun Connection...
# 2

but there is no embedded XML in the what you wrote. Without embedded XML, I concur everything works fine. Admittedly, my example was quite lame - but it has an embedded <begin> </begin> tag in it. I don't want the SAX parser that Preferences uses to try to process these tags as they are for use by my application...

jgamache at 2007-7-5 23:39:52 > top of Java-index,Administration Tools,Sun Connection...
# 3
Why are you using the preferences as a way to 'embed' xml?
Martin3 at 2007-7-5 23:39:52 > top of Java-index,Administration Tools,Sun Connection...
# 4
because I need to have a key/value pair where the value is xml...
jgamache at 2007-7-5 23:39:52 > top of Java-index,Administration Tools,Sun Connection...
# 5
Then you need to escape all the value xml and after reading it in from the preferences xml; run it thru a parser and use it resulting DOM
Martin3 at 2007-7-5 23:39:52 > top of Java-index,Administration Tools,Sun Connection...
# 6
Yes, with no other obvious approach, that was what I did.However, do you or anyone know _why_ CDATA does not work?
jgamache at 2007-7-5 23:39:52 > top of Java-index,Administration Tools,Sun Connection...
# 7
CDATA is a dtd construct
Martin3 at 2007-7-5 23:39:52 > top of Java-index,Administration Tools,Sun Connection...