I'm trying to get cdata text from a node using dom4j java. My issue here is that all of the line breaks are removed. Essentially, I need to read the contents of the CDATA as if it were a <pre开发者_运维百科> tag in HTML.
Do you have any ideas? I have a very small time to get this done unfortunately so any help would be appreciated.
Thanks!
If you need XML text to be statically defined as in a CDATA block, it must be flagged this way in the XML as such:
<tag><![CDATA[This is
three
lines]]></tag>
If your contents is not inside a CDATA section, i.e.:
<tag>This is
three
lines</tag>
normal XML processing will occur which means that the whitespace is normalised.
Yup, the contents were fine. I figured out the error, it was a data issue.
dom4j automatically does NOT remove whitespace in cdata sections. I was reading in file contents from a buffered reader and used readLine and did not re-append line breaks, causing the entire xml document to be a 1-liner, causing my cdata section to be one line as well.
Sorry for not responding earlier, I had figured this out a couple of days ago...
Thanks!
精彩评论