Since iOS 16 (HealthKit Export Version 12), Apple's export.xml has shipped with malformed DTD declarations. The file includes incomplete tags without matching declarations, so every standards-compliant XML parser fails before it reaches your data.
The error you see
ATTLIST: no name for Attribute [68]
Or in Python:
xml.etree.ElementTree.ParseError: syntax error: line 156, column 0
xmllint, R's XML package, Go's encoding/xml, they all fail on the same root cause. The file can be 1.7 GB or larger, and the DTD error sits in the first 200 lines. You never reach the actual health records.
Root cause
Apple ships a malformed DTD fragment on large exports. It is not your parser, and it is not your data. The RightEye EMPTY element and a handful of others are declared without their ATTLIST companion, which violates the XML spec.
The fixes that work
| Fix | Tools | Works on >1.7GB | Effort |
|---|---|---|---|
| Strip the DOCTYPE |
sed, head
|
yes | low |
| Pre-process with Python | lxml |
yes | medium |
| Tolerant parser | lxmlrecover |
yes | medium |
| Dedicated conversion tool | Health Export AI | yes | low |
Fastest: strip the DOCTYPE declaration entirely. The DTD is not needed to parse the HealthKit record elements, so removing it lets any parser proceed.
Permanent: skip export.xml and read HealthKit directly via a native HealthKit export. That avoids the DTD bug and the multi-gigabyte file problem, and gives you clean JSON instead of a broken XML blob.
What about AI agents?
If you want Claude, Cursor, or ChatGPT to query your Apple Health data, feeding them a broken 1.7 GB export.xml is the hard path. A native MCP bridge reads the on-device HealthKit cache directly, so the agent gets structured metrics (HRV, sleep, workouts, 190 types) without touching export.xml at all.
FAQ
Is my export corrupted? No. The health data is intact. Only the DTD preamble is malformed.
Will Apple fix it? The bug has persisted across iOS 16, 17, 18, and 19. Do not wait.
Can I just delete the bad lines? Yes, stripping the DOCTYPE block (roughly the first 200 lines) is the most reliable fix and loses zero data.
This is a summary. The complete guide with code snippets and the full comparison table is on the original post: [Fix Apple Health export.xml Parse Errors, the Complete Guide](https://dub.sh/oGKpzGL
Top comments (0)