XML Escape / Unescape

Escape and unescape XML special characters (& < > " ') with optional numeric references, slash escaping, and CDATA wrapping

Key Facts

Category
Conversion & Encoding
Input Types
textarea, select, checkbox, text
Output Type
text
Sample Coverage
4
API Ready
Yes

Overview

The XML Escape / Unescape tool allows you to quickly encode or decode special characters in XML data, ensuring well-formed documents. It supports standard entity conversions, quote escaping, OWASP-recommended slash escaping, non-ASCII numeric references, and CDATA wrapping.

When to Use

  • When embedding raw text containing characters like '<', '>', or '&' inside XML tags without breaking the document structure.
  • When decoding escaped XML payloads received from APIs or configuration files back into readable plain text.
  • When wrapping complex code blocks or markup inside CDATA sections to prevent XML parsers from interpreting them.

How It Works

  • Paste your XML or plain text into the input text area.
  • Select the operation (Escape or Unescape) and configure options like quote escaping, slash escaping, or non-ASCII conversion.
  • Optionally enable CDATA wrapping and specify an element tag to enclose the escaped content.
  • The tool instantly processes the input and displays the escaped or unescaped text in the output field.

Use Cases

Preparing code snippets or HTML templates to be safely embedded inside XML configuration files.
Decoding XML-encoded API responses to extract the original text or payload.
Securing user-generated inputs against XML injection by escaping slashes and quotes before processing.

Examples

1. Safely Embedding HTML in XML

Web Developer
Background
A developer needs to store an HTML template inside an XML configuration file for a content management system.
Problem
The HTML contains '<' and '>' characters that break the XML parser.
How to Use
Paste the HTML code into the input, select 'Escape', keep 'Escape Quotes' checked, and run the tool.
Example Config
Operation: Escape, Escape Quotes: True, Escape Slash: False, Numeric Non-ASCII: False, Use CDATA: False
Outcome
The HTML tags are converted to safe entities like '&lt;div&gt;' which can be parsed inside XML without errors.

2. Wrapping Code in CDATA Tags

Integration Engineer
Background
An engineer is configuring a SOAP API request that includes a raw SQL query containing multiple comparison operators.
Problem
Escaping every single character makes the SQL query unreadable in the source files.
How to Use
Input the SQL query, select 'Escape', check 'Wrap in CDATA section', and enter 'query' as the CDATA Element Tag.
Example Config
Operation: Escape, Use CDATA: True, CDATA Element Tag: 'query'
Outcome
The output wraps the SQL query in '<query><![CDATA[...]]></query>', keeping the query readable and XML-compliant.

3. Decoding API Response Payloads

QA Tester
Background
A tester receives an XML response from a legacy system where the data fields are heavily escaped.
Problem
The text contains entities like '&amp;' and '&quot;', making it difficult to verify the actual content.
How to Use
Paste the escaped XML string into the input, select 'Unescape' as the operation, and run the tool.
Example Config
Operation: Unescape
Outcome
The entities are decoded back to standard characters like '&' and '"' for easy reading and validation.

Try with Samples

xml, html, text

Related Hubs

FAQ

What characters are escaped by default?

By default, the tool escapes ampersands (&), less-than (<), greater-than (>), double quotes ("), and single quotes (').

Can I escape forward slashes?

Yes, you can enable the 'Escape Slash' option to convert '/' to '&#47;' for OWASP-compliant security.

What does the CDATA option do?

It wraps your input in a <![CDATA[...]]> section, optionally enclosed in a custom XML tag, to prevent parsers from reading the content as markup.

How does the numeric non-ASCII option work?

It converts non-ASCII characters (like accented letters or symbols) into their hexadecimal numeric character references (&#xNNNN;).

Does this tool validate XML syntax?

No, this tool only escapes or unescapes characters and does not validate the overall syntax of your XML document.

API Documentation

Request Endpoint

POST /en/api/tools/xml-escape

Request Parameters

Parameter Name Type Required Description
inputText textarea Yes -
operation select Yes -
escapeQuotes checkbox No -
escapeSlash checkbox No -
numericNonAscii checkbox No -
useCDATA checkbox No -
cdataElement text No -

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-xml-escape": {
      "name": "xml-escape",
      "description": "Escape and unescape XML special characters (& < > \" ') with optional numeric references, slash escaping, and CDATA wrapping",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=xml-escape",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]