-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml-formatter.html
More file actions
862 lines (798 loc) · 54.8 KB
/
Copy pathxml-formatter.html
File metadata and controls
862 lines (798 loc) · 54.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>XML Formatter & Validator — SOAP, RSS, Atom | FreeDevTool</title>
<meta name="description" content="Free XML formatter, validator & minifier. SOAP, RSS, Atom, sitemap support. Native DOMParser validation. Browser-only, no upload.">
<meta name="robots" content="index, follow">
<meta name="author" content="Anees Ur Rehman">
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","datePublished":"2026-05-02","dateModified":"2026-05-19","inLanguage":"en-US","isPartOf":{"@type":"WebSite","name":"FreeDevTool","url":"https://freedevtool.org"}}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"Person","name":"Anees Ur Rehman","url":"https://freedevtool.org/about","jobTitle":"Full-stack developer","worksFor":{"@type":"Organization","name":"FreeDevTool","url":"https://freedevtool.org"}}</script>
<link rel="canonical" href="https://freedevtool.org/xml-formatter">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=DM+Sans:wght@300;400;500;600&display=swap" as="style">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=DM+Sans:wght@300;400;500;600&display=swap">
<link rel="preload" href="style.css?v=20260502-cards" as="style">
<link rel="stylesheet" href="style.css?v=20260502-cards">
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/favicon.svg">
<meta property="og:image" content="https://freedevtool.org/og-image.svg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="FreeDevTool — 50+ free, fast, privacy-first developer tools">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://freedevtool.org/og-image.svg">
<meta name="twitter:title" content="XML Formatter & Validator Online — Free | FreeDevTool">
<meta name="twitter:description" content="Pretty print, validate & minify XML. SOAP, RSS, Atom, sitemap support. Runs in browser, no signup, no uploads.">
<meta property="og:image" content="https://freedevtool.org/og-image.svg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta name="twitter:image" content="https://freedevtool.org/og-image.svg">
<script async src="https://www.googletagmanager.com/gtag/js?id=G-3L0CMH3X36"></script>
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag('js',new Date());gtag('config','G-3L0CMH3X36');</script>
<meta property="og:title" content="XML Formatter & Validator Online — Beautify XML Free">
<meta property="og:description" content="Format, beautify, validate and minify XML online. Free browser-based tool.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://freedevtool.org/xml-formatter">
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"WebApplication","name":"XML Formatter & Validator Online","url":"https://freedevtool.org/xml-formatter","description":"Format, beautify and validate XML documents online with proper indentation and error detection.","applicationCategory":"DeveloperApplication","operatingSystem":"Any","offers":{"@type":"Offer","price":"0","priceCurrency":"USD"}}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "HowTo",
"name": "How to format and validate XML online",
"description": "Pretty-print, validate, or minify any XML document (SOAP, RSS, Atom, sitemap) using the browser's native DOMParser.",
"step": [
{"@type":"HowToStep","name":"Paste XML","text":"Paste any XML — SOAP envelope, RSS feed, Atom feed, sitemap, or config file — into the input pane. The DOM parses locally; nothing uploads."},
{"@type":"HowToStep","name":"Choose action","text":"Click Format to add indentation, Minify to strip whitespace, or Validate to confirm well-formedness."},
{"@type":"HowToStep","name":"Read the result","text":"The right pane shows the transformed XML. Validation errors (mismatched tags, unquoted attributes, multiple roots) display with line numbers."},
{"@type":"HowToStep","name":"Copy or download","text":"Click Copy to clipboard for paste into your editor, or Download as .xml file."}
]
}
</script>
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is XML formatting and why is it important?","acceptedAnswer":{"@type":"Answer","text":"XML formatting adds consistent indentation and line breaks to XML documents, making deeply nested structures readable. Unformatted XML from APIs, SOAP services, RSS feeds, or configuration files is often a single long line. Proper formatting is essential for debugging XML parsing errors, reviewing configuration files, and understanding document structure."}},{"@type":"Question","name":"How do I validate XML syntax?","acceptedAnswer":{"@type":"Answer","text":"Well-formed XML must follow these rules: every opening tag must have a matching closing tag, tags must be properly nested (no overlapping), attribute values must be quoted, element names are case-sensitive, and there must be exactly one root element. This tool uses the browser's built-in DOMParser to validate XML and reports syntax errors with descriptions."}},{"@type":"Question","name":"What is the difference between XML and HTML?","acceptedAnswer":{"@type":"Answer","text":"XML is strict and extensible — you define your own tag names, all tags must be closed, attributes must be quoted, and element names are case-sensitive. HTML is more lenient — it has predefined tags, browsers auto-close some elements, and it's case-insensitive. XML is used for data transport (APIs, config files, RSS), while HTML is for rendering web pages."}},{"@type":"Question","name":"What is the difference between XML and JSON?","acceptedAnswer":{"@type":"Answer","text":"JSON is lighter, faster to parse, and the dominant format for web APIs. XML is more verbose but supports namespaces, attributes, CDATA, mixed content, and schemas (XSD). Legacy SOAP APIs and document formats (RSS, Atom, SVG, DOCX) still use XML. Most new APIs use JSON."}},{"@type":"Question","name":"What is an XSD schema?","acceptedAnswer":{"@type":"Answer","text":"XSD (XML Schema Definition) is a W3C standard for defining the structure, content, and data types of an XML document. Validators check XML against the XSD to verify correctness. XSD is more powerful than JSON Schema but also significantly more complex. Used in enterprise SOAP services."}},{"@type":"Question","name":"How do I minify XML for production?","acceptedAnswer":{"@type":"Answer","text":"Remove whitespace between elements, drop comments, and collapse self-closing empty elements. Note: whitespace inside elements is often semantically significant — strict minification can change document meaning. Use safe-mode that preserves intra-element whitespace."}}]}
</script>
<style>
.xml-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}
.xml-pane{display:flex;flex-direction:column;gap:6px}
.xml-pane label{font-size:12px;color:var(--text3);font-family:var(--mono)}
.xml-pane textarea{width:100%;height:340px;background:var(--bg);border:1px solid var(--border);border-radius:var(--radius);padding:14px;color:var(--text);font-family:var(--mono);font-size:13px;resize:vertical;line-height:1.6;tab-size:2}
.xml-pane textarea:focus{border-color:var(--accent);outline:none;box-shadow:0 0 0 3px rgba(0,208,132,.08)}
.xml-controls{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin:12px 0}
.xml-stats{display:flex;gap:16px;font-size:11px;font-family:var(--mono);color:var(--text3);margin-top:6px}
.xml-error{margin-top:8px;padding:10px 14px;background:rgba(255,107,107,.1);border:1px solid rgba(255,107,107,.3);border-radius:var(--radius);color:#ff6b6b;font-size:12px;font-family:var(--mono);display:none}
.xml-valid{margin-top:8px;padding:10px 14px;background:rgba(0,208,132,.1);border:1px solid rgba(0,208,132,.3);border-radius:var(--radius);color:var(--accent);font-size:12px;font-family:var(--mono);display:none}
@media(max-width:700px){.xml-grid{grid-template-columns:1fr}}
</style>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "https://freedevtool.org/"
},
{
"@type": "ListItem",
"position": 2,
"name": "All Tools",
"item": "https://freedevtool.org/all-tools"
},
{
"@type": "ListItem",
"position": 3,
"name": "XML Formatter & Validator",
"item": "https://freedevtool.org/xml-formatter"
}
]
}
</script>
<script src="/ga4-events.js" defer></script>
</head>
<body>
<nav>
<a class="nav-logo" href="/" aria-label="FreeDevTool home"><svg class="logo-mark" width="22" height="22" viewBox="0 0 24 24" aria-hidden="true" fill="none"><rect x="1" y="1" width="22" height="22" rx="6" fill="currentColor" opacity=".12"/><path d="M9.5 8.5L6 12l3.5 3.5M14.5 8.5L18 12l-3.5 3.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>FreeDevTool</a>
<div class="nav-links">
<div class="nav-dropdown" id="tools-dropdown">
<a href="all-tools" onclick="event.preventDefault();this.parentElement.classList.toggle('open')" aria-haspopup="true">Tools <svg class="chev" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="6 9 12 15 18 9"/></svg></a>
<div class="nav-dropdown-menu">
<a href="encoding-tools">
<div class="dd-icon">b64</div>
<div class="dd-info"><div class="dd-name">Encoding & Conversion</div><div class="dd-count">11 tools · Base64, YAML, px→rem</div></div>
</a>
<a href="generation-tools">
<div class="dd-icon">{ }</div>
<div class="dd-info"><div class="dd-name">Generation & Formatting</div><div class="dd-count">16 tools · JSON, SQL, gradients</div></div>
</a>
<a href="security-tools">
<div class="dd-icon">#</div>
<div class="dd-info"><div class="dd-name">Security & Hashing</div><div class="dd-count">3 tools · JWT, MD5, SHA</div></div>
</a>
<a href="text-tools">
<div class="dd-icon">.*</div>
<div class="dd-info"><div class="dd-name">Code & Text Tools</div><div class="dd-count">9 tools · Regex, diff, tokens</div></div>
</a>
<a href="devops-tools">
<div class="dd-icon">JS</div>
<div class="dd-info"><div class="dd-name">Optimization & DevOps</div><div class="dd-count">7 tools · Minifiers, cURL, git</div></div>
</a>
<a href="network-tools">
<div class="dd-icon">IP</div>
<div class="dd-info"><div class="dd-name">Network & Time</div><div class="dd-count">4 tools · IP, DNS, timestamps</div></div>
</a>
<a href="seo-tools">
<div class="dd-icon">SEO</div>
<div class="dd-info"><div class="dd-name">SEO & Meta Tools</div><div class="dd-count">3 tools · OG, meta, slug</div></div>
</a>
<div class="nav-dropdown-divider"></div>
<a class="dd-all" href="all-tools">
<div class="dd-icon">All</div>
<div class="dd-info"><div class="dd-name">Browse all 50 tools</div><div class="dd-count">Searchable catalog & categories</div></div>
</a>
</div>
</div>
<a href="/guides">Guides</a>
<a href="about">About</a>
<a href="privacy">Privacy</a>
</div>
</nav>
<div class="wrapper">
<section class="tool-header">
<a class="tool-back" href="/" aria-label="Back to home">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 18l-6-6 6-6"/></svg>
Back
</a>
<span class="tool-badge">Formatting</span>
<h1>XML Formatter, Validator & Beautifier Online</h1>
<p>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 <a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMParser" rel="noopener" style="color:var(--accent)">DOMParser</a> for accurate <a href="https://www.w3.org/TR/xml/" rel="noopener" style="color:var(--accent)">XML 1.0</a> well-formedness validation. Your XML data — including ones with sensitive content — never leaves your machine.</p>
<div class="last-updated">Last updated: May 2026 · Written by <a href="/about">Anees Ur Rehman</a>, full-stack developer</div>
</section>
<div class="tool-card">
<div class="card-dots"><span></span><span></span><span></span></div>
<div class="tool-body">
<div class="xml-controls">
<button class="btn btn-primary" onclick="formatXML()">Format / Beautify</button>
<button class="btn btn-ghost" onclick="minifyXML()">Minify</button>
<button class="btn btn-ghost" onclick="validateXML()">Validate</button>
<button class="btn btn-ghost" onclick="clearAll()">Clear</button>
<button class="btn btn-ghost" onclick="loadSample()">Sample</button>
<select id="indent-size" style="background:var(--bg);border:1px solid var(--border);border-radius:var(--radius);padding:6px 10px;color:var(--text);font-size:12px;font-family:var(--mono)">
<option value="2" selected>2 spaces</option>
<option value="4">4 spaces</option>
<option value="tab">Tab</option>
</select>
</div>
<div class="xml-grid">
<div class="xml-pane">
<label>Input XML</label>
<textarea id="xml-input" placeholder="Paste your XML here..." spellcheck="false"></textarea>
<div class="xml-stats"><span id="input-stats">0 lines, 0 chars</span></div>
</div>
<div class="xml-pane">
<label>Formatted Output</label>
<textarea id="xml-output" placeholder="Formatted XML will appear here..." readonly spellcheck="false"></textarea>
<div class="xml-stats">
<span id="output-stats">0 lines, 0 chars</span>
<button class="btn btn-ghost" onclick="copyOutput()" style="padding:2px 10px;font-size:11px">Copy</button>
</div>
</div>
</div>
<div class="xml-error" id="xml-error"></div>
<div class="xml-valid" id="xml-valid"></div>
</div>
</div>
<div id="toast" style="position:fixed;bottom:30px;left:50%;transform:translateX(-50%);background:var(--accent);color:#000;padding:8px 20px;border-radius:var(--radius);font-size:13px;font-weight:600;opacity:0;transition:opacity .3s;pointer-events:none;z-index:999">Copied!</div>
<!-- =============================================================
LONG-FORM ARTICLE — comprehensive guide for E-E-A-T + ranking.
============================================================= -->
<article>
<p class="aeo-lead" style="font-size:16px;line-height:1.7;color:var(--text);max-width:760px;margin:24px auto 18px;padding:0 4px">
<strong>XML formatting</strong> 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 <strong>free XML formatter</strong> handles SOAP, RSS, Atom, SVG, and namespace-rich XML 1.1.
</p>
<section id="examples" style="max-width:760px;margin:24px auto 32px">
<h2 style="font-size:18px;margin-bottom:14px">Examples</h2>
<div style="background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);padding:16px;margin-bottom:12px">
<strong style="display:block;color:var(--accent);font-family:var(--mono);font-size:11px;text-transform:uppercase;letter-spacing:1px;margin-bottom:6px">Pretty-print§§Input: <root><user id="1"><name>Alice</name></user></root>§§Output:§§<root>§§ <user id="1">§§ <name>Alice</name>§§ </user>§§</root></strong>
</div>
<div style="background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);padding:16px;margin-bottom:12px">
<strong style="display:block;color:var(--accent);font-family:var(--mono);font-size:11px;text-transform:uppercase;letter-spacing:1px;margin-bottom:6px">CDATA preservation§§<![CDATA[ Raw content, including <special> characters & "quotes" ]]>§§CDATA sections are left untouched — formatters must NOT escape or re-format the content inside.</strong>
</div>
<div style="background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);padding:16px;margin-bottom:12px">
<strong style="display:block;color:var(--accent);font-family:var(--mono);font-size:11px;text-transform:uppercase;letter-spacing:1px;margin-bottom:6px">RSS feed structure§§A valid RSS feed has <rss version="2.0"> containing <channel> with required <title>, <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 Gatsby</title><author>F. Scott Fitzgerald</author><year>1925</year><price>10.99</price></book><book category="tech"><title lang="en">Learning XML</title><author>Erik T. Ray</author><year>2003</year><price>39.95</price><publisher><name>O'Reilly Media</name><city>Sebastopol</city></publisher></book><book category="fiction"><title lang="es">Cien años de soledad</title><author>Gabriel García Márquez</author><year>1967</year><price>14.50</price></book></bookstore>`;
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');}
</script>
</body>
</html>