Webucator blogs about online learning and training.

You can’t nest CDATA sections in XML. It’s not allowed. But Steve Claflin, our Java trainer extraordinaire and courseware author figured out a work around.

Nesting CDATA Sections – (workaround)

Imagine you’re starting with this code:

	code here

You then want to wrap everything inside the foo tag within a CDATA section like this:

But you can’t do that, because the closing of the nested CDATA tag closes the outer CDATA tag leaving you with poorly formed XML.

Here’s the workaround Steve came up with:

	more code here

The magic is in line 5 where he splits up the closing CDATA code (i.e., ]]>) using a close and open CDATA tag. This essentially does away with the nested CDATA tag, but keeps the original content whole. Very sweet!

One Response to “Nesting CDATA Blocks”

  1. Thanks, it was of gr8 help :)


© Webucator, Inc. All rights reserved. | Toll Free: 877-932-8228 | Outside the USA: 315-849-2724 | Fax: 315-849-2723