Share to: share facebook share twitter share wa share telegram print page

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:

This article uses bare URLs, which are uninformative and vulnerable to link rot. Please consider converting them to full citations to ensure the article remains verifiable and maintains a consistent citation style. Several templates and tools are available to assist in formatting, such as reFill (documentation) and Citation bot (documentation). (August 2022) (Learn how and when to remove this template message) Federal University of São João del-ReiUniversidade Federal de São João del-ReiUniv…

Serbian taekwondo practitioner Milica MandićMandić in 2016 during press conferencePersonal informationNationalitySerbianBorn (1991-12-06) 6 December 1991 (age 31)Belgrade, SR Serbia, SFR YugoslaviaHeight6 ft 1 in (1.85 m)Weight175 lb (79 kg)SportCountrySerbiaSportTaekwondoEvent(s)MiddleweightClubTK GalebCoached byDragan Jović Medal record Women's taekwondo Representing  Serbia Olympic Games 2012 London +67 kg 2020 Tokyo +67 kg World Championships 2017 Muju 7…

Uang logam dinar Adelchis Monogram Adelchis, dari denaro Wikimedia Commons memiliki media mengenai Adelchis dari Benevento. Adelchis merupakan putra Radelchis I, Pangeran Benevento, dan pewaris saudaranya Radelgar pada tahun 854. Tugas yang diberikan untuk Adelchis adalah menjaga asas kuno dan kemandirian di dalam menghadapi serangan berulang-ulang dari Saracen dari selatan, Kaisar Louis II dari utara, dan Kekaisaran Bizantium Langobardia ke timur. Awalnya, ia tidak berhasil di dalam perang-pera…

Artikel ini bukan mengenai Khirbet et-Tannur, situs kuil Nabatea di Yordania. Khirbat al-Tannur خربة التنورKhirbat al-TannurKoordinat: 31°42′50″N 35°02′50″E / 31.71389°N 35.04722°E / 31.71389; 35.04722Koordinat: 31°42′50″N 35°02′50″E / 31.71389°N 35.04722°E / 31.71389; 35.04722Grid Palestina154/124Entitas geopolitikMandat PalestinaSubdistrikYerusalemTanggal pengosongan21 Oktober 1948Populasi (Abad ke-19)&…

Zambian Air Force AF-319 طائرة DHC-5D نفس طراز الطائرة المنكوبة ملخص الحادث التاريخ 27 أبريل 1993 الموقع المحيط الأطلسي الغابون إحداثيات 0°37′05″N 9°18′46″E / 0.618135°N 9.312716°E / 0.618135; 9.312716 الركاب 25 الطاقم 5 الوفيات 30 الناجون 0   المالك القوات الجوية الزامبية  بداية الرحلة لوساكا 

Jembatan Trent, dengan Nottingham di latar belakang Sungai Trent adalah sungai terpanjang ketiga di Britania Raya. Muaranya berada di Staffordshire di tepi selatan Biddulph Moor. Sungai tersebut mengalir dan mengairi sebagian besar wilayah tengah dan utara metropolitan Midlands dari selatan dan timur muaranya di utara Stoke-on-Trent. Sungai tersebut dikenal karena banjir dramatis setelah angin ribut dan pencairan salju pada musim semi, yang pada masa lalu sering menyebabkan perubahan arah dari s…

The Astonishing Hypothesis: The Scientific Search for the Soul Cover of the original editionAuthorFrancis CrickPublication dateOctober 1994ISBN9780684801582 The Astonishing Hypothesis is a 1994 book by scientist Francis Crick about consciousness. Crick, one of the co-discoverers of the molecular structure of DNA, later became a theorist for neurobiology and the study of the brain. The Astonishing Hypothesis is mostly concerned with establishing a basis for scientific study of consciousness; howe…

Wim Hogenkamp Wim Hogenkamp in 1975 Algemene informatie Geboren 14 juni 1947 Geboorteplaats Groningen Overleden 5 februari 1989 Overlijdensplaats Amsterdam Land  Nederland Werk Beroep acteur, zanger, tekstschrijver (en) IMDb-profiel Portaal    Film Wim Hogenkamp (Groningen, 14 juni 1947 – Amsterdam, 5 februari 1989) was een Nederlands acteur, tekstschrijver en zanger.[1] Carrière Drs. P reikt de Louis Davidsprijs uit aan Wim Hogenkamp Hij was zoon van Jan George Hogenka…

März 2008: Während des Forums Wolken im gestörten Klimasystem leitet der Atmosphärenphysiker Jost Heintzenberg eine öffentliche Podiumsdiskussion beim hr Das Ernst-Strüngmann-Forum ist ein unabhängiger Think Tank, der auf Grundlage der wissenschaftlichen Unabhängigkeit und der neugierigen Natur des menschlichen Geistes die Erweiterung des Wissens in den Grundlagenwissenschaften fördert. Es wird von Andreas und Thomas Strüngmann finanziert und ist zu Ehren ihres Vaters, Ernst Strüngman…

Jordan Mounds(16 MO 1)Squier and Davis Plate XXXVIII Figure 4Location within Louisiana todayLocationOak Ridge, Louisiana, Morehouse Parish, Louisiana,  USARegionMorehouse Parish, LouisianaCoordinates32°38′38.65″N 91°45′34.92″W / 32.6440694°N 91.7597000°W / 32.6440694; -91.7597000Site notesArchaeologistsTristam R. KidderResponsible body: private Jordan Mounds (16 MO 1) is a multimound archaeological site in Morehouse Parish, Louisiana.[1]…

Zentralschule Weißenburg Schulform Grundschule Gründung 1908 Adresse Schulhausstraße 6 Ort Weißenburg in Bayern Land Bayern Staat Deutschland Koordinaten 49° 2′ 1″ N, 10° 58′ 12″ O49.03355310.969983Koordinaten: 49° 2′ 1″ N, 10° 58′ 12″ O Träger Stadt Weißenburg in Bayern Schüler 455 (Stand: 2019/2020)[1] Lehrkräfte 30 hauptamtliche (Stand: 2019/2020)[1] Leitung Margit Nothhaft-Buchner[2 …

Lake Mary Plaats in de Verenigde Staten Vlag van Verenigde Staten Locatie van Lake Mary in Florida Locatie van Florida in de VS Situering County Seminole County Type plaats City Staat Florida Coördinaten 28° 45′ NB, 81° 20′ WL Algemeen Oppervlakte 22,3 km² - land 19,5 km² - water 2,8 km² Inwoners (2006) 14.718 Hoogte 189 m Overig FIPS-code 38425 Portaal    Verenigde Staten Lake Mary is een plaats (city) in de Amerikaanse staat Florida, en valt bestuurlijk gezien onder…

Movimiento Electoral di Pueblo Plaats uw zelfgemaakte foto hier Personen Partijvoorzitter Ricky Hoek Partijleider Evelyn Wever-Croes Fractieleider Rocco Tjon Oprichter(s) Betico Croes Watty Vos Delwyn Gomez Zetels Statenzetels 9 / 21(25 juni 2021) Geschiedenis Opgericht 9 februari 1971 Algemene gegevens Actief in  Aruba Ideologie Sociaaldemocratisch Kleuren ​ Geel Internationale organisatie COPPPAL Website www.mep.aw Vlag Portaal    Politiek Cariben De Movimiento Electoral d…

Presiden Dwight Eisenhower memperingatkan A.S. tentang keberadaan kompleks militer–industri dalam pidato perpisahannya. Kompleks militer–industri (bahasa Inggris: Military–industrial complex; MIC), atau kompleks militer–industri–kongres,[1] terdiri dari hubungan kebijakan dan moneter yang terbentuk antara pembuat kebijakan, angkatan bersenjata nasional, dan industri senjata yang menopang keberadaan mereka. Hubungan ini meliputi sumbangan politik, persetujuan belanja militer…

Гетайри Відомий під іменем ἑταῖροι Країна  Стародавня Македонія Македонський кавалерист у беотійському шоломі з Сідонського саркофагу (IV ст. до н. е.) Гетайри (дав.-гр. ἑταῖροι) — дружина македонського царя з важких вершників часів Александра Великого. Зміст 1 І…

Спортивна ходьба на 20 кілометрів (чоловіки)на Чемпіонаті світу з легкої атлетики 2022Місце ЮджинУчасників 45 з 24 країнРозкладФінал 15 липняПризери01 ! Яманісі Тосікадзу02 ! Ікеда Кокі3 ! Персеус Карлстрем← 2019 2023 → Чемпіонат світу з легкої атлетики 2022 Бігові види 100 м &…

خوان كارلوس بلاتا   معلومات شخصية الميلاد 1 يناير 1971 (العمر 52 سنة)مدينة غواتيمالا الطول 1.70 م (5 قدم 7 بوصة) مركز اللعب مهاجم الجنسية غواتيمالا  المسيرة الاحترافية1 سنوات فريق م. (هـ.) 1990–2010 ميونيسيبال 553 (302) المنتخب الوطني 2 1996–2010 غواتيمالا[1] 87 (35) الفرق التي دربها…

Election in Virginia Main article: 1984 United States presidential election 1984 United States presidential election in Virginia ← 1980 November 6, 1984 1988 →   Nominee Ronald Reagan Walter Mondale Party Republican Democratic Home state California Minnesota Running mate George H. W. Bush Geraldine Ferraro Electoral vote 12 0 Popular vote 1,337,078 796,250 Percentage 62.29% 37.09% County and Independent City Results Reagan   40–50%  …

For the folk deity, see Madurai Veeran. 2018 Indian filmMadura VeeranTheatrical release posterDirected byP. G. MuthiahWritten byP. G. MuthiahProduced byViji SubramanianStarringShanmuga PandianMeenakshiCinematographyP. G. MuthiahEdited byPraveen K. L.Music bySanthosh DhayanidhiProductioncompaniesV StudiosPG Media WorksRelease date 2 February 2018 (2018-02-02) CountryIndiaLanguageTamil Madura Veeran (transl. Warrior from Madurai) is a 2018 Indian Tamil-language action drama fi…

Metro station in Nagoya, Japan This article relies largely or entirely on a single source. Relevant discussion may be found on the talk page. Please help improve this article by introducing citations to additional sources.Find sources: Sengen-chō Station – news · newspapers · books · scholar · JSTOR (January 2016) T05Sengen-chō Station浅間町駅 Nagoya Municipal Subway stationSengen-chō Station, 1st entranceGeneral informationLocationSengen 1-206, Ni…

Kembali kehalaman sebelumnya

Lokasi Pengunjung: 3.14.254.32