Format Code Now
/
ConvertXML to Text Next: XML to YAML ›

XML to Text Converter

CV-113

Paste XML and press Extract text to list the text content, or XML to string to get the document as a single quoted string for code.

Runs in your browser. Nothing is uploaded.

XML

Text or string

How to use it

  1. Paste your XML.
  2. For Extract text, pick Text only or Path: text, and tick attributes if you want them.
  3. For XML to string, leave the indentation option on to shrink the string.
  4. Press a button, then copy the result.

Extracting the text

Extract text lists the text inside each element on its own line, in document order, with whitespace collapsed. Tags, comments and the XML declaration are dropped, and entities such as & are decoded. Text directly inside an element is listed before the text of its child elements, so in mixed content, such as a bold tag inside a sentence, the order can differ from reading order. Path: text writes lines like catalog/book/title: Dune, and the attribute option adds attribute values.

XML as a string

XML to string first checks that the XML is well-formed, then writes it as one double-quoted string with backslash escapes, ready to paste into source code. With the option on, line breaks and indentation that sit only between tags are removed, and text inside CDATA is left alone. The XML is not otherwise changed. Malformed XML gives an error with its line and column.

Error messages and what to do

MessageWhat it meansFix
The XML has no text contentExtract text found no text or attributes to list.Tick the attribute option, or check that the elements hold text.

Questions people ask

How do I get only the text out of an XML file?

Paste the XML and press Extract text with Text only selected. Every element with text content gets a line. Tags, attributes and comments are left out unless you ask for attributes.

How do I turn XML into a string?

Press XML to string. The result is the XML as one double-quoted string with escapes, which you can paste into JavaScript, JSON or similar code. Quotes and line breaks are escaped for you.

Does the text keep its original order?

Mostly. Within one element, the element's own text comes before its children's text. For mixed content such as a sentence with inline tags, the order can differ from the original.

Is the XML validated?

It must be well-formed: matching tags, one root, valid names and escapes. It is not checked against a schema. Errors name the line and column.

Why did the string lose its indentation?

The option Remove indentation between tags is on by default. It removes line breaks and spaces that sit only between tags, outside CDATA. Untick it to keep the XML exactly as typed.

About this tool

Extract text lists the text inside each element on its own line, in document order, with whitespace collapsed; tags, comments and the XML declaration are dropped and entities such as &amp; are decoded. Text directly inside an element is listed before the text of its child elements, so in mixed content such as a <b> inside a sentence the order can differ from reading order. Path: text writes lines such as catalog/book/title: Dune, and the attribute option adds attribute values. XML to string checks that the XML is well-formed, then writes it as one double-quoted string with backslash escapes, ready to paste into code; with the option on, line breaks and indentation that sit only between tags are removed (text inside CDATA is left alone). The XML itself is not otherwise changed.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.