Skip to content

XML Formatter & Validator

Pretty-print or minify XML and find well-formedness errors with exact positions.

Runs in your browser. Nothing is uploaded.

XML input

Well-formed
Output
Indent

Formatted XML

15 elements, depth 3
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <label>Invoice</label>
    <pluralLabel>Invoices</pluralLabel>
    <nameField>
        <label>Invoice Number</label>
        <type>AutoNumber</type>
        <displayFormat>INV-{0000}</displayFormat>
    </nameField>
    <!-- Sharing and deployment -->
    <sharingModel>ReadWrite</sharingModel>
    <deploymentStatus>Deployed</deploymentStatus>
    <fields>
        <fullName>Amount__c</fullName>
        <type>Currency</type>
        <precision>16</precision>
        <scale>2</scale>
    </fields>
    <description><![CDATA[Invoices synced from the billing system & ERP.]]></description>
</CustomObject>

How to use the XML Formatter & Validator

  1. Paste XML into the input, or drop an .xml file onto it.
  2. Choose Format or Minify, and the indentation.
  3. If the XML is not well-formed, the error names the exact line, column and the tag involved.
  4. Copy the result or download it as an .xml file.

Well-formed XML

An XML document is well-formed when it follows XMLโ€™s basic rules. Every opening tag has a matching closing tag in the right order, there is exactly one root element, attribute values are quoted, and special characters in text are written as entities: &lt; for < and &amp; for &. Any XML parser, including the one Salesforce uses for metadata deployments, rejects documents that break these rules.

Example error

XML
<types>
    <members>*</members>
    <name>ApexClass</name>
</type>

This reports: the closing tag </type> does not match <types>, which was opened on line 1.

XML in Salesforce

Every piece of Salesforce metadata is XML: object definitions, fields, layouts, flows, permission sets and the package.xml that lists them. When a deployment fails with a parse error, formatting the file usually makes the problem obvious. Integrations with SOAP APIs and older enterprise systems also exchange XML.

In Apex, Dom.Document reads and writes XML, and XmlStreamReader handles large documents efficiently.

Apex
Dom.Document doc = new Dom.Document();
doc.load(xmlString);
Dom.XmlNode root = doc.getRootElement();
String label = root.getChildElement('label', root.getNamespace()).getText();

Features and limitations

What it does

  • Checks well-formedness: matching tags, a single root, quoted attributes, no duplicate attributes and valid entities.
  • Keeps short text-only elements on one line, such as <label>Invoice</label>.
  • Preserves comments, CDATA sections, processing instructions and the XML declaration.
  • Minify removes whitespace between tags for compact payloads.
  • Works well with Salesforce metadata files such as package.xml, objects, flows and layouts.

What it does not do

  • It checks that XML is well-formed, not that it is valid against a schema (XSD) or DTD.
  • Whitespace inside mixed content (text and elements together) may be adjusted when formatting.
  • Entities defined in a DOCTYPE are not expanded.

Questions about the XML Formatter & Validator

No. Parsing and formatting happen in your browser. Nothing is sent anywhere.

Element names, attributes, comments and CDATA are kept. Whitespace between tags is changed, and leading or trailing spaces in text are trimmed, which matters only for mixed content.

In XML, โ€œ&โ€ starts an entity such as &amp;amp;. A bare โ€œ&โ€ in text must be written as &amp;amp;, or the text must be wrapped in a CDATA section.

No. It checks the rules every XML document must follow. Schema validation needs the XSD and is best done by the receiving system.

Yes. To build one from scratch, the Package.xml Builder is quicker.