Why would I need to escape XML for code?
You escape XML when you embed it as a string literal inside source code or a JSON document. Without escaping, the XML's angle brackets, quotes, and ampersands would terminate the string or break the surrounding parser. Common scenarios: hard-coding a SOAP request template in a Java unit test, sending an XML payload as a JSON field to a REST API, or storing a small XML config snippet in a TypeScript constant.
Which characters does the converter escape?
For a JavaScript / JSON string the converter escapes: double quotes (" → \"), backslashes (\ → \\), newlines (\n), carriage returns (\r), tabs (\t), and control characters as \uXXXX. The XML stays valid XML — angle brackets and ampersands remain literal — they only need encoding if you embed the result in HTML, where you would use the HTML entity form (< > &) instead.
Is JSON string escaping the same as HTML / XML entity escaping?
No — they are different. JSON string escaping protects the surrounding JSON syntax (quotes, backslashes, control chars). HTML / XML entity escaping protects markup syntax (< → <, & → &). This tool produces JSON / source-code-safe strings, which is what you almost always want when storing or transporting XML inside another data format. For HTML embedding, use a separate HTML entity encoder.
Does it validate the XML before escaping?
Yes. The converter parses your input with the browser's DOMParser first and rejects malformed XML with an error. This stops you from silently shipping broken XML inside a string literal — a bug that would only surface at runtime when the consumer tried to parse the embedded XML.
Can I reverse a string back to XML?
Yes. Switch to the String → XML mode (if available) or paste the escaped string into any JSON parser to recover the original XML text. The conversion is fully lossless: every byte of the input XML is preserved across the round trip.
How do I embed XML in a Java or C# string?
For Java and C#, the JSON-style escaping this tool emits is mostly compatible — you escape backslashes and double quotes the same way. Java text blocks (Java 15+) and C# verbatim strings (@"...") let you skip most escaping; for those you only need to double internal quotes. For older code, paste the JSON-escaped output as a regular string literal.
Does the tool send my XML anywhere?
No. The DOMParser and JSON.stringify both run inside your browser. XML containing internal API examples, signed envelopes, or proprietary schemas never leaves your machine. Open DevTools → Network and click Convert to verify — there are no requests.
Will newlines be preserved in the output?
Yes — newlines inside the original XML become \n inside the resulting string literal, so the embedded XML retains its original line structure when un-escaped. If you want a single-line output, paste the XML through an XML minifier first or strip newlines before converting.