XML - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

XML CDATA

XML CDATA

shape Description

A CDATA(Unparsed character Data) section is a markup construct whose contents are assumed not to have any markup i.e. the writers advises not to treat CDATA as information and so CDATA sections are not reflected in the set of properties of an XML document because using a CDATA section engages escaping for all of its unescaped content, thus not needing to escape individual characters. In short, CDATA can be defined as the text data that should not be parsed by the XML parser. If the application is being used for some reason is mandating the use of CDATA, then it is likely not a conforming XML processor or conforming to XML syntax conventions. Characters like < or > symbols inside the tag(<>) may cause error if the compiler takes in the used symbol instead of tag.

shape Syntax

A CDATA section begins with <![CDATA[ as the start delimiter and ends with ]]> characters as the end delimiter. [xml] <![CDATA[ characters with markup ]]> [/xml] But, that end delimiter is the only way to end a CDATA section and so the XML processor knows to recognize the ]]> sequence of characters as a formal CDATA section end delimiter at all times. Therefore, it is very important in the text never to allow an end delimiter without a matching start delimiter already having been used. There is a need to escape something in the three characters if these three characters are present in the user data that is wrapped with XML. Using this construct, marking up markup content can be simplified.

shape Example

In the below example, everything given inside the CDATA is taken as character data and not as the markup. [xml] <script> <![CDATA[ function matchwo(a,b) { if (a < b && a < 0) { return 1; } else { return 0; } } ]]> </script> [/xml]

XML PCDATA

shape Description

PCDATA is exactly opposite to CDATA. PCDATA(Parsed Character Data) usually parse all the XML document data which is present even in the elements like below. [xml]<message>This text is also parsed</message>[/xml] When working with the DOM, there will be child elements in the root element. For example, [xml]<contact-info><name>Mike</name><company>SPLessons</company></contact-info>[/xml] The above code is broken up by the parser as shown below. [xml] <contact-info> <name>Mike</name> <company>SPLessons</company> </contact-info> [/xml]

Summary

shape Key Points

  • CDATA is the text data that should not be parsed by the XML parser.
  • CDATA has the syntax enclosed between "<![CDATA[" and "]]>" characters.
  • PCDATA parse all the XML document data.