How to use the XML Formatter & Validator
- Paste XML into the input, or drop an
.xmlfile onto it. - Choose Format or Minify, and the indentation.
- If the XML is not well-formed, the error names the exact line, column and the tag involved.
- Copy the result or download it as an
.xmlfile.
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: < for < and & for &. Any XML parser, including the one Salesforce uses for metadata deployments, rejects documents that break these rules.
Example error
<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.
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.