How to Add a CDATA Tag to an XML String

The "CDATA" tag element in an XML file lets you add non-XML to your Web files. For instance, if you want to add JavaScript to an XML Web file, the parser returns an error, because the JavaScript is not valid XML. To avoid these errors and add special characters or other coding languages, you wrap your extended characters and coding within the "CDATA" tag element.

Instructions

    • 1

      Right-click the XML file you want to edit and select "Open With." Click your preferred XML editor in the list of programs.

    • 2

      Find the string or section of the XML code you want to use in the CDATA element. You can place the CDATA element anywhere in the file.

    • 3

      Add the CDATA tag to the file. For instance, if you want to encode JavaScript within the CDATA tags, the following syntax shows you how to wrap the code within the tag:

      <![CDATA[
      function myfunction () {
      alert('my function');
      }
      ]]>

Related Searches:

References

Comments

Related Ads

Featured