XML URL Encode and Decode
ED-66Paste XML to percent-encode it for use in a URL, or paste a URL-encoded string to get the XML back, formatted if you like.
Runs in your browser. Nothing is uploaded.
XML (or a URL-encoded XML string)
Result
How to use it
- Paste your XML into the input box.
- Optionally remove the whitespace between tags, or write spaces as + for a form-style query string.
- Click Encode XML for URL and copy the result into your URL.
- To read an encoded value, paste it and click Decode URL-encoded XML.
What is encoded
Every character except letters, digits and - _ . ! ~ * ' ( ) is turned into a percent code. Angle brackets, quotes, slashes, equals signs and ampersands are all encoded, so the XML can be carried in a single query parameter. Characters outside ASCII are encoded as UTF-8 bytes, so é becomes %C3%A9. The XML itself is not altered: entities such as & stay as they are.
Whitespace and formatting
By default the document is encoded exactly as typed. Removing whitespace between tags makes the URL shorter, but it needs well-formed XML and also collapses runs of whitespace inside text, which matters in some documents. When decoding, Format the XML after decoding re-indents the result and also requires well-formed XML; leave it off to see the decoded text unchanged.
URL encoding is not XML escaping
These are different layers. URL encoding makes text safe for a URL. XML escaping, with < and &, makes text safe inside an XML document. If your text is going into an XML file, use the XML escape page instead. Long XML in a query string may hit URL length limits, in which case a request body is the better route.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Not valid percent-encoding | A % is not followed by two hex digits, or the bytes are not UTF-8. | Check for a truncated value. |
opened on line | When minifying or formatting, a tag is never closed. | Close the tag named in the message. |
Questions people ask
How do I URL encode XML?
Paste the XML and click Encode XML for URL. All characters that are not safe in a URL become %XX codes, so the whole document can be used as a query parameter value.
How do I decode URL-encoded XML?
Paste the encoded text and click Decode URL-encoded XML. Percent codes become characters again. Turn on Format the XML after decoding to indent it, which needs well-formed XML.
Is URL encoding the same as XML escaping?
No. URL encoding writes %3C for <, and XML escaping writes <. Use URL encoding for a value in a URL and XML escaping for text inside a document.
Why is the encoded XML so long?
Each special character becomes three characters, and XML has many angle brackets, quotes and slashes. Removing the whitespace between tags reduces the size a little, but a long document may still be too long for a URL.
What does the plus option do?
It writes spaces as + instead of %20, and reads + as a space when decoding. That is the form-style convention for query strings. Leave it off unless the receiver expects it.
Does encoding change my XML?
No. Decoding returns the same text. Only the Remove whitespace option changes the document, and it is off by default. Entities and attributes are left as written.
About this tool
The XML is percent-encoded as it is, with every character that is not a letter, digit or one of - _ . ! ~ * ' ( ) turned into %XX, so angle brackets, quotes, slashes and ampersands survive inside a query value. Non-ASCII characters become UTF-8 bytes. By default nothing in the document is changed, including whitespace and entities such as &. Removing whitespace between tags requires well-formed XML and also collapses runs of whitespace inside text, which can matter for some documents. Decoding reverses the percent-encoding; formatting the result after decoding requires well-formed XML. This is URL encoding, not XML escaping.