How to use the xml to text converter
- Paste your XML into the input area.
- Check Include attribute values if you want attribute data extracted alongside element text.
- The extracted plain text appears instantly as you type or paste.
- If the XML is malformed, an error message shows the exact line and column of the first problem.
How the xml to text extraction works
The converter uses a hand-written tokenizer rather than the browser's built-in DOM parser. It scans the input character by character, tracking state to distinguish element tags, attributes, text nodes, CDATA sections, comments and processing instructions. When it encounters text or a CDATA block, it appends the decoded characters to the output. Tags, comments and processing instructions like <?xml ... ?> are silently skipped.
For example, given <p>A & B</p>, the tokenizer reads the opening tag, collects the text "A ", resolves the & entity to "&", collects " B", then reads the closing tag. The final output is simply "A & B".
Entity resolution reference
XML defines five built-in character entity references. The tokenizer resolves these automatically wherever they appear in text or attribute values. Numeric character references in decimal (A) and hexadecimal (A) formats are also converted to their corresponding Unicode characters.
| Entity | Character | Description |
|---|---|---|
& | & | Ampersand |
< | < | Less-than sign |
> | > | Greater-than sign |
" | " | Double quotation mark |
' | ' | Apostrophe |
Error reporting with line and column
Because the tokenizer processes the raw string directly, it maintains a running count of newlines and characters to report the exact position of any syntax error. If an element is left unclosed, an attribute lacks quotes, or an invalid character sequence appears, the tool stops and returns a message such as "Unexpected end of input at line 3, column 12". This makes debugging broken XML straightforward without needing a separate validation step.
Limitations: no DOCTYPE or external entities
This xml to text converter intentionally does not process DOCTYPE declarations or resolve external entities. Supporting external DTDs would require network requests, which contradicts the goal of keeping all processing local in the browser. If your XML contains a <!DOCTYPE ...> declaration, the tokenizer will flag it as an error. Custom entities defined in an internal DTD subset are also unsupported; only the five standard XML entities and numeric references are resolved. For documents relying heavily on custom entities, expand them before pasting.
Practical use cases
Extracting plain text from XML is useful when migrating content out of structured formats. Configuration files, RSS feeds, SVG graphics and API responses often contain human-readable text buried inside markup. Stripping the tags leaves just the content for indexing, searching or pasting into other tools. If you need to convert XML into tabular data instead, consider xml to csv. To restructure XML into another markup format, tools like xml to html or xml to yaml may be more appropriate. You can also xml minify your source first to remove unnecessary whitespace before extraction.
Handling whitespace and formatting
The tokenizer preserves whitespace exactly as it appears in text nodes. Indentation spaces, tabs and newlines between elements are treated as text content and included in the output. If your XML is pretty-printed with significant indentation, the resulting text will contain those extra spaces and line breaks. To get cleaner output, you can xml minify the document first to collapse unnecessary whitespace, or run the result through a separate text cleanup step. CDATA sections preserve all internal whitespace literally, since no parsing occurs within them. No separator is added between adjacent elements, so <b>1</b><b>2</b> becomes 12; put whitespace between them in the source if you need a break.
Worked examples
| Example | Input | Result |
|---|---|---|
| Simple document | XML input: <note><to>User</to><from>Admin</from><body>Hello & welcome!</body></note>; Include attribute values: no | UserAdminHello & welcome! |
| CDATA and comments | XML input: <data><!-- secret --><![CDATA[Raw <text> & stuff]]></data>; Include attribute values: no | Raw <text> & stuff |
| Attributes included | XML input: <link href="https://example.com" title="Example">Click here</link>; Include attribute values: yes | Click here https://example.com Example |
FAQ
Does this tool upload my XML to a server?
No. The xml to text conversion happens entirely in your browser using JavaScript. Your data never leaves your device.
What happens to XML comments and processing instructions?
Comments and processing instructions like are recognized by the tokenizer and excluded from the text output. Only actual character data and CDATA content is extracted.
Can I extract attribute values along with element text?
Yes. Enable the "Include attribute values" checkbox. Attribute values will be appended after the element's text content, separated by a space.
Why does the tool reject my DOCTYPE declaration?
This converter does not support DOCTYPE declarations or external entity resolution. Remove the DOCTYPE before pasting your XML, as processing external definitions would require network access.
How are special characters like ampersands handled?
The five standard XML entities (amp, lt, gt, quot, apos) and numeric character references (decimal and hexadecimal) are decoded automatically into their corresponding characters.
What if my XML is malformed?
The tokenizer stops at the first syntax error and reports the exact line and column number where the problem was found, making it easy to locate and fix the issue.