Skip to content

2200M — invalid_xml_document

Source-backed reference for PostgreSQL SQLSTATE 2200M.

2200M

At a glance

This catalogue member denotes an invalid XML document. PostgreSQL 18.6 has a core xml_parse document branch that reports invalid XML document, and the contrib/xml2 XSLT path reports the same SQLSTATE for a failed source document or stylesheet parse. These are distinct emitters from the 2200L document-option wrapper.

Field Value
SQLSTATE 2200M
Condition invalid_xml_document
Status active
Known present by 8.3.0
Locked snapshots 9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3
Macros ERRCODE_INVALID_XML_DOCUMENT
Aliases

Meaning

This member names an invalid XML document condition from a concrete document parser guard. In core xml_parse, a failed xmlCtxtReadDoc parse reports 2200M when the original XML option was DOCUMENT; when the original option was CONTENT, the same parser failure reports 2200N. The separate contrib/xml2 functions use 2200M when parsing the input document or stylesheet as XML. The core xml_errsave helper passes these results to errsave: an ErrorSaveContext stores the error and returns, while an ordinary context throws; this soft-error path is distinct from the direct ERROR branches in contrib/xml2.

Messages

The core branch raises ERROR with primary invalid XML document. The contrib/xml2 branches raise ERROR with primary error parsing XML document or error parsing stylesheet as XML document. The cited branches do not provide a fixed DETAIL or HINT template; libxml2 context can be attached dynamically. Do not replace these messages with 2200L’s not an XML document.

Diagnosis

Use the actual SQLSTATE, message, detail, and context to distinguish document-level failure from invalid content (2200N), comment (2200S), or processing instruction (2200T). Inspect whether the producer is core xml_parse or contrib/xml2, then correct the named document or stylesheet. These emitters are source-confirmed here; no natural runtime was run.

Response

Use the actual message and parser context to repair the invalid document; do not substitute a 2200L fix without confirming the emitted SQLSTATE.

When this branch raises ERROR, an explicit transaction must first be recovered with ROLLBACK or ROLLBACK TO SAVEPOINT for a savepoint established before the statement; in autocommit, retry only the corrected action after the failed statement completes. See the transaction and retry guide for this boundary rule.

Versions

The locked catalogue records this condition from 8.3.0; fixed source coverage is PostgreSQL 18.6.

2200L, 2200N

Sources

Fixed core source: src/backend/utils/adt/xml.c#L1780-1862. The separate contrib/xml2/xslt_proc.c#L84-100 paths parse an XML document and stylesheet. The shared xml_errsave/errsave helper defines the soft-error versus ordinary-throw behavior. The structured evidence record retains both emitters, message roles, and scope boundaries. Core availability depends on USE_LIBXML; no natural XML case was run for this page.