CDATA

The term CDATA, meaning character data, is used for distinct, but related, purposes in the markup languages SGML and XML. The term indicates that a certain portion of the document is general character data, rather than non-character data or character data with a more specific, limited structure.

CDATA sections in XML

In an XML document or external entity, a CDATA section is a piece of element content that is marked up to be interpreted literally, as textual data, not as marked-up content.[1] A CDATA section is merely an alternative syntax for expressing character data; there is no semantic difference between character data in a CDATA section and character data in standard syntax where, for example, "<" and "&" are represented by "&lt;" and "&amp;", respectively.

Syntax and interpretation

A CDATA section starts with the following sequence:

<![CDATA[

and ends with the next occurrence of the sequence:

]]>

All characters enclosed between these two sequences are interpreted as characters, not markup or entity references. Every character is taken literally, the only exception being the ]]> sequence of characters. In:

<sender>John Smith</sender>

the start and end "sender" tags are interpreted as markup. However, the code:

<![CDATA[<sender>John Smith</sender>]]>

is equivalent to:

&lt;sender&gt;John Smith&lt;/sender&gt;

Thus, the "tags" will have exactly the same status as the "John Smith"; they will be treated as text.

Similarly, if the numeric character reference &#240; appears in element content, it will be interpreted as the single Unicode character 00F0 (small letter eth). But if the same appears in a CDATA section, it will be parsed as six characters: ampersand, hash mark, digit 2, digit 4, digit 0, semicolon.

Uses of CDATA sections

New authors of XML documents often misunderstand the purpose of a CDATA section, mistakenly believing that its purpose is to "protect" data from being treated as ordinary character data during processing. Some APIs for working with XML documents do offer options for independent access to CDATA sections, but such options exist above and beyond the normal requirements of XML processing systems, and still do not change the implicit meaning of the data. Character data is character data, regardless of whether it is expressed via a CDATA section or ordinary markup. CDATA sections are useful for writing XML code as text data within an XML document. For example, if one wishes to typeset a book with XSL explaining the use of an XML application, the XML markup to appear in the book itself will be written in the source file in a CDATA section.

Nesting

A CDATA section cannot contain the string "]]>" and therefore it is not possible for a CDATA section to contain nested CDATA sections. The preferred approach to using CDATA sections for encoding text that contains the triad "]]>" is to use multiple CDATA sections by splitting each occurrence of the triad just before the ">". For example, to encode "]]>" one would write:

<![CDATA[]]]]><![CDATA[>]]>

This means that to encode "]]>" in the middle of a CDATA section, replace all occurrences of "]]>" with the following:

]]]]><![CDATA[>

This effectively stops and restarts the CDATA section.

Issues with encoding

In text data, any Unicode character not available in the encoding declared in the <?xml ...?> header can be represented using a &#nnn; numerical character reference. But the text within a CDATA section is strictly limited to the characters available in the encoding.

Because of this, using a CDATA section programmatically to quote data that could potentially contain '&' or '<' characters can cause problems when the data happens to contain characters that cannot be represented in the encoding. Depending on the implementation of the encoder, these characters can get lost, can get converted to the characters of the &#nnn; character reference, or can cause the encoding to fail. But they will not be maintained.

Another issue is that an XML document can be transcoded from one encoding to another during transport. When the XML document is converted to a more limited character set, such as ASCII, characters that can no longer be represented are converted to &#nnn; character references for a lossless conversion. But within a CDATA section, these characters can not be represented at all, and have to be removed or converted to some equivalent, altering the content of the CDATA section.

Use of CDATA in program output

CDATA sections in XHTML documents are liable to be parsed differently by web browsers if they render the document as HTML, since HTML parsers do not recognise the CDATA start and end markers, nor do they recognise HTML entity references such as &lt; within <script> tags. This can cause rendering problems in web browsers and can lead to cross-site scripting vulnerabilities if used to display data from untrusted sources, since the two kinds of parser will disagree on where the CDATA section ends.

Since it is useful to be able to use less-than signs (<) and ampersands (&) in web page scripts, and to a lesser extent styles, without having to remember to escape them, it is common to use CDATA markers around the text of inline <script> and <style> elements in XHTML documents. But so that the document can also be parsed by HTML parsers, which do not recognise the CDATA markers, the CDATA markers are usually commented-out, as in this JavaScript example:

<script type="text/javascript">
//<![CDATA[
document.write("<");
//]]>
</script>

or this CSS example:

<style type="text/css">
/*<![CDATA[*/
body { background-image: url("marble.png?width=300&height=300") }     
/*]]>*/
</style>

This technique is only necessary when using inline scripts and stylesheets, and is language-specific. CSS stylesheets, for example, only support the second style of commenting-out (/* … */), but CSS also has less need for the < and & characters than JavaScript and so less need for explicit CDATA markers.

CDATA in DTDs

CDATA-type attribute value

In Document Type Definition (DTD) files for SGML and XML, an attribute value may be designated as being of type CDATA: arbitrary character data. Within a CDATA-type attribute, character and entity reference markup is allowed and will be processed when the document is read.

For example, if an XML DTD contains

<!ATTLIST foo a CDATA #IMPLIED>

it means that elements named foo may optionally have an attribute named "a" which is of type CDATA. In an XML document that is valid according to this DTD, an element like this might appear:

<foo a="1 &amp; 2 are &lt; &#51; &#x0A;" />

and an XML parser would interpret the "a" attribute's value as being the character data "1 & 2 are < 3".

CDATA-type entity

An SGML or XML DTD may also include entity declarations in which the token CDATA is used to indicate that entity consists of character data. The character data may appear within the declaration itself or may be available externally, referenced by a URI. In either case, character reference and parameter entity reference markup is allowed in the entity, and will be processed as such when it is read.

<DISPLAY_NAME Attribute="Y"><![CDATA[PFTEST0__COUNTER_6__:4:199:, PFTEST0__COUNTER_7__:4:199:]]></DISPLAY_NAME>

<SVLOBJECT><LONG name="" val="" INTEGER name="" val="" LONG name="" val=""/></SVLOBJECT>

See also

References

Read other articles:

Contoh pemborosan massal di Palo Duro Canyon (2002) Pemborosan massal (Inggris: mass wastingcode: en is deprecated ), adalah sistem pengangkutan massa puing-puing batuan menuruni lereng akibat pengaruh langsung tenaga gravitasi. Ketika gaya gravitasi yang bekerja pada lereng melebihi kekuatannya melawan, pemborosan massal terjadi. Kekuatan material lereng dan kohesi jumlah gesekan internal antara bantuan bahan menjaga stabilitas lereng dan dikenal secara kolektif sebagai kekuatan geser lereng...

 

Type of reflecting telescope Newton telescope redirects here. For the observatory at the Canary Islands, see Isaac Newton Telescope. Woman looking through a Newtonian telescope The Newtonian telescope, also called the Newtonian reflector or just a Newtonian, is a type of reflecting telescope invented by the English scientist Sir Isaac Newton, using a concave primary mirror and a flat diagonal secondary mirror. Newton's first reflecting telescope was completed in 1668 and is the earliest known...

 

Wakil Bupati BireuenPetahanaLowongsejak 19 Januari 2020Masa jabatan5 tahunDibentuk2002Pejabat pertamaDrs. Amiruddin Idris, S.E., M.Si.Situs webwww.bireuenkab.go.id Berikut ini adalah daftar Wakil Bupati Bireuen dari masa ke masa. No Portret Wakil Bupati Mulai Jabatan Akhir Jabatan Prd. Ket. Bupati 1 Drs.Amiruddin IdrisS.E., M.Si. 25 Juli 2002 25 Juli 2007 1   Drs. H.Mustafa A. Glanggang 2 Drs. H.Busmadar Ismail 25 Juli 2007 25 Juli 2012 2   Drs. H.Nurdin AbdurrahmanM.Si. Jabata...

Echinometra viridis Klasifikasi ilmiah Domain: Eukaryota Kerajaan: Animalia Filum: Echinodermata Kelas: Echinoidea Ordo: Camarodonta Famili: Echinometridae Genus: Echinometra Spesies: Echinometra viridisA. Agassiz, 1863 [1] Sinonim[1] Echinometra plana (A. Agassiz, 1863) Ellipsechinus viridis (A. Agassiz, 1863) Echinometra viridis, landak karang, adalah spesies bulu babi dalam keluarga Echinometridae. Ini ditemukan di terumbu karang di bagian yang sangat dangkal di Samudra At...

 

Spring Basin WildernessIUCN category Ib (wilderness area)The Spring Basin WildernessLocationWheeler County, Oregon, United StatesNearest cityFossil, ORCoordinates44°54′N 120°24′W / 44.9°N 120.4°W / 44.9; -120.4Area6,382 acres (2,583 ha)EstablishedUnited States Bureau of Land Management Spring Basin Wilderness is a 6,382-acre (2,583 ha) wilderness area located near the town of Clarno in the U.S. state of Oregon. It was created by the Omnibus Publi...

 

Kolkata Municipal Corporation in West Bengal, IndiaWard No. 115Kolkata Municipal CorporationInteractive Map Outlining Ward No. 115Ward No. 115Location in KolkataCoordinates: 22°28′55″N 88°20′31″E / 22.481833°N 88.341806°E / 22.481833; 88.341806Country IndiaStateWest BengalCityKolkataArea CoveredPaschim Putiary-Karunamoyee-Haridevpur(partly),ReservationOpenParliamentary constituencyKolkata DakshinAssembly constituencyBehala PurbaBorough13Population...

This article does not cite any sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: State budget of Norway – news · newspapers · books · scholar · JSTOR (February 2018) (Learn how and when to remove this message) The yellow book, the publication of the state budget. The State budget of Norway (Norwegian: Statsbudsjettet) is a government budget passed by the Nor...

 

Reflectivity (left) and relative velocity (right) radar loops of a thunderstorm that spawned an EF2 tornado in Longview, Texas, on December 23 Between November and December 2009, 51 tornadoes touched down across eight states.[note 1] Collectively, the tornadoes injured nine people and wrought $20.36 million,[note 2] much of which resulted from an EF3—the strongest tornado during the two-month period—that struck Lufkin, Texas, on December 23.[1...

 

Political organization in Bessarabia that proclaimed the Moldavian Democratic Republic For other uses, see Sfatul Țării (disambiguation). This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article's tone or style may not reflect the encyclopedic tone used on Wikipedia. See Wikipedia's guide to writing better articles for suggestions. (December 2009) (Learn how and when to remove this ...

French pirate and privateer This article is about the privateer. For the town named after him, see Jean Lafitte, Louisiana. Not to be confused with Jean Laffitte. Jean LafittePresumed portrait of Jean LafitteBornSeptember 25, 1780France or Saint-DomingueDiedc. February 5, 1823 (aged 42) or c. 1875 (aged 95)(presumed) Gulf of Honduras or Lincolnton, North CarolinaPiratical careerNicknameThe Terror of the GulfTypePirate, privateer, spy, naval artillery officer, slave traderYears active1810-1823...

 

Эта статья описывает находящуюся в разработке компьютерную игру.После выпуска игры сведения, приведённые здесь, могут оказаться неверными, и содержание статьи может значительно измениться. Star Wars Eclipse Разработчик Quantic Dream Издатель Lucasfilm Games Часть серии игра по вселенно�...

 

Equipment designed to protect from fallingThis article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Safety harness – news · newspapers · books · scholar · JSTOR (Jan...

UK Covid commemoration, 23 March Logo used in 2022 The Day of Reflection in the United Kingdom is a day to remember those who died during the COVID-19 pandemic. It was initiated, as the National Day of Reflection, in 2021 by the Marie Curie charity, and was held on 23 March, the anniversary of the first COVID-19 lockdown in the United Kingdom.[1] In 2024 the word National was removed and the date of the fourth day was changed to Sunday 3 March 2024.[2] The event is supported b...

 

Menara Jam AtkinsonMenara jamLua error in Modul:Location_map at line 537: Tidak dapat menemukan definisi peta lokasi yang ditentukan. Baik "Modul:Location map/data/Borneo Malaysia" maupun "Templat:Location map Borneo Malaysia" tidak ada.Koordinat5°58′55.87″N 116°4′38.40″E / 5.9821861°N 116.0773333°E / 5.9821861; 116.0773333LokasiKota Kinabalu, Sabah, MalaysiaTipeMenara jamMaterialKayuPanjang16 kaki 3 inciLebar16 kaki 3 inciTinggi50 kaki ...

 

雅亚Jayat 法國市镇雅亚的位置 雅亚显示法国的地图雅亚显示安省的地图坐标:46°22′14″N 5°07′15″E / 46.3706°N 5.1208°E / 46.3706; 5.1208国家 法國大区 奥弗涅-罗讷-阿尔卑斯大区省 安省面积1 • 市镇16.3 平方公里(6.3 平方英里)人口(1999)[1] • 市镇773人 • 密度47.4人/平方公里(123人/平方英里)时区CET(UTC+0...

Radivoj KoraćРадивој КораћKorać con la maglia del Petrarca PadovaNazionalità Jugoslavia Altezza196 cm Peso94 kg Pallacanestro RuoloAla grande Hall of fameNaismith Hall of Fame (2022)FIBA Hall of Fame (2007) CarrieraSquadre di club 1955-1958 BSK Belgrado1958-1967 OKK Belgrado1967-1968 Liegi1968-1969 Petrarca Nazionale 1959-1968 Jugoslavia157 (3.153) Palmarès  Olimpiadi ArgentoCittà del Messico 1968  Mondiali ArgentoBrasile 1963 Arge...

 

Annual celebration International Day of Non-ViolenceInternational Non-Violence Day is observed on the birthday of Mahatma GandhiObserved byAll UN Member StatesDate2 OctoberFrequencyannual International Day of Non-Violence is observed on 2 October, the birthday of Mahatma Gandhi. It was established on 15 June 2007 according to United Nations General Assembly resolution A/RES/61/271. The day is an occasion to disseminate the message of non-violence...through education and public awareness....

 

Hong Kong 1941Sampul DVDNama lainTradisional等待黎明Sederhana等待黎明MandarinDěng Dài Lí MíngKantonDang2 Doi6 Lai4 Ming4 SutradaraPo-Chih LeongProduserJohn ShumDitulis olehJohn ChanSammo Hung[1]PemeranChow Yun-fatCecilia YipAlex ManPenata musikViolet LamSinematograferBrian LaiPenyuntingPeter CheungPerusahaanproduksiD&B FilmsBo Ho FilmsTanggal rilis1 November 1984 (1984-11-01)Durasi100 menitNegaraHong KongBahasaKantonPendapatankotorHK$7.22 juta.[1&#...

Japanese voice actress and singer (born 1990) Haruka Tomatsu戸松 遥Haruka Tomatsu in 2021Born (1990-02-04) February 4, 1990 (age 34)[1]Ichinomiya, Aichi, Japan[1]Occupations Actress voice actress singer Years active2000–presentEmployerMusic Ray'n[2][3]Height165 cm (5 ft 5 in)[1]Children1Musical careerGenres J-Pop Anison Instrument(s)VocalsYears active2008–presentLabelsSony Music Entertainment Japan / Music Ray'n (Japan)Me...

 

Sri Lankan English language newspaper The Sunday TimesTypeWeekly newspaperFormatBroadsheetOwner(s)Wijeya NewspapersFounded1991; 33 years ago (1991)Political alignmentCentristLanguageEnglishHeadquartersNo. 48, Park Street, Colombo 2, Sri LankaCirculation330,000[1]Websitesundaytimes.lk The Sunday Times is a weekly Sri Lankan broadsheet initially published by the now defunct Times Group, until 1991, when it was taken over by Wijeya Newspapers. The paper features article...