jsonecho

XML to String

Turn a block of XML into one escaped line that fits inside a string literal.

Loading the tool...

How to use XML to String

  1. Paste your XML.
  2. Choose whether the result should include surrounding quotes.
  3. Copy the string.

About XML to String

SOAP messages in unit tests, XML fixtures in config files, payloads inside JSON: all of them need XML as a string. That means removing the line breaks and escaping every double quote, which is dull work.

This converter checks that your XML is well formed, removes the whitespace between tags, and escapes quotes and backslashes. Paste the result between your own quotes, or keep the quotes the tool adds.

Frequently asked questions

Is my XML changed?

The whitespace between elements is removed and quotes are escaped. The elements, attributes and text stay as they are.

Which languages can use the result?

Anything with C-style string escapes: Java, C#, JavaScript, TypeScript, Kotlin, Go (in interpreted strings), PHP in double quotes, and JSON itself.

How do I get the XML back?

Paste the string into the JavaScript Unescape tool, then format the result with the XML Formatter.

More in Converters

All tools →