
Smaller quantities of such text can be properly encoded to escape the XML characters, but for larger text, it helps to preserve the meaning of the text without having to do so. Characters you may escape in attributes values (depending on the syntax you use for attributes : attrvalue or attr'value. For information, the 2 characters you must escape in XML are : & in & < in <. Maybe you have encoding problems in your source file. Where is it used?ĬDATA sections are used when larger amounts of verbatim text need to appear within XML documents and processed verbatim. As you provide it, the XML is well formed. This declaration states that an img element must have a src attribute whose value type is CDATA. Within a Document-Type Definition (DTD), an attribute value may be declared to be of type CDATA as follows: Instead the above can be written in two sections as follows: " here.]]> Attribute Value NestingĪ CDATA section may not be nested inside another because “ ]]>” may not appear directly except to end the CDATA section. Within the following CDATA section, the entity reference “%AnEntity” is recognized and the value is replaced within character data passed to the XML processor. If a parser were to offer to ignore this, and pretend all. A CDATA section containing the character & is the same as a normal text node containing &. For example, assume the following parameter entity is defined: The purpose of CDATA sections in XML is to encapsulate a block of text 'as is' which would otherwise require special characters (in particular, >, < and &) to be escaped. In addition, parameter entity references are recognized within CDATA sections. When processing this XML, the parser receives the text “ Hello, world!” as character data and not as markup. The angle brackets surrounding “ greeting” and “ /greeting” need not be escaped. For example, angle brackets () and ampersands (&) which indicate XML markup need not be escaped within a CDATA section.įor example, the following is a CDATA section. Any character data (other than “ ]]>“) can appear within the section without needing to be escaped.

MarkupĪ CDATA section is marked up starting with “ “.


If you want to have XML displayed within HTML, you need to first create properly encoded XML (which involves changing & to &) and then use that to create properly encoded HTML (which involves again changing & to & ). It can appear anywhere character data can occur. & is the way to represent an ampersand in most sections of an XML document. A CDATA section in XML is used to escape text containing characters which would otherwise be recognized as markup.
