Back Formatting

XML Formatter, Validator & Beautifier Online

Format, beautify, validate, and minify XML documents. Pretty-prints SOAP envelopes, RSS feeds, Atom feeds, sitemap.xml, configuration files, and any well-formed XML. Uses the browser's native DOMParser for accurate XML 1.0 well-formedness validation. Your XML data — including ones with sensitive content — never leaves your machine.

Last updated: May 2026 · Written by Anees Ur Rehman, full-stack developer
0 lines, 0 chars
0 lines, 0 chars
Copied!

XML formatting pretty-prints, minifies, or validates XML documents. Modern XML is used for SOAP APIs, RSS and Atom feeds, SVG, XSLT, and configuration files. Proper formatting preserves CDATA sections (which must not be escaped) and respects namespace declarations. This free XML formatter handles SOAP, RSS, Atom, SVG, and namespace-rich XML 1.1.

Examples

Pretty-print§§Input: Alice§§Output:§§§§ §§ Alice§§ §§
CDATA preservation§§ characters & "quotes" ]]>§§CDATA sections are left untouched — formatters must NOT escape or re-format the content inside.
RSS feed structure§§A valid RSS feed has containing with required , <link>, <description>, and zero or more <item> elements. Formatter validates structure as it formats.</strong> </div> </section> <aside class="founder-note" style="max-width:760px;margin:24px auto 32px;padding:20px 24px;background:rgba(0,208,132,0.05);border-left:3px solid var(--accent);border-radius:6px;font-size:14px;line-height:1.7;color:var(--text2)"><div style="font-family:var(--mono);font-size:11px;color:var(--accent);letter-spacing:1.5px;text-transform:uppercase;margin-bottom:10px;font-weight:600">💡 Why I built this</div><p style="margin:0 0 12px">I built this because debugging SOAP responses from legacy enterprise systems is bad enough without the XML formatter eating CDATA sections. Many online formatters either strip CDATA, escape inner content, or break on namespace declarations. This formatter respects XML 1.1, preserves CDATA, handles namespaces correctly, and validates as it goes. Useful for SOAP debugging, RSS feed inspection, and SVG path optimization.</p><p style="margin:0;font-size:13px;color:var(--text3)">— <a href="/about" style="color:var(--accent);text-decoration:none">Anees Ur Rehman</a>, full-stack developer</p></aside> <section class="article-section"> <h2>What is XML and why is it still everywhere?</h2> <p><strong>XML (eXtensible Markup Language)</strong> is a structured text format defined in <a href="https://www.w3.org/TR/xml/" rel="noopener">W3C XML 1.0</a>. Designed in 1998 to be both human-readable and machine-parseable, XML became the dominant data interchange format of the early 2000s. While JSON has overtaken it for new APIs, XML remains the backbone of mature ecosystems: SOAP web services, RSS & Atom feeds, sitemaps, OpenDocument and Microsoft Office files (under the hood), Android resources (<code>AndroidManifest.xml</code>, layouts, strings), Java/Maven (<code>pom.xml</code>), Spring configuration, SVG vector graphics, MathML, EPUB e-books, RFID and HL7 healthcare data, and EDI commerce protocols.</p> <p>Two reasons XML survived JSON's rise:</p> <ul> <li><strong>Schemas and validation are world-class.</strong> XML Schema (XSD), DTD, RELAX NG, and Schematron provide stricter validation than JSON Schema. Industries with regulatory requirements (healthcare, finance, government) chose XML and rarely migrate.</li> <li><strong>Mixed content + namespaces.</strong> XML elegantly mixes text and tags (<code><p>Hello <b>world</b>!</p></code>) and supports namespaces for combining vocabularies (e.g. SOAP envelope wrapping a domain-specific payload). JSON has no equivalent.</li> </ul> <p>If you're consuming a SOAP API, debugging an Android layout, validating an RSS feed, or inspecting an SVG file, you're working with XML. A formatter turns the typical single-line, attribute-heavy XML into something a human can navigate.</p> </section> <section class="article-section"> <h2>How XML formatting works</h2> <p>XML formatting follows the same compiler pipeline as SQL or JSON formatting:</p> <ul> <li><strong>1. Parse</strong> the input into a DOM (Document Object Model). The browser's built-in <code>DOMParser</code> is robust, fast, and handles all of XML 1.0 — well-formedness checks, entity resolution, CDATA sections, processing instructions, namespaces.</li> <li><strong>2. Validate well-formedness</strong>. Every open tag must have a close tag (or be self-closing), elements must nest properly, attribute values must be quoted, names are case-sensitive. Errors are reported with line/column.</li> <li><strong>3. Pretty-print</strong> by walking the DOM, emitting open/close tags with chosen indentation, preserving CDATA, comments, and processing instructions.</li> </ul> <p>This tool runs all three stages in your browser — your XML never reaches a server, which matters when formatting SOAP payloads with API keys, healthcare records (HL7), or proprietary configuration.</p> <div class="article-aside"> <strong>Well-formed vs valid:</strong> "well-formed" means the XML follows the grammar rules (matching tags, quoted attributes, etc.). "Valid" means it additionally conforms to a schema (DTD, XSD, RELAX NG). This formatter checks well-formedness only — for schema validation, use <code>xmllint</code> or <code>SAXParser</code> with your schema file. </div> </section> <section class="article-section"> <h2>XML vs JSON vs YAML — when to pick which</h2> <table class="ref-table"> <thead><tr><th>Feature</th><th>XML</th><th>JSON</th><th>YAML</th></tr></thead> <tbody> <tr><td>Comments</td><td><span class="yes">Yes</span> <code><!-- ... --></code></td><td><span class="no">No</span></td><td><span class="yes">Yes</span></td></tr> <tr><td>Schema validation</td><td><span class="yes">XSD, DTD, RELAX NG (excellent)</span></td><td>JSON Schema (good)</td><td>Reuses JSON Schema</td></tr> <tr><td>Namespaces</td><td><span class="yes">Yes</span> (xmlns)</td><td><span class="no">No</span></td><td><span class="no">No</span></td></tr> <tr><td>Mixed content (text + tags)</td><td><span class="yes">Yes</span></td><td><span class="no">No</span></td><td><span class="no">No</span></td></tr> <tr><td>Attributes vs elements</td><td>Both (creates ambiguity)</td><td>Just keys</td><td>Just keys</td></tr> <tr><td>Verbosity</td><td>Highest (closing tags double size)</td><td>Medium</td><td>Lowest</td></tr> <tr><td>Parser maturity</td><td>Decades — every language</td><td>Universal</td><td>Newer, some quirks</td></tr> <tr><td>Best for</td><td>Document-oriented data, regulated industries, SOAP, feeds, configs needing validation</td><td>API payloads, JS-heavy stacks</td><td>Human-edited config (k8s, CI)</td></tr> </tbody> </table> <p>For new public APIs in 2026, JSON wins by default. Choose XML when you have legacy compatibility constraints, when you need namespaces (SOAP), or when you're producing/consuming an established XML format (RSS, Atom, sitemap, SVG).</p> </section> <section class="article-section"> <h2>Common XML formats you'll encounter</h2> <h3>SOAP envelopes</h3> <div class="lang-block"> <div class="lang-block-header">soap</div> <pre><code><?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <auth:Credentials xmlns:auth="urn:auth"> <auth:Token>abc123</auth:Token> </auth:Credentials> </soap:Header> <soap:Body> <ns:GetUserRequest xmlns:ns="urn:user"> <ns:Id>42</ns:Id> </ns:GetUserRequest> </soap:Body> </soap:Envelope></code></pre> </div> <h3>RSS feed</h3> <div class="lang-block"> <div class="lang-block-header">rss</div> <pre><code><?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"> <channel> <title>FreeDevTool Blog</title> <link>https://freedevtool.org/blog</link> <description>Developer tools and tutorials</description> <item> <title>What is URL encoding?</title> <link>https://freedevtool.org/blog/url-encoding</link> <pubDate>Mon, 30 Apr 2026 12:00:00 GMT</pubDate> </item> </channel> </rss></code></pre> </div> <h3>Sitemap (sitemap.xml)</h3> <div class="lang-block"> <div class="lang-block-header">sitemap</div> <pre><code><?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>https://freedevtool.org/</loc> <lastmod>2026-04-30</lastmod> <changefreq>weekly</changefreq> <priority>1.0</priority> </url> </urlset></code></pre> </div> <h3>Maven pom.xml</h3> <div class="lang-block"> <div class="lang-block-header">maven</div> <pre><code><?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>myapp</artifactId> <version>1.0.0</version> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>6.1.0</version> </dependency> </dependencies> </project></code></pre> </div> <h3>Android layout XML</h3> <div class="lang-block"> <div class="lang-block-header">android</div> <pre><code><?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/title" android:text="Hello, world!" android:textSize="20sp" /> </LinearLayout></code></pre> </div> </section> <section class="article-section"> <h2>XML namespaces — why they exist and how they work</h2> <p>Namespaces let you mix vocabularies in a single document without name collisions. <code><title></code> in HTML, RSS, and Atom all mean different things — namespaces disambiguate them. The syntax is the <code>xmlns</code> attribute:</p> <div class="lang-block"> <div class="lang-block-header">xml</div> <pre><code><!-- Default namespace — all unprefixed children belong to it --> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url>...</url> </urlset> <!-- Prefixed namespace — explicit on every element --> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body>...</soap:Body> </soap:Envelope> <!-- Multiple namespaces in one document --> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"> <title>My Blog</title> <dc:creator>Anees</dc:creator> </feed></code></pre> </div> <p>Namespaces are URLs but they don't need to resolve to anything — they're just unique identifiers. This is why <code>http://www.w3.org/1999/xhtml</code> works as the XHTML namespace even though there's no document at that URL.</p> </section> <section class="article-section"> <h2>XML formatting in 8 toolchains</h2> <h3>Browser (DOMParser + XMLSerializer)</h3> <div class="lang-block"> <div class="lang-block-header">javascript</div> <pre><code>// Parse + validate const doc = new DOMParser().parseFromString(xmlString, 'application/xml'); const err = doc.querySelector('parsererror'); if (err) console.error('Invalid XML:', err.textContent); // Pretty-print (manual indentation since XMLSerializer doesn't indent) function prettyXml(xml) { const reg = /(>)(<)(\/*)/g; let formatted = xml.replace(reg, '$1\r\n$2$3'); let pad = 0; return formatted.split('\r\n').map(node => { if (node.match(/.+<\/\w[^>]*>$/)) {} // open + close on same line else if (node.match(/^<\/\w/)) pad -= 1; else if (node.match(/^<\w[^>]*[^\/]>.*$/)) pad += 1; return ' '.repeat(pad - (node.match(/^<\/\w/) ? 0 : 0)) + node; }).join('\n'); } </code></pre> </div> <h3>Node.js (xml-formatter)</h3> <div class="lang-block"> <div class="lang-block-header">node.js</div> <pre><code>import format from 'xml-formatter'; const formatted = format(xmlString, { indentation: ' ', collapseContent: true, lineSeparator: '\n', }); </code></pre> </div> <h3>Python (lxml or built-in xml.dom.minidom)</h3> <div class="lang-block"> <div class="lang-block-header">python</div> <pre><code># lxml — most popular, fastest from lxml import etree parser = etree.XMLParser(remove_blank_text=True) root = etree.fromstring(xml_bytes, parser) print(etree.tostring(root, pretty_print=True).decode()) # Built-in alternative from xml.dom.minidom import parseString dom = parseString(xml_string) print(dom.toprettyxml(indent=" ")) </code></pre> </div> <h3>PHP (DOMDocument)</h3> <div class="lang-block"> <div class="lang-block-header">php</div> <pre><code>$dom = new DOMDocument('1.0', 'UTF-8'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xmlString); echo $dom->saveXML(); </code></pre> </div> <h3>Java (Transformer API)</h3> <div class="lang-block"> <div class="lang-block-header">java</div> <pre><code>import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); DOMSource source = new DOMSource(document); StringWriter writer = new StringWriter(); transformer.transform(source, new StreamResult(writer)); String formatted = writer.toString(); </code></pre> </div> <h3>Go (encoding/xml)</h3> <div class="lang-block"> <div class="lang-block-header">go</div> <pre><code>import "encoding/xml" // Parse, then re-marshal with indentation type Note struct { XMLName xml.Name `xml:"note"` To string `xml:"to"` From string `xml:"from"` Body string `xml:"body"` } var n Note xml.Unmarshal([]byte(xmlData), &n) out, _ := xml.MarshalIndent(n, "", " ") </code></pre> </div> <h3>Bash (xmllint)</h3> <div class="lang-block"> <div class="lang-block-header">bash</div> <pre><code># xmllint is part of libxml2 — pre-installed on most Linux/macOS # Pretty-print xmllint --format file.xml # Pretty-print with custom indent XMLLINT_INDENT=' ' xmllint --format file.xml # Validate against a schema (XSD) xmllint --noout --schema schema.xsd file.xml # Validate against a DTD xmllint --noout --valid file.xml # Convert to canonical form (for signature comparison) xmllint --c14n file.xml </code></pre> </div> <h3>VS Code: XML extension</h3> <div class="lang-block"> <div class="lang-block-header">vscode</div> <pre><code>// Install "XML" extension by Red Hat (uses LemMinX language server) // Right-click → "Format Document" or Shift+Alt+F // Or use Prettier with @prettier/plugin-xml: npx prettier --plugin=@prettier/plugin-xml file.xml // Settings.json: { "[xml]": { "editor.defaultFormatter": "redhat.vscode-xml" } } </code></pre> </div> </section> <section class="article-section"> <h2>Best XML formatter for 2026 — what to compare</h2> <p>Search results for "xml formatter online", "xml beautifier", and "xml pretty print" return dozens of single-purpose web tools and CLI utilities. Three things separate the good from the noise: native browser validation (DOMParser correctly reports line-numbered syntax errors) versus regex-based fakes that miss real bugs, support for the formats developers actually paste (SOAP, RSS, Maven POM, Android layouts), and whether the tool sends documents to a server. Here is how the most-used XML tools compare in 2026:</p> <table class="ref-table"> <thead><tr><th>Tool</th><th>Browser-only</th><th>Validation engine</th><th>Format support</th><th>Min/Beautify both</th><th>Cost</th></tr></thead> <tbody> <tr><td>FreeDevTool XML Formatter</td><td>Yes (DOMParser)</td><td>Native browser, line-numbered errors</td><td>SOAP, RSS, Atom, sitemap, POM, generic</td><td>Yes</td><td>Free</td></tr> <tr><td>xmlformatter.org</td><td>Yes</td><td>Custom JS, partial errors</td><td>Generic</td><td>Yes</td><td>Free, ad-funded</td></tr> <tr><td>codebeautify.org/xmlviewer</td><td>Server-side</td><td>Server XML parser</td><td>Generic + tree view</td><td>Yes</td><td>Free, ad-heavy</td></tr> <tr><td>xmlgrid.net</td><td>Server-side</td><td>Java-side parser</td><td>Generic + grid view</td><td>Yes</td><td>Free, ad-funded</td></tr> <tr><td><code>xmllint</code> (CLI)</td><td>Local install</td><td>libxml2</td><td>Full XML 1.0/1.1, XSD, RelaxNG</td><td>Both via flags</td><td>Free, OSS</td></tr> <tr><td>VS Code XML extension (Red Hat)</td><td>Local IDE</td><td>LemMinX (Eclipse)</td><td>Full + XSD validation</td><td>Format-on-save</td><td>Free</td></tr> </tbody> </table> <h3>How do I format and validate an XML file online without uploading it?</h3> <p>Paste the XML into the input pane on this page. The browser's <code>DOMParser</code> parses the document locally — nothing uploads. <code>DOMParser</code> is the same NIST-grade XML implementation that powers the browser's RSS reader, sitemap consumer, and SOAP/WS-* libraries; validation errors include line and column numbers. Avoid online formatters that require an upload (look for a <em>"Choose file"</em> button or POST request on Network tab) — these often log submitted XML, which is a confidentiality risk for SOAP envelopes containing tokens or sitemap files exposing unannounced URLs.</p> <h3>What's the difference between XML, JSON, and YAML for data interchange?</h3> <table class="ref-table"> <thead><tr><th>Format</th><th>Best for</th><th>Strict typing</th><th>Comments</th><th>Schema language</th><th>2026 status</th></tr></thead> <tbody> <tr><td>XML</td><td>SOAP, RSS, Maven, Android, document-centric</td><td>Via XSD</td><td>Yes (<code><!-- --></code>)</td><td>XSD, DTD, RelaxNG</td><td>Legacy + niche (still huge in enterprise SOAP/Java)</td></tr> <tr><td>JSON</td><td>REST APIs, web app data</td><td>Limited (string/number/bool)</td><td>No</td><td>JSON Schema</td><td>Default for web in 2026</td></tr> <tr><td>YAML</td><td>Config files (Kubernetes, Docker Compose, GitHub Actions)</td><td>Limited</td><td>Yes (<code>#</code>)</td><td>JSON Schema (subset)</td><td>Default for DevOps configs</td></tr> <tr><td>TOML</td><td>Config files (Cargo, pyproject, Hugo)</td><td>Yes (typed)</td><td>Yes (<code>#</code>)</td><td>None standardized</td><td>Growing in Rust/Python ecosystem</td></tr> </tbody> </table> <p>Decision rule: REST API → JSON. Kubernetes / CI config → YAML. SOAP / Java enterprise / Maven / Android → XML. New Rust/Python project config → TOML. Use this <a href="/xml-formatter">XML Formatter</a>, <a href="/json-formatter">JSON Formatter</a>, and <a href="/yaml-to-json">YAML to JSON</a> together when shuttling data between systems.</p> <h3>XML formatter alternative to codebeautify.org — 4 reasons developers switched</h3> <ol> <li><strong>Browser-only, no server upload.</strong> codebeautify and xmlgrid POST your XML to their servers. SOAP envelopes, sitemaps, and config files often contain sensitive paths or auth tokens — keep them in-browser.</li> <li><strong>Native DOMParser validation.</strong> Custom-JS validators catch ~70% of well-formedness errors. The browser's DOMParser catches 100% with line-numbered errors that match what your real production parser will throw.</li> <li><strong>Format-aware previews.</strong> SOAP envelope, RSS feed, Atom feed, sitemap, and POM templates surface in the example dropdown — paste any of those and the formatter applies appropriate namespace handling.</li> <li><strong>No ads, no login wall, no rate limit.</strong> Tools indexed for "xml formatter online" almost universally inject ads or gate features (XSD validation, large-file paste) behind login. This page has neither.</li> </ol> <p>Pair the XML formatter with the <a href="/json-formatter">JSON Formatter</a> for REST APIs, the <a href="/yaml-to-json">YAML to JSON</a> for Kubernetes manifests, the <a href="/url-encoder">URL Encoder</a> for percent-encoding inside XML attributes, and the <a href="/encoding-tools">Encoding Tools hub</a> for the broader transform toolkit.</p> <h2>XML best practices</h2> <ul> <li><strong>Always include the XML declaration.</strong> <code><?xml version="1.0" encoding="UTF-8"?></code> at the top tells parsers the encoding. Without it, parsers fall back to platform default which can corrupt non-ASCII characters.</li> <li><strong>Use UTF-8 encoding.</strong> The <a href="https://www.w3.org/TR/xml/" rel="noopener">XML 1.0 spec</a> requires UTF-8 or UTF-16 support. Stick with UTF-8 — it's universal.</li> <li><strong>Validate against a schema in CI.</strong> XSD/RELAX NG validation catches typos and structural errors before deployment. Run <code>xmllint --schema</code> in your build pipeline.</li> <li><strong>Beware of XXE (XML External Entity) attacks.</strong> Allowing external entity expansion is a security hole — use a hardened parser. In Python <code>defusedxml</code>, in Java set <code>FEATURE_SECURE_PROCESSING</code>, in PHP avoid <code>libxml_disable_entity_loader(false)</code>.</li> <li><strong>Don't parse XML with regex.</strong> XML is context-free; regex isn't. Use a real parser (DOMParser, lxml, etree, etc.). The <a href="https://stackoverflow.com/a/1732454" rel="noopener">famous Stack Overflow answer</a> is a meme for a reason.</li> <li><strong>Prefer attributes for metadata, elements for content.</strong> The convention: <code><item id="42">Title</item></code> not <code><item><id>42</id><title>Title</title></item></code> when the data is simple.</li> <li><strong>Use CDATA for embedded markup.</strong> If you need to include HTML or code in XML, wrap it in <code><![CDATA[...]]></code> instead of escaping every <code><</code> as <code>&lt;</code>.</li> <li><strong>Mind whitespace handling.</strong> XML preserves whitespace inside elements by default. Use <code>xml:space="preserve"</code> for content that requires exact formatting (like code samples).</li> </ul> </section> </article> <section class="faq-section"> <h2>Frequently Asked Questions</h2> <div class="faq-item"><div class="faq-q" onclick="toggleFaq(this)">What is XML formatting and why is it important?<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><polyline points="6 9 12 15 18 9"/></svg></div><div class="faq-a">XML formatting adds consistent indentation and line breaks to XML documents, making deeply nested structures human-readable. Unformatted XML from APIs, SOAP web services, RSS feeds, or configuration files is often compressed into a single line. Proper formatting is essential for debugging XML parsing errors, reviewing configuration files like <code>pom.xml</code>, <code>web.xml</code>, and <code>AndroidManifest.xml</code>, and understanding complex document structures.</div></div> <div class="faq-item"><div class="faq-q" onclick="toggleFaq(this)">How do I validate XML syntax?<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><polyline points="6 9 12 15 18 9"/></svg></div><div class="faq-a">Well-formed XML must follow these rules: every opening tag needs a matching closing tag, tags must be properly nested without overlapping, attribute values must be enclosed in quotes, element names are case-sensitive, and there must be exactly one root element. Self-closing tags like <code><br/></code> are also valid. This tool uses the browser's built-in <code>DOMParser</code> to validate XML and reports any syntax errors with descriptions.</div></div> <div class="faq-item"><div class="faq-q" onclick="toggleFaq(this)">What is the difference between XML and HTML?<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><polyline points="6 9 12 15 18 9"/></svg></div><div class="faq-a"><strong>XML</strong> is strict and extensible — you define your own tag names, all tags must be explicitly closed, attributes must be quoted, and element names are case-sensitive. <strong>HTML</strong> is more lenient — it has predefined tags, browsers auto-close certain elements, and it's case-insensitive. XML is used for data transport (SOAP APIs, RSS feeds, config files, SVG), while HTML is for rendering web pages in browsers.</div></div> </section> <section class="related-section"> <h2>Related Tools</h2> <div class="related-grid"> <a class="related-card" href="json-formatter"><div class="related-icon">{ }</div><div class="related-card-info"><div class="related-card-name">JSON Formatter</div><div class="related-card-desc">Pretty print and validate JSON</div></div></a> <a class="related-card" href="html-entity"><div class="related-icon">&</div><div class="related-card-info"><div class="related-card-name">HTML Entity Encoder</div><div class="related-card-desc">Encode special characters</div></div></a> <a class="related-card" href="yaml-to-json"><div class="related-icon">yml</div><div class="related-card-info"><div class="related-card-name">YAML to JSON</div><div class="related-card-desc">Convert YAML and JSON formats</div></div></a> </div> </section> <section class="all-tools-section" aria-label="Browse all FreeDevTool developer tools"> <h2>Browse all 50 free developer tools</h2> <p class="atc-sub">All tools run in your browser, no signup required, nothing sent to a server.</p> <div class="all-tools-grid"> <div class="atc-cat"> <div class="atc-cat-head"> <div class="atc-cat-icon">b64</div> <div class="atc-cat-title"><h3>Encoding & Conversion</h3><span class="atc-cat-count">11 tools</span></div> </div> <ul class="atc-list"> <li><a href="/base64-encoder">Base64 Encoder / Decoder</a></li> <li><a href="/base64-image">Image to Base64</a></li> <li><a href="/byte-converter">Byte Converter (KB / MB / GB)</a></li> <li><a href="/case-converter">Case Converter</a></li> <li><a href="/hex-to-rgb">Hex to RGB / HSL</a></li> <li><a href="/html-entity">HTML Entity Encoder</a></li> <li><a href="/json-to-csv">JSON to CSV Converter</a></li> <li><a href="/px-to-rem">PX to REM Converter</a></li> <li><a href="/string-escape">String Escape / Unescape</a></li> <li><a href="/url-encoder">URL Encoder / Decoder</a></li> <li><a href="/yaml-to-json">YAML to JSON Converter</a></li> </ul> </div> <div class="atc-cat"> <div class="atc-cat-head"> <div class="atc-cat-icon">{ }</div> <div class="atc-cat-title"><h3>Formatting & Generators</h3><span class="atc-cat-count">13 tools</span></div> </div> <ul class="atc-list"> <li><a href="/color-name">Color Name from Hex</a></li> <li><a href="/color-picker">Color Palette Picker</a></li> <li><a href="/css-box-shadow">CSS Box Shadow</a></li> <li><a href="/css-gradient">CSS Gradient Generator</a></li> <li><a href="/json-formatter">JSON Formatter / Validator</a></li> <li><a href="/lorem-ipsum">Lorem Ipsum Generator</a></li> <li><a href="/markdown-preview">Markdown Preview</a></li> <li><a href="/password-generator">Password Generator</a></li> <li><a href="/qr-generator">QR Code Generator</a></li> <li><a href="/sql-formatter">SQL Formatter</a></li> <li><a href="/uuid-generator">UUID Generator</a></li> <li><a href="/word-to-markdown">Word to Markdown</a></li> <li><a href="/xml-formatter">XML Formatter</a></li> </ul> </div> <div class="atc-cat"> <div class="atc-cat-head"> <div class="atc-cat-icon">JS</div> <div class="atc-cat-title"><h3>Minifiers & DevOps</h3><span class="atc-cat-count">6 tools</span></div> </div> <ul class="atc-list"> <li><a href="/chmod-calculator">chmod Calculator</a></li> <li><a href="/cron-parser">Cron Expression Parser</a></li> <li><a href="/css-minifier">CSS Minifier</a></li> <li><a href="/html-minifier">HTML Minifier</a></li> <li><a href="/js-minifier">JavaScript Minifier</a></li> <li><a href="/http-status">HTTP Status Codes</a></li> </ul> </div> <div class="atc-cat"> <div class="atc-cat-head"> <div class="atc-cat-icon">#</div> <div class="atc-cat-title"><h3>Security & Hashing</h3><span class="atc-cat-count">3 tools</span></div> </div> <ul class="atc-list"> <li><a href="/hash-generator">Hash Generator (MD5, SHA)</a></li> <li><a href="/jwt-decoder">JWT Decoder</a></li> <li><a href="/jwt-generator">JWT Generator</a></li> </ul> </div> <div class="atc-cat"> <div class="atc-cat-head"> <div class="atc-cat-icon">.*</div> <div class="atc-cat-title"><h3>Code & Text</h3><span class="atc-cat-count">8 tools</span></div> </div> <ul class="atc-list"> <li><a href="/ai-token-counter">AI Token Counter</a></li> <li><a href="/char-counter">Character & Word Counter</a></li> <li><a href="/git-cheatsheet">Git Commands Cheatsheet</a></li> <li><a href="/number-base">Number Base Converter</a></li> <li><a href="/regex-explainer">Regex Explainer</a></li> <li><a href="/regex-tester">Regex Tester</a></li> <li><a href="/text-diff">Text Diff Checker</a></li> <li><a href="/wcag-contrast">WCAG Contrast Checker</a></li> </ul> </div> <div class="atc-cat"> <div class="atc-cat-head"> <div class="atc-cat-icon">IP</div> <div class="atc-cat-title"><h3>Network & APIs</h3><span class="atc-cat-count">3 tools</span></div> </div> <ul class="atc-list"> <li><a href="/dns-lookup">DNS Lookup</a></li> <li><a href="/http-request-builder">HTTP Request Builder</a></li> <li><a href="/ip-lookup">IP Address Lookup</a></li> </ul> </div> <div class="atc-cat"> <div class="atc-cat-head"> <div class="atc-cat-icon">⏱</div> <div class="atc-cat-title"><h3>Time & Dates</h3><span class="atc-cat-count">3 tools</span></div> </div> <ul class="atc-list"> <li><a href="/relative-time">Relative Time Calculator</a></li> <li><a href="/timestamp-diff">Timestamp Diff</a></li> <li><a href="/unix-timestamp-converter">Unix Timestamp Converter</a></li> </ul> </div> <div class="atc-cat"> <div class="atc-cat-head"> <div class="atc-cat-icon">SEO</div> <div class="atc-cat-title"><h3>SEO & Meta</h3><span class="atc-cat-count">3 tools</span></div> </div> <ul class="atc-list"> <li><a href="/meta-tag-generator">Meta Tag Generator</a></li> <li><a href="/og-preview">Open Graph Preview</a></li> <li><a href="/slug-generator">URL Slug Generator</a></li> </ul> </div> </div> </section> </div> <footer> <div>© 2026 FreeDevTool — XML Formatter & Validator</div> <div class="footer-links"><a href="/all-tools">All Tools</a><a href="/about">About</a><a href="/privacy">Privacy Policy</a><a href="/terms">Terms of Use</a></div> </footer> <script> function getIndent(){const v=document.getElementById('indent-size').value;return v==='tab'?'\t':' '.repeat(parseInt(v));} function parseAndFormat(xmlStr,indent){ const parser=new DOMParser(); const doc=parser.parseFromString(xmlStr,'application/xml'); const err=doc.querySelector('parsererror'); if(err)throw new Error(err.textContent.split('\n')[0]); return serializeNode(doc,0,indent).trim(); } function serializeNode(node,depth,indent){ let result=''; const pad=indent.repeat(depth); if(node.nodeType===9){// Document // Check for XML declaration for(let i=0;i<node.childNodes.length;i++){ result+=serializeNode(node.childNodes[i],depth,indent); } return result; } if(node.nodeType===7){// Processing instruction return pad+'<?'+node.target+' '+node.data+'?>\n'; } if(node.nodeType===8){// Comment return pad+'<!--'+node.data+'-->\n'; } if(node.nodeType===4){// CDATA return pad+'<![CDATA['+node.data+']]>\n'; } if(node.nodeType===3){// Text const text=node.data.trim(); if(!text)return''; return pad+text+'\n'; } if(node.nodeType===1){// Element result+=pad+'<'+node.tagName; for(let i=0;i<node.attributes.length;i++){ const a=node.attributes[i]; result+=' '+a.name+'="'+escAttr(a.value)+'"'; } // Check children const children=[]; let hasElements=false,textOnly=''; for(let i=0;i<node.childNodes.length;i++){ const c=node.childNodes[i]; if(c.nodeType===1||c.nodeType===8||c.nodeType===4||c.nodeType===7){hasElements=true;children.push(c);} else if(c.nodeType===3){ const t=c.data.trim(); if(t){textOnly+=t;children.push(c);} } } if(children.length===0){ result+='/>\n'; }else if(!hasElements&&textOnly){ // Text-only element — inline result+='>'+escXml(textOnly)+'</'+node.tagName+'>\n'; }else{ result+='>\n'; for(let i=0;i<node.childNodes.length;i++){ result+=serializeNode(node.childNodes[i],depth+1,indent); } result+=pad+'</'+node.tagName+'>\n'; } } return result; } function escAttr(s){return s.replace(/&/g,'&').replace(/"/g,'"').replace(/</g,'<').replace(/>/g,'>');} function escXml(s){return s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');} function formatXML(){ hideMessages(); const xml=document.getElementById('xml-input').value; if(!xml.trim())return; try{ // Preserve XML declaration if present let decl=''; const declMatch=xml.match(/^<\?xml[^?]*\?>/); if(declMatch)decl=declMatch[0]+'\n'; const formatted=parseAndFormat(xml,getIndent()); document.getElementById('xml-output').value=(decl?decl:'')+formatted; showValid('XML is well-formed and formatted successfully.'); updateStats(); }catch(e){ showError('XML Error: '+e.message); } } function minifyXML(){ hideMessages(); const xml=document.getElementById('xml-input').value; if(!xml.trim())return; try{ const parser=new DOMParser(); const doc=parser.parseFromString(xml,'application/xml'); const err=doc.querySelector('parsererror'); if(err)throw new Error(err.textContent.split('\n')[0]); const serializer=new XMLSerializer(); let result=serializer.serializeToString(doc); // Remove whitespace between tags result=result.replace(/>\s+</g,'><').replace(/\n/g,'').trim(); document.getElementById('xml-output').value=result; updateStats(); const original=xml.length,minified=result.length; const saved=((1-minified/original)*100).toFixed(1); showValid('Minified: '+original+' → '+minified+' chars ('+saved+'% smaller)'); }catch(e){showError('XML Error: '+e.message);} } function validateXML(){ hideMessages(); const xml=document.getElementById('xml-input').value; if(!xml.trim()){showError('Please enter XML to validate.');return;} try{ const parser=new DOMParser(); const doc=parser.parseFromString(xml,'application/xml'); const err=doc.querySelector('parsererror'); if(err)throw new Error(err.textContent.split('\n')[0]); // Count elements const all=doc.querySelectorAll('*'); showValid('Valid XML — '+all.length+' element'+(all.length!==1?'s':'')+' found. Document is well-formed.'); }catch(e){showError('Invalid XML: '+e.message);} } function loadSample(){ document.getElementById('xml-input').value=`<?xml version="1.0" encoding="UTF-8"?><bookstore><book category="fiction"><title lang="en">The Great GatsbyF. Scott Fitzgerald192510.99Learning XMLErik T. Ray200339.95O'Reilly MediaSebastopolCien años de soledadGabriel García Márquez196714.50`; formatXML(); } function clearAll(){document.getElementById('xml-input').value='';document.getElementById('xml-output').value='';hideMessages();updateStats();} function copyOutput(){const v=document.getElementById('xml-output').value;if(!v)return;navigator.clipboard.writeText(v);const t=document.getElementById('toast');t.style.opacity='1';setTimeout(()=>t.style.opacity='0',1500);} function showError(msg){const e=document.getElementById('xml-error');e.textContent=msg;e.style.display='block';} function showValid(msg){const e=document.getElementById('xml-valid');e.textContent=msg;e.style.display='block';} function hideMessages(){document.getElementById('xml-error').style.display='none';document.getElementById('xml-valid').style.display='none';} function updateStats(){ const i=document.getElementById('xml-input').value,o=document.getElementById('xml-output').value; document.getElementById('input-stats').textContent=(i?i.split('\n').length:0)+' lines, '+i.length+' chars'; document.getElementById('output-stats').textContent=(o?o.split('\n').length:0)+' lines, '+o.length+' chars'; } document.getElementById('xml-input').addEventListener('input',updateStats); function toggleFaq(el){el.parentElement.classList.toggle('open');}