Troubleshooting
How to fix XML parse errors
Start with the first reported error, inspect the surrounding source, and correct one issue at a time. A parser can stop at a symptom caused by an earlier mistake, so check the preceding line as well.
1. Keep a copy and find the first error
Save an untouched copy before editing. Open the document locally and note the parser’s line and column, then inspect a few lines around that location. Fix the earliest error and parse again before chasing later messages.
For example, an invoice export may report a failure on a closing tag when the real mistake is an unclosed attribute quote above it. Reformatting is useful after parsing succeeds; indentation alone cannot repair broken syntax.
3. Escape text and quote attributes
A literal ampersand in ordinary text must be written as &. Attribute values need matching quotation marks. Do not globally replace every ampersand: that can double-escape references that were already correct.
<!-- Broken -->
<vendor id=7>Parts & Service</vendor>
<!-- Corrected -->
<vendor id="7">Parts & Service</vendor>- Check literal less-than signs in text; write them as <.
- Look for duplicate attributes on the same element.
- If the error mentions encoding, check the saved file encoding against its XML declaration.
4. Check the document boundary
A document needs a single root element. Two invoice elements placed side by side are not a complete XML document. A containing invoices element makes this example well-formed, but the receiving system must also accept that structure.
<invoices>
<invoice id="7"/>
<invoice id="8"/>
</invoices>5. Parse again, then check the receiving system
In XML Lens, reopen or paste the corrected source, inspect its structure, and check well-formedness. If you have the expected XSD, validate against that schema next. A file that parses can still contain an invalid date, a missing required field, or the wrong namespace.
Keep the original and corrected versions until the destination accepts the file. Compare them to confirm that you changed only the intended values or markup.
Common questions
Will formatting fix invalid XML?
No. Formatting changes presentation; repair the reported syntax errors first. Once the document parses, indentation can help you inspect its structure.
Why does the reported line look correct?
The parser reports where it detects a problem. An earlier unclosed quote or tag can make a later line appear invalid. Inspect the preceding source as well.
References
W3C XML 1.0: well-formed documents and markup ↗Try the workflow in XML Lens
Explore the relevant Mac workspaces and their capabilities.
View and format XML locally on Mac Validate XML and run local XSLT 1.0 on Mac Compare XML files side by side on Mac