XML URL encoding
Paste XML and get a URL-safe, percent-encoded version you can put in a link, a query parameter or a form field. Choose %20 or + for spaces. Switch to Decode to turn it back into XML.
< → %3C · > → %3E · / → %2F · " → %22 · space → %20
%3Cnote%20priority%3D%22high%22%3E%0A%20%20%3Cto%3ETeam%3C%2Fto%3E%0A%20%20%3Cbody%3EReview%20the%20XML%20payload%3C%2Fbody%3E%0A%3C%2Fnote%3E
Encoded · 84 characters → 142 characters
Everything runs in your browser; nothing is uploaded.
How XML URL encoding works
URLs can only carry letters, digits and a few symbols safely. URL encoding, also called percent-encoding, replaces every other character with a % followed by two hexadecimal digits. XML is full of characters that need this treatment: the angle brackets of every tag, the slash in every end tag, the quotes and equals signs in attributes, and the spaces.
- Letters, digits and a few safe symbols such as
- _ . ~stay as they are, so tag names and text remain readable. - Every other character is turned into its UTF-8 bytes.
- Each byte is written as
%plus two hex digits:<is byte 3C, so it becomes%3C.
The result is one long string with no spaces or special characters, which a server decodes back into the original XML.
Common character mappings
| Character | Encoded | Where it appears in XML |
|---|---|---|
| < | %3C | Start of every tag |
| > | %3E | End of every tag |
| / | %2F | End tags and self-closing tags |
| " | %22 | Attribute values |
| = | %3D | Attributes |
| ? | %3F | The <?xml ?> declaration |
| : | %3A | Namespace prefixes such as soap: |
| & | %26 | Entities such as & |
| space | %20 or + | Between attributes and in text |
| line break | %0A | Between lines of indented XML |
| é | %C3%A9 | Accented text (two UTF-8 bytes) |
Worked example: XML in a query string
An API takes an XML message in a parameter called xml. The message is:
Step 1: Encode the special characters
Step 2: The encoded value
Step 3: Add it to the URL as the parameter value
Encode only the value, not the whole URL. The ? and = around it must stay as they are, or the server cannot find the parameter. The & inside the XML has to be encoded as %26, otherwise the server would read it as the start of a second parameter.
URL encoding vs XML escaping
Both change special characters, but for different reasons, and they are easy to mix up. XML escaping keeps a document well-formed; URL encoding lets data travel safely inside a URL.
| URL encoding | XML escaping | |
|---|---|---|
| < becomes | %3C | < |
| & becomes | %26 | & |
| Spaces | %20 or + | unchanged |
| Used for | URLs, query strings, form data | Text and attributes inside XML |
To send XML in a URL, URL-encode it and nothing else. You do not need to XML-escape it first; the receiving server decodes the URL encoding and gets your XML back exactly. If you need to escape characters inside the XML itself, use the XML escape tool.
URL-encoding XML in JavaScript, PHP, C#, Java and Python
encodeURIComponent(xmlString) // JavaScript
rawurlencode($xmlString); // PHP
System.Web.HttpUtility.UrlEncode(xmlString); // C# / .NET
URLEncoder.encode(xmlString, "UTF-8"); // Java
urllib.parse.quote(xml_string, safe="") # PythonThey differ in one detail: how they write a space. JavaScript, PHP’s rawurlencode and Python’s quote use %20. C#’s HttpUtility.UrlEncode and Java’s URLEncoder use +, the style HTML forms use. Servers read both correctly in a query string; if the receiving side expects %20, pick it in the tool, or in C# use Uri.EscapeDataString() instead.
In JavaScript, use encodeURIComponent, not encodeURI. The second one is meant for whole URLs and leaves &, =, / and ? alone, which breaks a query string as soon as the XML contains them.
Frequently asked questions
Should I URL-encode the whole URL or just the XML?
Just the XML, as the value of its parameter. Encoding the whole URL would also encode the ? and = that the server needs to find the parameter.
Why is URL-encoded XML so much longer?
Each special character becomes three characters (< is %3C), and accented letters become six or more. Indented XML also has many spaces and line breaks to encode. Turn on Minify first in the tool to drop the indentation.
Is URL encoding the same as Base64?
No. URL encoding replaces only the unsafe characters, so the tag names stay readable. Base64 rewrites the whole document into letters and digits. Use the XML to Base64 converter if a system asks for Base64.
Does URL encoding hide or protect the XML?
No. Anyone can decode it instantly. It only makes the XML safe to carry inside a URL, so never put passwords or private data in a URL this way.
Sources
- RFC 3986, section 2.1: Percent-encoding: how characters are percent-encoded
- MDN: encodeURIComponent(): which characters are encoded
- PHP manual: rawurlencode: percent-encoding with %20 for spaces
- Microsoft Learn: HttpUtility.UrlEncode: URL encoding in .NET
- Java SE: URLEncoder: form-style encoding with + for spaces
Related Tools
Build and preview Valorant crosshair settings.
Search common Vim commands.
Turn JSON rows into bar, line, or pie charts.
Convert WebP files and Base64 data in both directions.
Convert GIF files and Base64 data in both directions.
Save any GIF frame, or all frames, as JPG.