2200M
PostgreSQLERRORNotableData ExceptionHIGH confidence

invalid XML document

What this means

SQLSTATE 2200M is raised when an XML document fails document-level validation — it may be syntactically malformed or violate XML well-formedness rules.

Why it happens
  1. 1XML input with unclosed tags, invalid attribute syntax, or other well-formedness violations
  2. 2Invalid XML declaration or encoding declaration
How to reproduce

Parsing malformed XML.

trigger — this will error
trigger — this will error
SELECT XMLPARSE(DOCUMENT '<unclosed>');

expected output

ERROR:  invalid XML document

Fix

Validate and fix the XML structure before storing

WHEN When XML data comes from external sources.

Why this works

Use an XML validator or library in the application layer to confirm well-formedness before sending to Postgres.

Sources
Official documentation ↗

Class 22 — Data Exception

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors