XML CDATA Encoder/Decoder
Wrap text in XML CDATA sections or extract the original text from CDATA
Wrap text in XML CDATA sections online, or extract the original text from existing CDATA blocks. CDATA lets you include HTML, scripts, and special characters such as < and & in XML without escaping them. This free XML CDATA encoder and decoder helps developers working with RSS feeds, SOAP messages, and XML configs.
Output will appear here.
Press Ctrl+Enter or click Encode / Decode.
About XML CDATA Encoder/Decoder
The XML CDATA Encoder/Decoder wraps arbitrary text in a CDATA section so that characters such as
<, > and & can be placed inside an XML element without
escaping each one. In decode mode it removes the CDATA markers and returns the original content.
All processing happens in your browser, so your data is never uploaded or stored.
What Is a CDATA Section?
XML treats a handful of characters as markup. The less-than sign starts a tag, the ampersand starts an entity
reference, and the greater-than sign can close one. When an element must carry text that contains many of
these characters, such as an HTML fragment, a JavaScript function, a SQL statement, or a code sample, escaping
every occurrence with < and & makes the content hard to read and easy to
break. A CDATA section solves this by marking a block of text as literal character data. Everything between
<![CDATA[ and ]]> is passed to the application exactly as written, and the parser
does not try to interpret it as markup.
Why the Closing Sequence Needs Special Handling
A CDATA section ends at the first ]]> the parser finds. If your source text happens to contain that
exact sequence, wrapping it naively produces a broken document: the section closes early and the remaining
text is parsed as markup. The standard workaround is to end the current section in the middle of the sequence
and start a new one, so ]]> becomes ]]]]><![CDATA[>. This tool applies that split
automatically during encoding, and the decoder joins the pieces back together, so a round trip always
returns the original text. Note that CDATA cannot be nested, and it is only valid inside element content,
not inside attribute values, element names, or comments.
Key Features
- Encode — wraps the input in
<![CDATA[ ... ]]>. - Safe splitting — a literal
]]>inside the text is split across two CDATA sections so the result stays well-formed. - Decode — replaces every CDATA section in the input with its raw content and leaves the surrounding XML untouched.
- Swap — move the output back to the input and switch mode for round-trip checks.
How to Use
- Select Encode or Decode mode.
- Paste text, or upload a file.
- Click the convert button or press Ctrl+Enter.
- Copy or download the result.
Encode vs. Entity Escaping
Both CDATA and entity escaping produce valid XML, but they suit different situations. CDATA is best for large blocks of human-edited text where readability matters, because the content stays visible exactly as it was typed. Entity escaping is better for short values, for attribute values, and for pipelines that re-serialize the document, since many XML libraries do not preserve CDATA boundaries and will write the content back as escaped text. The two forms are equivalent to a conforming parser, so the data you read is the same either way. Choose the form that makes your document easier to maintain.
Real-World Scenarios
- Embedding HTML or JavaScript snippets in RSS, Atom, or SOAP payloads.
- Storing SQL queries or scripts in XML configuration files.
- Extracting readable content from CDATA-wrapped feed items.
- Placing code samples or templates in Maven, Ant, Spring, or Android resource files.
- Preparing content for XML-based CMS imports, sitemaps, and product feeds where descriptions contain markup.
- Cleaning up exported data by stripping CDATA wrappers before loading it into another system.
Tips for Reliable Results
- Encode only the text value, not the surrounding tags, so the element structure remains valid.
- Make sure the text is valid for the document encoding. CDATA does not allow characters that XML 1.0 forbids, such as most control characters.
- Use decode mode on a full XML fragment to unwrap only the CDATA sections while keeping the other elements unchanged.
- After editing, run the result through an XML formatter or validator to confirm the document is well-formed.
Frequently Asked Questions
What is a CDATA section?
A CDATA section tells the XML parser to treat its content as literal character data, so markup characters inside it are not interpreted.
Can CDATA contain the text ]]>?
Not directly, because it ends the section. The encoder splits it into ]]]]><![CDATA[>, which decodes back to the original text.
Is my data sent to a server?
No. Encoding and decoding run entirely in your browser, and nothing you paste or upload leaves your device.
Can I use CDATA inside an XML attribute?
No. CDATA sections are only allowed in element content. For attribute values, use entity escaping such as <, &, and ".
What happens if the decoder finds no CDATA section?
The tool shows a warning and returns the input unchanged, so nothing is lost.
Does decoding also convert entities such as &?
No. Decode mode only removes CDATA wrappers. Text outside CDATA keeps its entities as written.