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

Kevin Regan kevinr at valicert.com
Sat Jun 3 14:45:19 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.
> 

Ok, now I see what you are talking about.  You mean something
like:

CDATA cdata = new CDATA( "Stuff with a <![CDATA[Hello!]]> in it" );

Fortunately, this is disallowed by the Xml 1.0 Specification (S 2.7),
so it does not have to be dealt with.  However, to help the
application writer, you may want to do a:

if ( value.indexOf( "]]>" ) != -1 ) {
	Error...
}

in the CDATA constructor...

--Kevni




More information about the jdom-interest mailing list