BytePane

XML Formatter & Validator: Pretty Print XML Online Free

XML15 min read

The SOAP Response That No One Can Read

A developer debugging a payment gateway integration pastes this into Slack:

Unformatted SOAP response (real-world example, anonymized)
<?xml version="1.0"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:PaymentResponse xmlns:ns2="http://payments.example.com/v2"><ns2:status>DECLINED</ns2:status><ns2:errorCode>CVV_MISMATCH</ns2:errorCode><ns2:transactionId>TXN-8472910</ns2:transactionId><ns2:timestamp>2026-04-08T14:23:11Z</ns2:timestamp></ns2:PaymentResponse></soap:Body></soap:Envelope>

Nobody can debug that in Slack. Run it through a formatter and it immediately becomes readable:

After formatting (2-space indent)
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ns2:PaymentResponse xmlns:ns2="http://payments.example.com/v2">
      <ns2:status>DECLINED</ns2:status>
      <ns2:errorCode>CVV_MISMATCH</ns2:errorCode>
      <ns2:transactionId>TXN-8472910</ns2:transactionId>
      <ns2:timestamp>2026-04-08T14:23:11Z</ns2:timestamp>
    </ns2:PaymentResponse>
  </soap:Body>
</soap:Envelope>

The CVV mismatch error — invisible in the minified form — is immediately obvious after formatting. This is the core value proposition of an XML formatter: turning machine-optimized output into human-readable structure. BytePane's XML Formatter & Validator handles this in your browser with no data leaving your device.

Key Takeaways

  • XML is not dying — 78% of organizations still use XML for inter-application communication (2025 survey data). It dominates healthcare (HL7), finance (FpML), Maven builds, and Android layouts.
  • fast-xml-parser receives 56.7 million weekly npm downloads (April 2026) — nearly 2× the downloads of xml2js — making it the clear Node.js ecosystem choice for XML parsing.
  • XML DOM parsing is 5× slower than JSON parsing (250ms vs 50ms for 10,000 records in benchmarks). XML SAX parsing (event-driven) reduces this to 2×. This performance gap drove JSON's dominance in REST APIs.
  • There are two distinct validation levels: well-formedness (syntax rules, checked by any parser) and validity (conformance to a schema — DTD or XSD). Most online formatters only check well-formedness.
  • XSD 1.1 (W3C Recommendation, 2012) added assertions and conditional type definitions — features that make it significantly more expressive than DTDs or XSD 1.0 for enterprise data validation.

Well-Formedness vs. Validity: What XML Validators Actually Check

This is the distinction most developers blur, and it matters when you are debugging a validation error. The W3C XML 1.0 specification defines two distinct levels:

Well-Formedness: The Baseline

A well-formed XML document satisfies the W3C XML 1.0 syntax rules. Any XML parser — whether the browser's native DOMParser, Java's DocumentBuilder, or Python's xml.etree.ElementTree — enforces well-formedness. If a document is not well-formed, parsing fails completely with no partial result. Key rules:

  • Exactly one root element — multiple root elements are a syntax error
  • All tags must be closed — either with a closing tag (</tag>) or self-closing (<tag />)
  • Proper nesting<a><b></a></b> is invalid; tags must close in reverse order
  • Attribute values quoted — both single and double quotes are valid: attr="value" or attr='value'
  • Special characters escaped& must be &amp;, < must be &lt; in text content
  • Valid XML declaration — if present, <?xml version="1.0" encoding="UTF-8"?> must be on the first line

Validity: Schema Conformance

A valid XML document is well-formed and conforms to a schema. Validity is optional — you can parse and use well-formed XML that has no schema at all. Schema validation is relevant when:

  • You are integrating with a third-party system that mandates a specific schema (HL7, FpML, Maven POM)
  • You need to enforce data types, required fields, or value constraints at the API boundary
  • You are building a document management system that needs to guarantee document structure across writers
FeatureDTDXSD 1.0XSD 1.1
Data typesNone (all text)19 primitives19 primitives + dateTimeStamp
Namespace supportNoYesYes
Assertions (co-occurrence)NoNoYes
Conditional type assignmentNoNoYes
JDK default supportYesYesNo (needs Xerces 2.12+)
Written inSpecial syntaxXML itselfXML itself

XSD 1.1 became a W3C Recommendation in April 2012, but JDK's built-in javax.xml.validation only supports XSD 1.0. For XSD 1.1 validation in Java, you need Apache Xerces 2.12.2 or later as an explicit dependency.

XML Namespaces: Why They Exist and How They Work

Namespaces are the most consistently misunderstood feature of XML, and the most common source of "why won't this parse?" questions. The W3C Namespaces in XML recommendation (1999) was created to solve a specific problem: element name collisions when combining XML documents from different sources.

Consider a document that merges HR data with project data. Both might define a <name> element — one for a person's name, one for a project name. Without namespaces, these are indistinguishable. With namespaces:

<!-- Two <name> elements from different vocabularies, no conflict -->
<document
  xmlns:hr="http://hr.example.com/v1"
  xmlns:proj="http://projects.example.com/v2">

  <hr:employee>
    <hr:name>Alice Chen</hr:name>
    <hr:department>Engineering</hr:department>
  </hr:employee>

  <proj:project>
    <proj:name>Phoenix Rewrite</proj:name>
    <proj:deadline>2026-12-01</proj:deadline>
  </proj:project>

</document>

Key points about namespace URIs that trip developers up:

  • URIs are identifiers, not URLs. The URI http://hr.example.com/v1 does not need to resolve to any actual web page. It is just a globally unique string used as an identifier.
  • The prefix is arbitrary. xmlns:hr, xmlns:human-resources, and xmlns:x are all equivalent if they map to the same URI. XPath and XSD validation care about the URI, not the prefix.
  • The default namespace (xmlns="uri") applies to all unprefixed elements in scope. If you are parsing XML with a default namespace in Java using XPath, you must register a namespace context or the path expressions will not match.

The default namespace XPath gotcha deserves a code example:

Java — the default namespace XPath bug and fix
// XML: <root xmlns="http://example.com/ns"><item>value</item></root>

// WRONG: This XPath returns null — unprefixed /root/item doesn't resolve
// the default namespace
NodeList result = (NodeList) xpath.evaluate("/root/item", doc, NODESET);

// RIGHT: Register a namespace context with a prefix mapping
xpath.setNamespaceContext(new NamespaceContext() {
  public String getNamespaceURI(String prefix) {
    return "ns".equals(prefix) ? "http://example.com/ns" : null;
  }
  // ...
});
NodeList result = (NodeList) xpath.evaluate("/ns:root/ns:item", doc, NODESET);

XML vs JSON Parsing Performance: What the Benchmarks Show

The performance difference between XML and JSON parsing is real, consistent across languages, and large enough to matter in high-throughput systems. Here is what the benchmark data shows:

Format / Method10K records parse timeRelative to JSONMemory use
JSON (native parse)~50ms1× (baseline)Low
XML SAX (event-driven)~100msLow (streaming)
XML DOM (tree in memory)~250msHigh (full tree)

Payload size amplifies the performance gap. The same dataset serialized as JSON vs XML:

  • 1,000 user records: ~85KB JSON vs ~165KB XML — XML is roughly 48% larger due to closing tags
  • XML's verbosity comes from the closing-tag requirement — every <field> needs a </field>
  • This is why JSON won the REST API space: smaller payloads + faster parsing = lower latency and infrastructure cost at scale

Where XML still wins on the technical merits: attribute metadata, mixed content (text interleaved with elements like HTML), document-centric data with complex nesting, and namespace-qualified interoperability across organizations. These use cases map exactly to where XML persists in 2026.

fast-xml-parser vs xml2js: Choosing Your Node.js XML Library

The Node.js XML ecosystem has a clear winner: fast-xml-parser receives 56.7 million weekly npm downloads as of April 2026, versus 28.4 million for xml2js. The gap has widened over the past two years as more projects migrate from xml2js.

fast-xml-parser — parsing and formatting in Node.js
import { XMLParser, XMLBuilder, XMLValidator } from 'fast-xml-parser'

// Validate XML well-formedness
const validationResult = XMLValidator.validate(xmlString)
if (validationResult !== true) {
  console.error('XML validation error:', validationResult.err)
  // { code: 'InvalidXml', msg: 'Unexpected end', line: 5, col: 12 }
}

// Parse XML to JavaScript object
const parser = new XMLParser({
  ignoreAttributes: false,    // Include attributes, not just elements
  attributeNamePrefix: '@_',  // Prefix for attribute keys
  parseTagValue: true,        // Auto-parse numbers and booleans
})
const result = parser.parse(xmlString)

// Build (format) JavaScript object back to XML
const builder = new XMLBuilder({
  ignoreAttributes: false,
  attributeNamePrefix: '@_',
  format: true,               // Pretty-print with indentation
  indentBy: '  ',             // 2-space indent
})
const formattedXml = builder.build(result)

For browser-side XML formatting, skip npm entirely. The browser's native DOMParser and XMLSerializer APIs handle parsing and serialization with no bundle cost:

Browser-native XML formatting (zero dependencies)
function formatXml(xmlString, indent = '  ') {
  const parser = new DOMParser()
  const doc = parser.parseFromString(xmlString, 'application/xml')

  // Check for parse errors (XML errors are embedded in the document)
  const errorNode = doc.querySelector('parsererror')
  if (errorNode) {
    throw new Error('XML parse error: ' + errorNode.textContent)
  }

  // Serialize back to string (no built-in pretty-print in XmlSerializer)
  const serializer = new XMLSerializer()
  const raw = serializer.serializeToString(doc)

  // Apply indentation via regex (sufficient for most use cases)
  return raw
    .replace(/></g, '>\n<')
    .split('\n')
    .map((line, i, arr) => {
      // Track nesting depth for indentation
      // (simplified — a full implementation tracks open/close tags)
      return line
    })
    .join('\n')
}

// Better approach: use an XSL transform for proper indentation
function formatXmlWithXslt(xmlString) {
  const xsltString = `<?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" indent="yes"/>
      <xsl:template match="@* | node()">
        <xsl:copy><xsl:apply-templates select="@* | node()"/></xsl:copy>
      </xsl:template>
    </xsl:stylesheet>`

  const xsltDoc = new DOMParser().parseFromString(xsltString, 'application/xml')
  const srcDoc = new DOMParser().parseFromString(xmlString, 'application/xml')
  const processor = new XSLTProcessor()
  processor.importStylesheet(xsltDoc)
  const resultDoc = processor.transformToDocument(srcDoc)
  return new XMLSerializer().serializeToString(resultDoc)
}

Where XML Is Thriving in 2026 (And Where It Is Not)

The "XML is dead" narrative does not survive contact with production infrastructure. A 2025 industry survey found 78% of organizations use XML for inter-application communication and 40% use it for configuration management. The XML Databases Software Market was valued at USD 3.2 billion in 2024, projected to reach USD 7.5 billion by 2033 at a 9.8% CAGR (per Verified Market Reports).

What is actually happening is domain consolidation — XML retreating to domains where its features genuinely outperform JSON, while JSON wins elsewhere. Here is an honest assessment:

DomainXML StatusWhy
Healthcare (HL7 FHIR)ActiveRegulatory requirements, schema validation mandated
Finance (FpML, MISMO)ActiveIndustry standards bodies, audit trail requirements
Maven / Gradle buildsActivepom.xml is the Maven standard; not going away
Android layoutsDecliningJetpack Compose replacing XML layouts
SOAP web servicesStable (legacy)Legacy enterprise — no new SOAP being written
SVG graphicsActiveSVG is XML — embedded in HTML, inline in React
RSS / Atom feedsActive revivalRenewed interest post-social media platform concerns
Modern REST APIsReplaced by JSON78–85% of APIs use JSON; XML <15% of new APIs

The practical implication: if you are building a new microservice, use JSON. If you are integrating with a hospital system, an insurance company, a financial data provider, or a Java enterprise application built in the 2000s, you need XML tooling. Neither camp is wrong — the domain dictates the format.

Common XML Errors and How to Fix Them

XML parsing is zero-tolerance: one syntax error and the entire document fails to parse. These are the errors most commonly surfaced by XML validators:

Error: Unclosed tag
<!-- INVALID -->
<root><item>value</root>

<!-- VALID -->
<root><item>value</item></root>

Every opening tag must have a corresponding closing tag or be self-closed with />. HTML's lenient parsing allows unclosed tags; XML does not.

Error: Unescaped ampersand
<!-- INVALID — & starts an entity reference -->
<company>Smith & Jones Ltd</company>

<!-- VALID — escape as entity -->
<company>Smith &amp; Jones Ltd</company>

<!-- VALID — wrap in CDATA section -->
<company><![CDATA[Smith & Jones Ltd]]></company>

The five predefined XML entities: &amp; (&), &lt; (<), &gt; (>), &apos; ('), &quot; (").

Error: Multiple root elements
<!-- INVALID — two root elements -->
<users>...</users>
<metadata>...</metadata>

<!-- VALID — wrap in a container root -->
<document>
  <users>...</users>
  <metadata>...</metadata>
</document>

XML documents must have exactly one root element. This frequently trips up developers generating XML by concatenating fragments.

Error: Attribute without quotes
<!-- INVALID — unquoted attribute (valid in HTML, not XML) -->
<item id=42 type=product>

<!-- VALID -->
<item id="42" type="product">

All attribute values must be quoted. HTML5 allows unquoted attributes when they contain no special characters. XML never does.

A reliable workflow for debugging XML: paste into BytePane's XML Formatter, which highlights the first error with line and column numbers, or use the browser console — new DOMParser().parseFromString(xml, 'application/xml') returns a document with a <parsererror> element if parsing fails.

XML Formatting Tools Compared: Online vs IDE vs CLI

Different XML formatting contexts call for different tools. Here is an honest comparison — BytePane is included but not ranked first, because the choice genuinely depends on your workflow:

ToolBest forXSD ValidationOffline
Oxygen XML EditorEnterprise XML work, XSLT debugging, XSD authoringYes (XSD 1.0 + 1.1)Yes
VS Code + Red Hat XML ext.Day-to-day development, pom.xml, Spring configYesYes
xmllint (libxml2)CI/CD pipelines, batch validation, scriptingYes (XSD 1.0)Yes
BytePane XML FormatterQuick one-off formatting, API response debuggingWell-formedness onlyBrowser-only
CoreFiling XSD ValidatorQuick XSD validation without local toolchainYesNo (online only)

xmllint: The CLI Workhorse

For CI/CD pipelines and batch operations, xmllint (part of libxml2, installed on virtually every Linux/macOS system) is the right tool. It is faster than any IDE for scripted validation:

# Check well-formedness only
xmllint --noout document.xml

# Validate against an XSD schema
xmllint --noout --schema schema.xsd document.xml

# Pretty-print (format) XML
xmllint --format document.xml

# Format with specific indent (default is 2 spaces)
XMLLINT_INDENT="    " xmllint --format document.xml

# Validate all XML files in a directory
find . -name "*.xml" -exec xmllint --noout --schema schema.xsd {} \;

# GitHub Actions step for XML validation
# - run: xmllint --noout --schema config/schema.xsd src/config/*.xml

Frequently Asked Questions

What is the difference between XML well-formedness and XML validity?

Well-formedness is syntax compliance (W3C XML 1.0 rules: one root, closed tags, quoted attributes). Validity is well-formedness plus conformance to a schema (DTD or XSD). Validity is optional — you can parse well-formed XML with no schema. Most online formatters check only well-formedness; tools like Oxygen XML and xmllint support full XSD validation.

Is XML still relevant in 2026?

Yes — in specific domains. A 2025 survey found 78% of organizations use XML for inter-application communication. It dominates healthcare (HL7), finance (FpML), Maven builds (pom.xml), SVG graphics, Android layouts, SOAP APIs, and RSS/Atom feeds. JSON won modern REST APIs (78–85% adoption). XML is consolidating in enterprise and regulated industries, not disappearing.

How do XML namespaces work?

Namespaces associate element and attribute names with a URI identifier to prevent collisions when combining XML vocabularies. xmlns:ns="http://example.com" declares a prefix. The URI does not need to resolve to anything — it is just a unique identifier. Prefixes are arbitrary; the URI is what matters for validation and XPath resolution.

What is the difference between XSD and DTD for XML validation?

DTDs define structure but have no data types (everything is text) and no namespace support. XSD 1.1 (W3C Recommendation 2012) provides 19 primitive data types, namespace awareness, inheritance, assertions for co-occurrence constraints, and conditional type assignment. XSD replaced DTDs in all modern enterprise XML systems. JDK only supports XSD 1.0 natively; XSD 1.1 requires Apache Xerces 2.12+.

How does XML parsing performance compare to JSON?

JSON parsing benchmarks at ~50ms for 10,000 records versus ~250ms for XML DOM (5×) and ~100ms for XML SAX (2×). JSON payload size is also 30–50% smaller — 1,000 records is ~85KB JSON vs ~165KB XML. These differences drove JSON adoption in REST APIs. For enterprise integration where schema validation and mixed content matter, the performance trade-off is acceptable.

What npm packages are best for XML parsing in Node.js?

fast-xml-parser leads with 56.7 million weekly downloads (npm, April 2026) and is the recommended choice for new projects — pure JavaScript, supports validation, namespace handling, and attribute parsing. xml2js (28.4M weekly downloads) is still widely used in existing codebases. For browser-side XML, the native DOMParser API is preferred over npm packages.

How do I format XML in VS Code?

Install the "XML" extension by Red Hat (uses Eclipse LemMinX Language Server). Open any .xml file and press Shift+Alt+F (Windows/Linux) or Shift+Option+F (Mac). Configure indent size in settings.json under "xml.format.splitAttributes" and "xml.format.spaceBeforeEmptyCloseTag". For Maven pom.xml, the "Maven for Java" extension adds project-aware formatting.

Format & Validate XML Instantly

Paste any XML — a SOAP response, an RSS feed, a Maven pom.xml, an SVG — and get properly indented, validated output in milliseconds. Well-formedness checked client-side, no data transmitted to any server.

Open XML Formatter →