[jdom-interest] my last CDATA comment (I promise)

Kevin Regan kevinr at valicert.com
Sat Jun 3 14:39:04 PDT 2000


On Sat, 3 Jun 2000, Jason Hunter wrote:

> > Now, you can imagine the huge efficiency hit that the
> > second output method causes.  We have to (1) create a
> > StringBuffer for the new string, (2) look at every character
> > in the output against 4 possible restricted characters
> > in a switch statement, (3) replace 1 character with 4
> > (or 5 for &) characters for each escaped character,
> > (4) create a new String from the newly created StringBuffer
> > (oh, and (0) call the escape method in the first place).
> > 
> > For the first output we (1) do nothing special.  We just
> > output the string as is (wrapped in <![CDATA[...]]>).
> 
> Not entirely true.  You have to search the CDATA text for the CDATA
> terminal string and escape it wherever it should appear.
> 

The text (String) within the CDATA object does not contain
the CDATA terminal string:

public class CDATA {
	String value = "<TAG>The value <<<<<>>>>> to be escaped</TAG>";

	public String getOutput() {
		return "<![CDATA[" + value + "]]>";
	}
}

The return value of getOutput() is inserted into the XMl
document directly.  There is no need to examine/parse value:

<![CDATA[<TAG>The value <<<<<>>>>> to be escaped</TAG>]]>

For the alternative (no CDATA), we need to parse value and
output the following to the XML file:

&lt;TAG&gt;The value &lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt; to be
escaped&lt;TAG&gt 





More information about the jdom-interest mailing list