Formatting of C# examples including literal XML

Jan 14, 2010 at 9:14 PM

 

Hi,

 

When using SHFB v1.6.0.4, the formatting of our C# examples that include literal XML script does not come out correctly. What appears is that the first line comes out as literal text, while subsequent lines appear with syntax highlighting. All of the XML script should be referred to as literal text. 

Currently, the formatting after compiling our project looks like:

      string xmlScript = @"<?xml version=""1.0"" encoding=""utf-8""?>
      <XMLScript Version=""2.0"" Name=""XMLScript Example"" ID=""123"">
         <Command Name=""XMLScriptExample"">
            <Print WaitForJobToComplete=""true"" JobName=""XMLScript Example"" 
            Timeout=""30000"" ReturnPrintData=""true"" ReturnSummary=""true"" 
            ReturnLabelData=""true"" ReturnChecksum=""true"">
               <Format>C:\Format1.btw</Format>
            </Print>
         </Command>
      </XMLScript>";

 

As literal text, it should be formatted as such:

      string xmlScript = @"<?xml version=""1.0"" encoding=""utf-8""?>
      <XMLScript Version=""2.0"" Name=""XMLScript Example"" ID=""123"">
         <Command Name=""XMLScriptExample"">
            <Print WaitForJobToComplete=""true"" JobName=""XMLScript Example"" 
            Timeout=""30000"" ReturnPrintData=""true"" ReturnSummary=""true"" 
            ReturnLabelData=""true"" ReturnChecksum=""true"">
               <Format>C:\Format1.btw</Format>
            </Print>
         </Command>
      </XMLScript>";
My SHFB project currently has both the Code Block Component and the Post-Transform Component enabled. The source code looks like:

 

      /// <example>
      /// The following example demonstrates
      /// how to use XML Script.
      ///   <code lang="cs" 
      ///    source="..\Example1.cs" 
      ///    region="Snippet1" /> 
      /// </example>
 

Any insight on how to correctly format the C# example with XML would be greatly appreciated!

~Jen

 

Coordinator
Jan 15, 2010 at 2:43 AM

Literal strings that span multiple lines are handled but the first double quote to be encountered after the start of the string will terminate it.  There is no language-specific parsing that occurs.  To work around the issue, use a single quote in place of the doubled double quotes which is still valid XML:

string xmlScript = @"<?xml version='1.0' encoding='utf-8'?>
      <XMLScript Version='2.0' Name='XMLScript Example' ID='123'>
         <Command Name='XMLScriptExample'>
            <Print WaitForJobToComplete='true' JobName='XMLScript Example' 
            Timeout='30000' ReturnPrintData='true' ReturnSummary='true' 
            ReturnLabelData='true' ReturnChecksum='true'>
               <Format>C:\Format1.btw</Format>
            </Print>
         </Command>
      </XMLScript>";

Eric