XML Escape / Unescape · Tutorial
How to put special characters into XML safely
4 min readbeginnerUpdated
A product name contains an ampersand, angle brackets and quotes, and your XML feed breaks whenever it is included. You will escape it for an element and for an attribute, and check the result.
What you need
- The XML Escape tool
Steps
Paste the value
Load the example: “Fish & Chips <special offer> for "only" €9.50 — it's back!”.
Escape for an element
With Escape for XML selected,
&and<and>are replaced. The result can go between tags.<name>Fish & Chips <special offer> for "only" €9.50 — it's back!</name>Escape for an attribute
Keep Escape quotes ticked when the value goes into an attribute such as
title="…", so the quotes inside can’t end the value early.Check it
Paste the finished element into the XML Viewer, Formatter & Validator. It should pass.
Try it yourself
Opens the XML Escape / Unescape with this tutorial's sample loaded.
Common mistakes
- Escaping twice
- Escaping already escaped text turns
&into&amp;. Unescape first if you are not sure. - Escaping a whole document
- Escape only the values you insert. Escaping the tags themselves turns the markup into text.
Next steps
Go back to the XML Escape / Unescape, or keep going with one of these: