The Right Format for CDATA inside CDATA

Recently, I would like to include Content Editor webpart into a page through feature. I also would like to initialized my javascript into the CEWP.

Initially, I have my CEWP added to the page manually and edit the webpart source to include my javascript, everything looks good. Export the webpart and include the exported xml into file element in element.xml. I found out there is CDATA tag inside the outer CDATA tag. This makes my outer CDATA tag broken. Its like you need escape characters in a string, if you know what I mean.

I spent a bit of time to look for the solution, probably because I do not search the right keyword in google. Anyway the valid format would be:

From

<![CDATA[ blah blah blah <![CDATA[ bleh bleh bleh ]]> blah blah blah ]]>

To

<![CDATA[ blah blah blah <![CDATA[ bleh bleh bleh ]]]]><![CDATA[> blah blah blah ]]>

My full file element would be:

    <File Url="Account.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
      <Property Name="Title" Value="Account page." />
      <Property Name="UIVersion" Value="4" />
      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
      <Property Name="PublishingPreviewImage" Value="$PublishingPreviewImage$" />
      <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/CustomPageLayout.aspx, My Custom Page Layout "/>
      <Property Name="PublishingAssociatedContentType" Value=";#$Resources:cmscore,contenttype_articlepage_name;;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D;#"/>
      <AllUsersWebPart WebPartZoneID="Top" WebPartOrder="1">
        <![CDATA[              
        <?xml version="1.0" encoding="utf-8"?>
          <WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
            <Title>Content Editor</Title>
            <FrameType>Default</FrameType>
            <Description>Allows authors to enter rich text content.</Description>
            <IsIncluded>true</IsIncluded>
            <ZoneID>Top</ZoneID>
            <PartOrder>1</PartOrder>
            <FrameState>Normal</FrameState>
            <Height />
            <Width />
            <AllowRemove>true</AllowRemove>
            <AllowZoneChange>true</AllowZoneChange>
            <AllowMinimize>true</AllowMinimize>
            <AllowConnect>true</AllowConnect>
            <AllowEdit>true</AllowEdit>
            <AllowHide>true</AllowHide>
            <IsVisible>false</IsVisible>
            <DetailLink />
            <HelpLink />
            <HelpMode>Modeless</HelpMode>
            <Dir>Default</Dir>
            <PartImageSmall />
            <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
            <PartImageLarge>/_layouts/15/images/mscontl.gif</PartImageLarge>
            <IsIncludedFilter />
            <Assembly>Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
            <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
            <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
            <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor"><![CDATA[
            <script>
              function HideAllChildDiv()
              {
               $('#Account1').hide();
               $('#Account2').hide();
               $('#Account3').hide();
              }
              
              HideAllChildDiv();
              $('#Account1').show();
            </script>
          ]]]]><![CDATA[>
          </Content>
          <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
          </WebPart>
          ]]>

      </AllUsersWebPart>
    </File>
Advertisements

Tagged: , , , , ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: