About the XML Stringify
Embedding XML inside code is fiddly. Every double quote in an attribute needs escaping, every newline has to become a \n or the literal has to be a multi line form, and getting it wrong produces a compile error at best and a silently truncated document at worst. This page does the escaping for the language you name, so the result compiles the first time.
The JSON option gives you a quoted, fully escaped value ready to drop into a request body or a fixture file. JavaScript produces either a quoted constant or, when you turn minifying off, a template literal that keeps the original line breaks and escapes backticks and dollar brace sequences so nothing is interpolated by accident. Java builds a concatenation with one quoted line per source line, which stays readable in a test class. C# uses a verbatim string with doubled quotes, Python uses a triple quoted block, and the shell option produces a single quoted variable with embedded quotes handled the awkward way that shells require.
Minifying first is on by default because an embedded document usually only needs to be correct rather than pretty, and collapsing it makes the literal far shorter. The XML is parsed before anything is escaped, so a malformed document is reported rather than quietly turned into a broken string. To reverse the process on a value you found in a log, JSON Unescape and XML Formatter together will get you back to readable markup.
How to use
- Paste the XML you want to embed in code.
- Choose the language in String for so the escaping rules match your compiler.
- Leave Minify the XML first on for a compact single line literal, or turn it off to keep the layout.
- Set a variable name if the target language emits a declaration, then copy the result.
Common questions
- Does it check that my XML is valid first?
- Yes. The document is parsed before escaping, so a mismatched tag is reported with a line number instead of becoming a broken literal.
- Which JavaScript form should I use?
- Keep minifying on for a normal quoted constant. Turn it off if you want a template literal that preserves the indentation.
- How are quotes handled for C#?
- The output is a verbatim string, so every double quote in the XML is doubled and backslashes need no escaping at all.
- Is the XML declaration kept?
- Yes. The processing instruction at the top is part of the document and is escaped along with everything else.