JAXB and CDATA
843834May 1 2008 — edited May 1 2008Can someone please point me in the right direction. I am having an issue with the JAXB 2.0 marshall/unmarshall and an element within an XML file.
In an XML "properties" file I have a password such: <password>some cipher text containing xml illegal characters</password>.
1. If the password is initially blank and I enter the password, it is encrypted using a key from a Keystore and saved (marshalled) to the element and all appears Ok. If I then read the password (unmarshall) I get a JAXBException basically saying that a character within the element is invalid for XML. This is quite probable as the cipher text could contain any type of character.
2. If I hack the XML file and wrap the password element value with <password><![CDATA[ . . . ]]></password>, I still get the exception but this time saying that a character - within the CDATA section - is invalid. Programatically constructing the element character string, e.g. "<![CDATA[" + "the cipher text" + "]]>" produces an exception as well.
Is it simply that JAXB doesn't support CDATA and tries to parse everything, i.e. treats all as PCDATA ? If not, what within the JAXB API can I use ? Basically I want this element's value to be passed straight to the application without any interpretation to its meaning.
Thanks