ampersands parsed in code block

Sep 22, 2008 at 9:41 PM
(using C#, VS2005 presentation)

Given

<code>
if (a!=b && b!=c)
</code>

Sandcastle fails with "An error ocurred while parsing EntityName." I have to change && to &amp;&amp; in the code block.
Sep 22, 2008 at 10:01 PM
Hi,

That's correct.  The ampersand character has special meaning in XML so it must be escaped.

Try using the Code Block Component provided by Sandcastle Help File Builder.  It supports pulling in code snippets from actual source code files.

- Dave
Sep 22, 2008 at 10:23 PM
>>Owens: I have to change && to &amp;&amp; in the code block.
This is not Sandcastle issue, it is the XML issue. Another way is to use the CDATA tag as

<code>
<![CDATA[
if (a!=b && b!=c)
]]>
</code>

Best regards,
Paul.
Sep 22, 2008 at 10:41 PM
Hi,

Paul's suggestion is also good, but beware that CDATA sections seem to crash Visual Studio.  So I recommend only using them if you're including the documentation with an include element.

- Dave
Sep 22, 2008 at 11:01 PM
>>Dave: but beware that CDATA sections seem to crash Visual Studio.
I have only heard, it has never crashed my Visual Studio, and I use it extensively.

Best regards,
Paul.
Sep 23, 2008 at 1:05 AM
Edited Sep 23, 2008 at 1:08 AM
Hi Paul,

I'm able to reproduce crashes easily in VS 2005 by simply typing a CDATA section somewhere within XML documentation comments (C# only - I've never tried in VB).

However, the CDATA issue seems to be fixed now in VS 2008.

- Dave
Sep 23, 2008 at 1:26 AM
Edited Sep 23, 2008 at 1:27 AM
>>Dave: I'm able to reproduce crashes easily in VS 2005 by simply typing a CDATA section somewhere within XML...
This issue was thought to have being introduced by the SP, see here...
But it was fixed long ago, see here (KB940201)...

Currently, I am still using VS2005 for my work projects, I only use the VS 2008 at home for personal projects.
CDATA is an essential part of XML, so if you are still having that problem, then report it.

Best regards,
Paul.
Sep 23, 2008 at 1:54 AM
Hi Paul,

Well at least there's a hot fix :)

- Dave